Game Development Reference
In-Depth Information
Chapter 14
Game Objects in a Structure
14.1 Introduction
In Chap. 12 , we have seen how we can maintain a list of game objects. In the Snow
example, these objects (snowflakes) were placed arbitrarily on the screen. However,
games often require that game objects are adhering to some kind of structured game
world. Many board or puzzle games have this requirement. These games impose a
set of rules, which binds the playing pieces to certain positions or configurations
on the playing board. For example, in a chess game, the pieces can only be placed
(meaningfully) on the white and black squares on the playing board. It is not al-
lowed to place your queen halfway two squares. In computer games, these kinds of
restrictions are easier to enforce, you just have to make sure that the position where
you place your game object is a valid one.
In this chapter, we will look into incorporating these kind of structures into com-
puter games.
14.2 Game Objects in a Grid
14.2.1 Grids in Games
Often, board games and puzzle games are based on placing objects in some kind of
grid. There are many examples of such games: Chess, Tetris, Tic-tac-toe, Sudoku,
Bejeweled, and many more. Often the goal in these games is to modify the config-
uration of the grid in some way to achieve points. In Tetris, completely filled rows
have to be constructed, and in Sudoku, numerical properties must hold for rows,
columns, and sub grids. Our game Jewel Jam also uses a grid structure. The question
is: how do we represent these kinds of grid-like structures in our games?
First let us have a look at a simplified case, where we want to draw a background
sprite, and on top of that, a grid of ten rows times five columns, where each location
in the grid is filled with a sprite. The program that does this is called JewelJam2 and
you can find it in the example solution belonging to this chapter.
 
Search WWH ::




Custom Search