image collide with floor

BlitzPlus Forums/BlitzPlus Programming/image collide with floor

Ross C(Posted 2003) [#1]
i'm just at the basic stages with a platformer game right now, but i can't seem to figue out how to do the collision detection between my character and the floor because i'm gonna have to check maybe 6 or 7 different bits of flooring.

Can't seem to get my head round it. too late maybe. Any help would be great!


WolRon(Posted 2003) [#2]
Just set all the different flooring to the same collision type. The Collisions command does all the work.


DarkNature(Posted 2003) [#3]
Joker, is it 2D or 3D?


Dr Derek Doctors(Posted 2003) [#4]
Hmm... it's posted in the 2D forum so, taking a wild completely unfounded stab in the dark, I'd say it's 2D. ;)

As for my solution to the problem, it's DON'T USE IMAGESCOLLIDE! Collision with your environment shouldn't use pixel-perfect screen collision because if you draw a bumpy bit of floor you'll probably get stuck in it all the time. You should represent your world in a simpler form in an array of tiles or at most in a huge array/bank (bank for preference!) where you can use individual bits to represent the properties of each pixel.


Ross C(Posted 2003) [#5]
lol@dr derek.
thanks for your reponses. it is 2d btw.

it the actual code to get the character to walk on the ground and check when is is jumping/falling when he hits a bit of floor. would i need to check collisions between the image and ever single tile or piece of ground in the level?

i know you said not to use imagescollide but this is for example purposes
if imagescollided(player,x,y,groundtile1,gx,gy)

or store all the tiles in a type collection when they are being used and cycle thru them maybe?

and dr., what other method do you suggest for checkin image collision?


Dr Derek Doctors(Posted 2003) [#6]
Well, I would personally use a tilemap and assume that all tiles are solid squares, however if you're dead set on pixel-perfect image collides (if you're doing summat like Thrust this would be advisable) then I'd use a tilemap which tells you what the image is in each tile position and then check for collides with all the nearby ones. Checking every tile in the level via a list of types would be the maddest idea in the history of everything and something you definitely want to avoid. Very SLOOOOOOW.


cyberseth(Posted 2003) [#7]
Actually I'd personally use ImagesCollided. I'd perform the x,y location on what the player "would be" if he moves in the current direction. If ImagesCollided returns true, then perform the same function on the x,y a pixel or two higher up (so that he walks above the terrain). If that says no, then move the player there. Otherwise, start where the player would be when walking forward, and trace the x value back to the player's current pos, unti ImagesCollided returns false.

The problem with this method is that you can end up having quite a lot of ImagesCollided checks in one loop. However, if it's just for one player then it shouldn't be a problem.