Game Development Reference
In-Depth Information
a sine function, and depending on the
x
-position of the water drop, we change the
phase, so that not all drops move up or down at the same time. We store the offset
in a member variable called
bounce
:
∗
3.0f + position.X;
double
t = gameTime.TotalGameTime.TotalSeconds
∗
0.2f;
bounce = (
float
)Math.Sin(t)
Finally, we add the bounce value to the
y
-position:
position.Y += bounce;
In the next chapter, we are going to add more game objects, such as the player and
a variety of enemies. But let us first have a look at how we define the tiles in a
platform game such as
Tick Tick
.
25.5 The
Tile
Class
The
Tile
class is very similar to the one we used in
Penguin Pairs
, but it has a few
differences. First, we define the different tile types as an enumerated type:
enum
TileType
{
Background,
Normal,
Platform
}
In the
Tile
class, we then declare a member variable
type
to store the type of tile that
an instance represents:
protected
TileType type;
Next to these basic tile types, we also have ice tiles and hot tiles. In the level file,
an ice tile is represented by the '*' character (or the '@' character if it is a platform
tile), and a hot tile is represented by the 'ˆ ' character (or the '+' character for the
platform version). We add two boolean member variables to the
Tile
class with their
associated properties to be able to represent these different kinds of tiles. Now, let
us have a look at the
Level
class.
25.6 Setting up the
Level
Class
Given everything that we want to do, the
Level
class is likely going to be quite large.
Inside that class, we have to load the tiles from a text file, deal with different game