Tile based game display

I have been writing a fairly simple turn based rpg game in c++ and at the moment it has a 2d integer array for the map, which I can display using periods for the blank areas and letters for the various people in the game, and I am trying to figure out how to upgrade to a tile based display. I don't even know if it will be within my realm of skills, but if someone could point me to some sample code or at least give me a nudge in the right direction, it'd be very appreciated.
Instead of integers you use images.
Have you chosen a graphics library yet? If not I'll suggest SFML http://www.sfml-dev.org/ (use version 2, 1.6 isn't updated anymore) as I find it easy to work with.

Creating a tile map is fairly straight forward. A simple method, you can keep the array of ints and use that to specify what tile is in what position. Then to draw iterate over the array and use the index times tile size for the draw position of the tile.

1
2
3
4
5
6
7
8
9
10
11
12
/*0 = empty
  1 = player
  2 = ground*/
int mapsize = 16;
int mapcol = 4;
int map[] = {0,0,0,0,0,0,0,0,0,0,1,0,2,2,2,2};

//psuedo code dependant on API used.
Sprite sprite[] = //load tiles

for(int = 0; i < mapsize; ++i)
    window.draw(sprite[i].setPosition(i % mapcol, i / mapcol));
Instead of integers you use images.


lol yep basically this

also, out of all the graphics library i think sdl is the easiest to use and adapt so i would recommend it
Topic archived. No new replies allowed.