Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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 2246 times)
0 Members and 1 Guest are viewing this topic.
Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Posted 2005-02-13 17: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.

Blog
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #1 - Posted 2005-02-17 07: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).

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

JGO Coder


Medals: 1


pixels! :x


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

Two tutorials you might want to read:
http://www.harveycartel.org/metanet/tutorials/tutorialA.html
http://www.harveycartel.org/metanet/tutorials/tutorialB.html

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 Member




Like a leaf in an icy world, memories will fade


« Reply #3 - Posted 2005-02-19 00: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.

Blog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (27 views)
2014-04-15 18:08:23

BurntPizza (24 views)
2014-04-15 03:46:01

UprightPath (38 views)
2014-04-14 17:39:50

UprightPath (21 views)
2014-04-14 17:35:47

Porlus (36 views)
2014-04-14 15:48:38

tom_mai78101 (61 views)
2014-04-10 04:04:31

BurntPizza (119 views)
2014-04-08 23:06:04

tom_mai78101 (219 views)
2014-04-05 13:34:39

trollwarrior1 (186 views)
2014-04-04 12:06:45

CJLetsGame (193 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org 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‑gaming.org
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!