Pages

Tuesday, February 15, 2011

Code::Blocks(10) RPG 1 - Tileset and maps(3)

Time to use a multi - layered map:



We want to draw (quite) complex things, starting from simple ones, the easier way to accomplish that is to use tiles (at least one used quite often), so we don't draw the full image, but just small pieces, with many pieces we can draw complex images, I'm going to use three (virtually four)  layers of tiles:

  1. The base ground: Sand, grass, water, etc.
  2. The ground objects: Rocks, trees, a road, a volcano, etc.
  3. Things that can lay on the ground: Treasures , any other inventory-related object, etc.
  4. On a virtual 4rd layer we will draw  additional objects, not map-related such as PCs, NPcs, the mouse cursor, etc.
Before going any further, just download the 2nd project from the Download page (http://jbfproject.blogspot.com/p/downloads.html) and just compile and run it, if everything goes ok, you should have a screen like the one in the top.

Not very impressive right? but it shows the key to build complicated maps using simple tiles, divide an image into small pieces and use layers, we have applied here the latest updates to the simple engine class in the previous posts.

The basic difference between this projects and the life game one is that in the previous one the map was an array with two dimensions: cellmap[x][y], now it is a three dimensions map: map[x][y][layer], so when we draw the map we will have to draw first layer (0) to print the base ground, then layer(1) for the terrain objects and finally layer(2) to draw other objects, after we have drawn the map we will draw the mouse pointer.

Note: there are many , many ways to define and draw a map, here i have just used a simple way.. you can find more ways for example in Amit's game programming information but of course, you can use anything that meets your objectives.

In the next post: Our Hero drawn on screen, cameras , and other things....

Bye

    No comments: