Sign in to follow this  
too_many_stars

2D map creators

Recommended Posts

too_many_stars    336

Hi guys,

 

I have made a couple of 2D levels using SDL where I simply load a tile from a text file which is a set width and height. Then I run two for loops checking collision. Of course, this is rather crude and makes for a "boxy" world.

 

I am wondering if there's a way of creating more advanced shapes such as hills and valleys which already have SDL_Rect built in. I shudder at the thought and the amount of time it would take to craft a hill or a slope if I have to create an SDL_Rect for each pixel height.

 

Of course if this is the only way to do it, then so be it.

 

Thanks,

 

Mike

Share this post


Link to post
Share on other sites
doyleman77    367

As I understand it, you can store a slope type metadata in the map file on how steep a slope is; and handle the player's position on said slope by using some simple trig. There's an article I read about it, using Megaman X's level as an example. Here:

 

http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/

 

This can be done in SDL.

Share this post


Link to post
Share on other sites

Really, it isn't even relevant to SDL at all, it's entirely part of the game logic (SDL only cares about what you're drawing).

 

Just store collision data alongside the graphic for each tile, i.e. each tile has both a graphic and a collision type that indicates what kind of block is it (e.g. empty, solid, slope, one-way, etc.). You could also assign a collision type to each graphic too, if you need to save space and want to ensure consistency, though storing collision for each tile makes it easy to allow for stuff like hidden passages and the like.

Share this post


Link to post
Share on other sites

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