9 Collision detection

This chapter covers

  • Object collision detection
  • Applying collision detection between our enemies and the player’s bullet

In most games, especially action games, there will be the need to know when one or more objects collide with each other. Because our sample game is a shoot-em-up, we need to know when our enemy objects encounter both our player and any player’s bullets. At this stage, our enemies are all a fixed size, but later we will introduce more enemies of different sizes, so we will need to take this into account with the collision detection routine we will introduce in this chapter.

9.1 Object collision detection

Our first step is to write a function that works out whether two objects of different sizes have hit ...

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.