Game Development Reference
In-Depth Information
Now, let's return to the constructor and initialize the player character, which will be a
rather silly robot. Add the following code at the bottom of the constructor:
m_PlayerSprites =
LoadBitmap(Application.StartupPath +
"\\Robot.png");
m_Player = new Player();
m_Player.PositionX = 4;
m_Player.PositionY = 8;
The first line of code uses our LoadBitmap() method to load the robot sprite sheet
and store it in the m_PlayerSprites member variable. The second line creates the
player object to hold information about the player character. Finally, the last two lines
set the starting position for the player. Note that the coordinates (0, 0) represent the
upper-left corner of the screen. The robot sprite sheet is just a series of animation
frames for our robot that we will display one after another in quick succession to an-
imate the robot.
Now that the player object is initialized, we need to initialize the game world! The fol-
lowing is the first part of the code:
m_TileSheet =
LoadBitmap(Application.StartupPath +
"\\TileSheet.png");
m_TileList = new List<Tile>();
// First row of sprites in the sprite sheet.
m_TileList.Add(new Tile() { IsSolid = false,
SheetPosX = 0, SheetPosY = 0 });
m_TileList.Add(new Tile() { IsSolid = false,
SheetPosX = 1, SheetPosY = 0 });
m_TileList.Add(new Tile() { IsSolid = false,
SheetPosX = 2, SheetPosY = 0 });
m_TileList.Add(new Tile() { IsSolid = false,
SheetPosX = 3, SheetPosY = 0 });
Search WWH ::




Custom Search