Posts
Search
Contact
Cookies
About
RSS

Creating a simple game (part 4)

Added 30 Jun 2019, 11:52 a.m. edited 18 Jun 2023, 7:15 p.m.

You can see the start of the series here

Okay things really start hotting up now as we introduce shooting... Lets look at the states, no wait this time there isn't any, just a simple structure

typedef struct shot {
     bool isAlien;
     Vector3 pos;
 } shot;

Each shot has a position and a flag so we know if its an alien shot or the players (so kind of a state!). To track our array of shots we're using PoolArray.h which has previously been introduced here. Briefly it uses a couple of lists to track which items (shots) in the array are active and which are available for use. Having the array tracked by lists means we don't have to scan through the list looking for one that's not being used next time the player or an alien shoots. While we are limited to a maximum number of shots active at once, we can quickly make "new" shots and "delete" ones we've finished with, as often as we like, with little overhead.

Other than moving the shot differently depending if its a player or alien shot, each shot must me check against either the player or each of the aliens. Because all we have to do is change mode when something is destroyed there's no additional complications like tracking lives etc.

Despite really bringing things alive and despite the slight extra though needed for the pool array there isn't a great deal of extra code to look at.

We're almost done, but next time I'll provide my implementation of am_Dive for now you can get the code here

The next part of the tutorial is here