This chapter covers
- How the NES handles player objects (sprites)
- Defining patterns for our player and bullet
- Controlling the timing of movement and gameplay
- Getting objects moving on the screen
- Testing the gamepad direction and moving the player’s ship left or right
- Testing the gamepad fire button and placing a bullet on the screen
- Moving the current player’s 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 onscreen using special objects provided by the NES hardware called sprites.
We will use the sprites to display our player’s ship onscreen 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 moving 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.