Game Development Reference
In-Depth Information
Chapter 14
Game Objects in a Structure
In the previous chapter, you saw how you can use arrays to represent lists of things. For example,
you used an array to keep track of the locations where the player is touching the touch screen,
or how many keys the player is currently pressing on the keyboard.
Arrays can be used in a lot of other situations as well. You can use them to store more complicated
objects such as the ball or the paint cans in the Painter game. In general, it's useful to provide some
structure to the game objects, instead of simply having them all declared as member variables in
the game world. Many games place their game objects in some kind of game hierarchy. For
example, you could have a game object Car that consists of other game objects such as wheels,
a transmission system, a motor, windows, seats, and so on. Each of these objects can in turn
consist of smaller game objects, and so on.
In some cases, game objects have to adhere to a certain structure in the game world. Many board
or puzzle games have this requirement. These games impose a set of rules that 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.
You aren't allowed to place your queen halfway between two squares. In computer games, these
kinds of restrictions are easier to enforce: you just have to make sure the position where you
place your game object is a valid one. In this chapter, you see how to incorporate hierarchies and
structures into computer games.
Game Objects in a Grid
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, Candy Crush, and many more.
Often the goal in these games is to modify the configuration 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 subgrids. The game JewelJam also uses a grid structure. The
question is, how do you represent these kinds of grid-like structures in your games?
187
 
Search WWH ::




Custom Search