Sign in to follow this  

collision detection design on 2d side scroller

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. Ive begun to create a 2d side scrolling shooter using SDL and ive got the EXTREME basics of the game worked out. But i have some design questions on what would be the best way to implement some collision detections for shooting and well as running around in the game itself. my first question for shooting to check and see what it hit, either a monster or part of the ground/ceiling/etc. I had the thought of getting the angle that the weapon is pointing, the using the y=mx+b equation of a line, checking to see if any objects fall within that point. but to do that, i would have to go up a pixel, then check all the monsters lowest point and highest point to see if that line falls inbetween in. my concerns are two things. 1. is this the standard way of doing this and 2. is the concern of efficiency. id like to have decent amount of monsters on the screen at once (10-15) and i dont know how much its going to bog a PC down by basically getting a point on the line, then scanning all mobs, checking, and looping until it hits something. another question i have has to do with the ground and ceilings. now i could just cheat and have a constant flat surface to run on, but id like to have hills or multiple paths within the game to run on. im just not sure how to go about checking to see when you at a point on the 'ground image' that you are going up. to my knowledge, the ground is just a huge 'image' that you woudl scroll and you run in the game and only show the portion necessary so you arent rendering parts you arent seeing on the screen. so how would you go about doing this? thank you in advance. if you need more deteails, please let me know.

Share this post


Link to post
Share on other sites
Look for some tutorials on ray / bounding box collision. You can trace if the bullet hit the target based on this collision method and time. Can't help more atm, have all my projects not on the desktop pc.

P.S.: There is no big performance hit with 10-15 targets

Share this post


Link to post
Share on other sites
To speed up coll. det. you could setup a raster (an array of Bytes) and use this is as a simplification of what is happening on the screen (enemy 1= 1, enemy 2 = 2, your ship=5, etc).

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this