Sign in to follow this  

Two questions tile based maps and collision

This topic is 4841 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

In a tile based side scroller, should I use a 2d array for the map, I see some people do not, what are the advantages to not using a 2d array? How would I do the collision? Each tile right now holds a state of solid or not, can I have the names of some methods to research? I want the collision to work for any velocity, some method I saw did not work if the sprite moved too fast.

Share this post


Link to post
Share on other sites
i prefer to use a nested vector. its all your personal preference, as i doubt which type of array you use will effect speed. if you want to index your array using [][], use a multi-dimensional array, or more preferably a nested vector or boost::multie dimensional array. the other alternative is to use a single dimension array and index it [x + y*width].

Share this post


Link to post
Share on other sites
I don't understand, how come there are no good tutorials online about 2d game programming?

Almost all collision detection tutorials are 3d.. I am not intersted in 3d at all right now and prefer to just work with 2d for a bit. There are no resources at ALL, especially because I am using SDL.

The only thing I see is jump n run dev but that's not that good.. everything else is way too big for me to learn from. The only site I think that looks promising is about tile games but it's for Flash..

Does anyone have any books they recommend? Any general books about game programming would be nice, not tied to any language or library.

Share this post


Link to post
Share on other sites
Personally, I don't use a 2d array so that my tiles may be arranged into an arbitrary shape.

3d and 2d aren't very different. The algorithms apply to each, but instead of using x,y,z you use x,y. For collision detection, one of the common methods is to draw a line from the originating point to the destination point. If that intersects a "solid" then a collision would happen [or do a more detailed collision check to make sure].

Share this post


Link to post
Share on other sites
For storing the map, I feel that a 1D array is better than 2D because internally the computer stores the array as 1D anyway.

For collision, I would primarily try to work with your original system. If the sprite moves too fast (and jumps blocks) then take steps to check the spaces in between the motion... so that if the sprite moves 100 pixels in one jump, detect that and check along it's path every say 10 pixels in a for...next loop.

An alternative is to use the bresenham line drawing algorithm. Start by looking at your current block, the block that your sprite occupies, then look at where it moved to. Trace a line from the source to the destination and look at every block in between to see if any of those blocks would prevent moving through.

Both are probably easier that converting using floating point maths like the 3D algorithms use.

Mark
Cornutopia Games
http://www.cornutopia.net
Sound Effects For Game Developers
http://www.indiesfx.co.uk

Share this post


Link to post
Share on other sites

This topic is 4841 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