Game Development Reference
In-Depth Information
This constant defines the movement speed of the player. A constant is just a variable
whose value can never be changed after it is initialized, so its value is always the
same. Now, we need a place to store the information about our player character. We
will create a structure named Player . Just add it right below the constant we just
made with the following code:
public struct Player
{
public float PositionX;
public float PositionY;
public int AnimFrame;
public double LastFrameChange;
}
The first two member variables in this struct store the player's current location within
the 2D world. The AnimFrame variable keeps track of the current animation frame
that the player character is on, and the last variable keeps track of how long the play-
er character has been on the current animation frame. This is used to ensure that
the animation runs at about the same speed regardless of how fast your PC is.
We need to add a second struct below this one now. We will name this struct Tile .
It stores information on a single tile. As you might guess, we will be creating a list of
these structures containing one for each tile type in our game world. The following is
the Tile struct:
public struct Tile
{
public bool IsSolid;
public int SheetPosX;
public int SheetPosY;
}
The first variable indicates whether this tile is solid or not. If a tile is solid, it means
that the player cannot walk on it or through it. So, for example, a brick wall tile would
have this set to true , since we don't want our players to be walking through brick
walls! The last two member variables of this struct hold the coordinates of the tile's
image within the tile sheet.
Search WWH ::




Custom Search