#### Archived

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

# Platform game

This topic is 5928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to know how to keep track on where the player is in the game. Let''s make it simple. I have a screen, let''s say 800x600. I have three objects: object 1: w=64, h=64, x=100, y=200; object 2: w=150, h=64, x=500, y=400; object 3: w=64, h=64, x=10, y=70; These objects are stored in a list: obj_list[3]. Ok, look, my guy knows how to jump. But the problem is I don''t want him fall through the objects. They should be solid. I thought this would be an easy thing to do. But when I began coding. I met some problems. How should this be done? Some links, explanations, tips or pushes in the right direction would be fine! /J Lindroos

##### Share on other sites
First of all, since the "guy" is falling down, you could only check the upper contour of the objects against the lower contour of the guy. From each object, you can extract two points: Upper left and upper right. If the guy is between those, and the Y-coordinate equals the objects'' Y-coordinates, don''t let him fall anymore. If no objects has been found below the guy, just let him fall.

Also, if the guy can move while falling, be sure to check the sides of the objects against the guy.

##### Share on other sites
Yeah, you know, that was what I thought to. But first of all, the guy isn''t always falling down (have you ever seen a game were that is the case?). I also want him to bump in the roof. I mean, this is how I check if he is hitting the roof:

if(( guy.x+guy.w ) > object1.x && guy.x < ( object1.x+object1.w)
&& ( guy.y+guy.h ) > object1.y && guy.y < ( object1.y+object1.h)
&& guy.yspeed < 0)

if this is true I set y to the y-pos of the roof, and makes yspeed positive so that the guy will fall down again
So far so good, but when I''m checking the sides everything will stop working.

I think this is not quite so easy
/J Lindroos

##### Share on other sites
Congratulations, you''ve just discovered why programming games is not easy and why hardly anyone who attempts them actually finishes them. The reason being: Its Hard!

The above is a good start on collision detection, you can check here for a good article on "pixel perfect" collision detection (www.javage.com) Also check the articles on this site, there is a ton of information here if you look for it.

1. 1
Rutin
65
2. 2
3. 3
4. 4
5. 5

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633415
• Total Posts
3011767
• ### Who's Online (See full list)

There are no registered users currently online

×