Game Development Reference
In-Depth Information
We convert the character to lowercase so that the instruction works for both nor-
mal and boxed penguins. To complete the
Animal
class, we add a few convenient
methods to check if we are dealing with a special case such as a multicolored pen-
guin, an empty box, or a seal. For the complete
Animal
class, see the example project
belonging to this chapter.
Finally, we also have sharks in the
Penguin Pairs
game. Sharks are relatively sim-
ple animals and they cannot be controlled by the player (very much like in real
life!). Therefore, we will not use the
Animal
class for them, but we will simply use
SpriteGameObject
, which contains everything we need. We follow a similar proce-
dure as with the penguins. We create a tile and a shark, and store the sharks in a
List
so that we can easily find them later on:
t=
new
Tile("Sprites/spr_field@2", 0, "", (row + col) % 2);
tilefield.Add(t, col, row);
SpriteGameObject s =
new
SpriteGameObject("Sprites/spr_shark", 2, "");
s.Position = t.Position;
playingField.Add(s);
sharks.Add(s);
break
;
Automatic copying of assets—
You may have noticed that when a game is
compiled, it copies all the assets to a folder local to the application file. For
example, if you compile the
PenguinPairs4
program in release mode, the con-
tents are copied to the folder
bin/x86/Release/Content
. These are the contents
that are really used when you run the game, and not the contents in the con-
tent project. So, watch out that if you want to modify for example a text file,
you modify the right version of that file.
22.7 Completing the
Level
Class
Now that we have finished loading the tiles, we still have to add a few more game
objects to complete the
Level
class. The first thing we will do is add a 'quit' button,
so that players can quit the level and return to the level menu:
quitButton =
new
Button("Sprites/spr_button_quit", 1);
quitButton.Position =
new
Vector2(1058, 20);
this
.Add(quitButton);