Jump to content
  • Advertisement
Sign in to follow this  
yats55

How are maps done in SDL?

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

I'm speaking mostly of maps made with tiles.

 

Is it ever done in map editors or such programs, then the image file of the map is loaded into the code just like how bitmaps and sprite bitmaps are?

 

If so, what format/file types is it usually done in? (I'm aware sdl by itself uses only bmp) (Mappy has MAP. and FMP. files is that used?)

Edited by bigbadbear9885

Share this post


Link to post
Share on other sites
Advertisement

Maps are done any way you like. SDL isn't a game-engine, it's a low-level library.

 

You can make your map vector, tilemap, or something else. Whatever you want.

Share this post


Link to post
Share on other sites

SDL is not a game engine and as such does not have any built in classes for managing tile maps like those found in Mario or Zelda.

 

I would suggest you do the following.

 

1. Create a class called Map, this should include some means of storing tile information. A very basic system is to initialise a dynamic 2D array of tile ints upon loading a map file. Each integer would represent a map tile, 0 for sky, 1 for grass etc.

 

2. You need to create a map file format. For now we are keeping things very simple, and whilst this approach is highly limited, you can modify it to suit your needs. Create a text file or any file, Personally I just remove the file extension as it is unimportant. An example map format could be the following...

width
height
tile x1,y1 x2,y1 xn,y1

tile x1,y2 x2,y2 xn,y2

tile x1,y3 x2,y3 xn,y3

 

4

3

0 0 0 0

0 0 0 0

1 1 0 1

.

using the '0' for sky '1' for grass approach, this represents a map that is mostly sky, with 2 small pieces of land at the bottom, similar to a side scrolling platformer.

 

3. Now that we have our map saved in a file, create a function that takes a string to the map directory as a parameter eg LoadMap(string _mapAddress) and load your map from file. Your class will need some getter functions so that other parts of your code, particularly your renderer can access tile information stored in your 2D array.

 

4. In your renderer, call the function in your map class to get the id of a tile. This will be called in a double for loop. Draw the tile in the correct position using the current indexes of the for loop multiplied by the width and height of the tile. If the value is 0, draw sky, if it is 1, draw land.

 

Happy coding :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!