Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

collision detection

Recommended Posts

You would probably want to use bounding boxes (which is the size of the sprites width and height). I'm assuming your map is an array so here it goes.

Let's just say your sprite is a 16x10 dude. He's walking from 0,0 sector of the map to 1,0 of the map. But wait! 1,0 is a giant wall. What to do!? During each step, compare the sprite's blitting coordinate(top left) and the width or height with the wall's location.

ie.


if (sprite.x > mapxlocation*32 &&
sprite.x+width < (mapxlocation*32)+32 &&
sprite.y > mapylocation*32 &&
sprite.y+height > (mapylocation*32)+32)
collision == TRUE;

It would be something like this. What this do is creates a "box" around the sprite and checks the box's coordinates (yes, all four!) with the tile's four cordinates.

This is the simplest collision detection there is. If you want greater precision there are spherical and perfect pixel collision detection methods.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hmm...that works fine...for one tile...but I have sevral hundreds (yes, hundreds) of tiles that I want to restict...all of them scattered throughout different map arrays. so, it would be a lot easyer if I could just define the tiles that my character cant walk though (he's 32x32, by the way).

Share this post


Link to post
Share on other sites
Easiest way is to hold the "passibility" of a tile. You can do it as simply go/no go, or as a rate of speed decrease (or increase), so say if you travelled slower over mountains or whatever.

Then as the player moves, just check the pass information, and either restrict the movement, or alter it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hello,
for the longest time, I had been very frustrated with C++. so frustrated infact, that I bought a new computer just so I could take a sledge-hammer to my old one. but recently, I finaly got a small tile-based game to work. the only part I have done now is the tile scrolling engine. but now I'm clueless on how to get some collision detection to work. I use DirectX 4.0+ in my game, and the tiles are square 32x32 tiles. if its possible, could I just define the tiles that I dont want the character to walk through? if anyone has examples that I could easily add to my code, that would be great!

-Tom

Share this post


Link to post
Share on other sites