Game Development Reference
In-Depth Information
for (x = 0; x < 5; x++)
grid[x, 0] = random.Next(3);
14.2.4 More Possibilities with Grids
You can find the complete listing of the JewelJam2 program in the samples provided
with this chapter. In order to get acquainted with how multi-dimensional arrays
work, you can try to program some other grid operations on your own. For ex-
ample, can you write a method void RemoveRow( int i) that removes a row at a given
index and that creates new values for the top row? Or can you write a method that
performs a round-robin operation on the rows (so: all rows move down and the last
row becomes the first row)? Or how about moving rows up? Or moving columns?
You can imagine that it is possible to create many different operations on a grid like
this. These operations can be useful for many different games. For example, remov-
ing a row from a grid is an operation that is used a lot in Tetris games. In a game like
Bejeweled, operations are needed that can remove a number of items from a row or
a column and fill the grid up again.
Next to the operations that we can perform on grids, we also have to think about
the items that a grid contains. In this example, we have used a two-dimensional grid
containing integers. For more complicated games, it is probably useful to have a
grid of game objects instead, so that we can add more behavior and interaction to
the objects that are a part of the grid.
14.3 Hierarchy of Game Objects
14.3.1 Anatomy of a Game Object
Most of the games have quite a complicated structure of game objects. First, there
might be a background consisting of various layers of moving objects (mountains,
air, trees, and so on). Then, there are various objects moving around that the player
can interact with. These objects can be enemies of the player so they need some
level of intelligence, these objects can also be more static such as power-ups, trees,
doors, or ladders. Sometimes, objects do not even have a physical appearance in
the shape of a sprite. For example, you could imagine that the current score of the
player is also a game object, but it does not have a sprite associated with it, but a font
in which the current score should be displayed somewhere. Or you could imagine
a game where there is an invisible enemy that has to be defeated, whose position
can only be seen by the effect that this enemy has on its surroundings. We can also
think of game objects that are even more complex: game objects that consist of other
game objects. Suppose that we have a game object that represents a house. However,
Search WWH ::




Custom Search