8 Enemy movement

This chapter covers

  • Generating random numbers
  • Adding the logic to generate and display new enemy asteroids
  • Making the asteroids move down toward the player
  • Removing asteroids as they reach the bottom of the screen

In previous chapters, we placed the player’s ship on the screen and allowed the player to move the ship and fire bullets. Now we need to introduce some enemy objects for the player to shoot at and dodge away from as they move down the screen. Just like in the original Astro Smash game, our main enemy objects will be asteroids of various sizes that move down the screen at different speeds.

8.1 Generating random numbers

Before we start working directly on the enemy objects, it would be nice to have some randomness as ...

Get Classic Game Programming on the NES now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.