Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (776)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Environmental Collision Detection in Platform game  (Read 3656 times)
0 Members and 1 Guest are viewing this topic.
Offline Virum

Junior Devvie

Like a leaf in an icy world, memories will fade

« Posted 2005-02-13 16:35:30 »

I'm coding up the map part of my game engine ATM, which brings me too this question.

Is this a good way to handle way to handle collision detection with the environment (like walls, floors, etc.) in a platform scrolling game:

I create an image for my level in the game, and I split it up into tiles.  The game loads the tiles and then renders the ones that are on the screen.  This is fine and dandy.

For collision, I'd make a special "collision channel" (like an alpha channel) based on black and white values that corresponds to the background image and this is also split into tiles.  For collisions detection with the character(s) and sprites, I get the tile they are one and then test to see if they are touching any of the non-black pixels of the "collision channel."

The advantage to using this system, is I could define volumes that slow motion (like water for example).  Any value less than white would be a "slowing down" (friction) area.

Does this make sense?  Will it be too processor intensive?  Is there a better way?

Edit:  I've been giving this more thought, and I realized that it would be inneficient to scan the "collision channel" image for the gray->white pixels every game loop.

Anyway to cache the data?  Would storing the colors in custom objects that takes a double array of ints (x,y coords) and a Color object, and cycle through the array?) be good enough do you think?

It's time to prove to your friends that your worth a damn. Sometimes that means dying; sometimes that means killing a whole lotta people.

Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #1 - Posted 2005-02-17 06:44:03 »

Here's how I do things in Quix:

Originally I just had tile properties (a fake enum on each Tile object), which were basically SOLID, EMPTY, PLATFORM and WATER. Solid was non-passable, platform allowed you to walk on the top edge but jump though it, water would be like empty but slow you down.

Since my Tile objects are in a 2d array, its dead easy to turn a 2d pixel coord into a specific Tile object. Then you just need to check the different edges against the tiles that they're over.

Unfortunatly that means you're pretty restricted to flat platforms and everything looks very square (although you might be able to hide that with good art). So I added heightfields. Heightfields start off as a 32x32 (tile size) black/white image, which at load time are converted into a 1d heightfield. Tiles may have an associated heightfield that means that everything above the heightfield is empty, and everything below is solid. Then you just need to convert your normal walking movement into one that follows the surface of your heightfield.

Fairly simple idea, but I think it makes the levels much more interesting (even though its not as flexible as something like Sonic's looping, twisting levels).

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #2 - Posted 2005-02-17 07:23:00 »

Two tutorials you might want to read:

You won't necessarly need to do it the way they did, but for me it was a nice source of inspiration. The stuff there is highly optimized, because the game (N) was written in (extremely slow) action script.

What's certainly faster than a collision map is using simple gemetric constuctions for each (different) tile. Well, look at the tutorials... it's all there Smiley

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Virum

Junior Devvie

Like a leaf in an icy world, memories will fade

« Reply #3 - Posted 2005-02-18 23:25:41 »

Thanks guys; I'll look through those tutorials later and think about Orangy Tang's Quix implementation.

When I get into the mood to code (I have been unable to achieve nirvana for the past few days), I'll let you know if I have more questions. Smiley

It's time to prove to your friends that your worth a damn. Sometimes that means dying; sometimes that means killing a whole lotta people.

Pages: [1]
  ignore  |  Print  

hadezbladez (270 views)
2018-11-16 13:46:03

hadezbladez (147 views)
2018-11-16 13:41:33

hadezbladez (280 views)
2018-11-16 13:35:35

hadezbladez (63 views)
2018-11-16 13:32:03

EgonOlsen (2118 views)
2018-06-10 19:43:48

EgonOlsen (2142 views)
2018-06-10 19:43:44

EgonOlsen (1354 views)
2018-06-10 19:43:20

DesertCoockie (1950 views)
2018-05-13 18:23:11

nelsongames (1594 views)
2018-04-24 18:15:36

nelsongames (2241 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!