28
Figure 9-12. The tiles sheet for the scrolling examples
Next, we use the data from a two-dimensional array to paint these tiles to the game
screen to create our game world.
Second, a Two-Dimensional Array to Describe Our Game World
We put this game world into an array. Each number in the array rows and columns
represents a tile number in our game world. So, a 0 would paint the first tile in the tile
sheet (the blue wall), a 1 would be gray road tile, and so on.
world.map=[
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
,[0,1,2,1,1,1,1,1,1,1,1,1,1,1,0]
,[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0]
,[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0]
,[0,1,0,1,0,0,1,1,1,0,0,1,0,1,0]
,[0,2,1,1,1,1,0,0,0,1,1,1,1,1,0]
,[0,1,0,0,0,1,0,0,0,1,0,0,0,1,0]
,[0,1,1,1,2,1,0,0,0,1,1,1,1,1,0]
,[0,0,0,0,0,1,1,1,1,1,0,0,0,0,0]
,[0,1,1,1,1,1,0,0,0,1,1,1,1,1,0]
,[0,1,0,1,0,0,1,1,1,0,0,1,0,1,0]
,[0,1,0,1,0,0,2,0,0,0,0,1,0,1,0]
,[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0]
,[0,1,1,1,1,1,1,2,1,1,1,1,1,1,0]
,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
];
Third, Paint the Tile-Based World to the Canvas
Our world is built using a 15x15 grid. Figure 9-13 shows the entire world we will use in
our scrolling examples.
Scrolling a Tile-Based World | 571