7 Move and shoot
This chapter covers
- Look at how the NES handles player objects (sprites)
- Defining some patterns for our player and bullet.
- How to control the timing of movement and gameplay.
- Get some objects moving on the screen.
- Testing the gamepad direction and moving the player ship left or right.
- Testing the gamepad fire button and placing a bullet on the screen.
- Moving the current player bullet up the screen.
In the last chapter, we drew our background graphics for both the title screen and the main game screen. In this chapter, we can look at how you display the player objects on screen using special objects provided by the NES hardware called sprites.
We will use the sprites to display our player’s ship on screen and allow the player to move it left and right using the game controller.
Then we will use another sprite to display the player’s bullet that will be triggered by the player pressing one of the action buttons on the game controller and then move up to the top of the screen.
7.1 NES Sprites
Rather than having to draw moving objects on the screen by changing the individual pixels that are displayed, the NES PPU allows the programmer to define up to 64 objects, called “sprites”, that sit either in front of or behind the tile patterns. The NES PPU then determines what needs to be displayed and renders the final pattern to the screen.