Game Development Reference
In-Depth Information
There are also different kinds of blocks that the player can jump on, there will be
water drops, enemies, the start position of the player, and the end position that the
player has to reach. As in the Penguin Pairs game, we will store level information in
a text file. To do things slightly differently here, let us store one level in one text
file, instead of all levels in a single text file. There is no real disadvantage to either
approach.
We will define a level using tiles, where each tile has a certain type (wall, back-
ground, and so on). We then represent each tile type with a character in the text file.
Next to the actual tiles, we also store a hint together with the level definition. Here
you can see the definition of the first level:
....................
.................X..
..........##########
....................
WWW....WWWW.........
---....####.........
....................
WWW.................
###.........WWWWW...
............#####...
....WWW.............
....###.............
....................
.1........W.W.W.W.W.
####################
Pick up all the water drops and reach the exit in time.
In this level definition, a number of different tiles and objects are defined. A 'wall'
tile is defined by the '#' sign, a water drop by a 'W' character, the start position
of the player by the '1' character, and the end position of the player by the 'X'
character. If there is no tile at the specific position, we use the '.' character. For the
platform game, we need different types of tiles: a 'wall' tile on which the player can
stand or collide with, and a 'background' tile that indicates that there is no block
on that position. We also want to define a platform tile . This tile has the property
that you can stand on it like a wall tile, but if you are standing under this tile, you
can jump through it. This kind of tile is used in many classic platform games, and it
would be a pity not to include it here! In the level file, platform tiles are represented
by a '-' character.
25.4 Water Drops
The goal of each level is to collect all the water drops. Each water drop is represented
by an instance of the WaterDrop class. This class is a SpriteGameObject subclass, but
we want to add a little behavior to it: the water drop should bounce up and down. We
can do this in the Update method. First, we will compute a bounce offset that we can
add to the current position of the water drop. In order to calculate this offset, we use
Search WWH ::




Custom Search