Saturday, February 5, 2011

Code::Blocks(8) RPG 1 - Tileset and maps(1)

In the life game tutorial we have used that tileset:



Now we are going to use a different tileset:



We need to draw more things, in the last tutorial we just needed 4 cells states and a mouse cursor, now we are going to use a tileset with 8(width) x 8(height) =64 different tiles, (you can use any size but at the moment it is enough for us), i am going to divide the tiles using a logical way: each row has a particular function, so:
  • Row(0) will be the terrain tiles.
  • Row(1)  terrain object (trees, a volcano, roads...).
  • Row(2) :PCs (NPCs): A person (kinda) , a cat and a dog.
  • Finally in row(3) we have the mouse cursor.
Notice three things:

  1. My horrid drawing skill with Gimp ;)
  2. There are many empty tiles so if we want to draw more things you can easily do it without making a big effort.
  3. I'm going to use more than one layer to draw the terrain, so we will use a base image for every tile , say grass, water, sand, etc and then we will draw other elements (rocks, threes , a road, etc) on a different layer to add complexity to the image.
 In the engine, we have to change the tileset size from 50 to 100 so it will adjust the tiles properly,

We need a new function to draw tiles, the one we have just use the tile size to adjust the position of the tiles, but now we need another one so we can adjust the tile to an offset x and y because we want to draw the characters at x=15(pixels), y=27(pixels), not at x=15(tiles), y =27(tiles).

Finally i'm going to adjust the tileset drawing function so we will pass the tile as a integer (0-63) and the function will automatically search the correct tile.

In the next post the two new tileset drawing functions.

bye

    No comments: