Skip to main content
GameDev.net gamedev.net
🔒 Locked

collision detection

Started by lemonstix Jul 31, 2002 at 8:20 AM 8 replies 900+ views
Original Post
lemonstix
lemonstix
I am wondering how to do collision detection for my very simple 2D game (top view). I have created a graphical map but the user can travel anywhere in it, regardless of trees or any other obstacles. I have tried looking in the tutorials, but none of them are easy enough to understand. Could someone explain this to me? one of the problems is that the two objects colliding are not just two rectangles. one is the user, the other is a map...it''s just a picture. Will this not work? SHould I create a ASCII version of the map? Any help would be great
JOL
JOL
you could use rectangles anyway, just put them on the right spot (on the map).
it is quite easy to use circles too (check for distance to a centerpos)
you can also make the detection using multiple rectangles and circles for each object.

the easiest way would be to have a rectagular grid of numbers that is combined with the map and where there is a number you will collide and where there is a zero you don''t...

think about it some and you''ll figure it out.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
Samith
Samith
if its a big map per pixel collision detection would be pretty slow. i would suggest just putting rectangles on the map and testing those.



Sam Johnston (Samith)
Amma
Amma
That''s easy


Map[100, 100] (In tiles)

Player pos = {23, 86} (In pixels)

How to get the tile beneath the player
---------------------------------------
TheTile = Map[ ((PlayerPosX / TileDX) * TileDX), ((PlayerPosY / TileDY) * TileDY) ]

You can now check if the Tile is one that the player may step over or not.


Look at my old 2D games at http://tmb.united.net.kg





-----------------------------
AM
-----------------------------Amma
rmdeboer82
rmdeboer82
hyt
Be creative, don't copy...Greets from Holland!
coriolis666
coriolis666
Collision detection is easy. Try it on SDL.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.