Adding the player

So we now have a working tile map, and what looks like a piece of a robotic vehicle that we can move around on the map. There are a number of issues right now, however:

  • The robot we can move around simply floats around without animation or direction.
  • Our floating sprite does not obey any kind of screen or world limitations. It will happily fly off into oblivion if you hold down the movement keys.
  • Similarly, the sprite is not blocked by wall tiles. It will float right over them.
  • Moving the sprite to the right or bottom edges of the screen doesn't scroll the camera to follow the sprite. Our camera is currently controlled by a separate set of movement keys.

In order to begin addressing these issues, we need to construct a class for the player's robo-tank. If you look at the SpriteSheet.png image, you will see that the player's robot is split into a couple of pieces. The treaded base that we currently have floating around on the screen will provide the base for the player's character:

Adding the player

On top of the base, we will place one of the available gun turrets located below the tank base on the sprite sheet. Both the base and the turret will rotate independently, allowing the user to move and fire in any combination of directions.

Building the Player class

The Player class will handle both tracking and displaying the player's robo-tank, and dealing with user input. We will start by building the basics to display the two sprites that comprise the player's tank.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.149.242