Skip to navigation


Alien feeding and growth patterns

The many stages of the alien life cycle

The aliens in Aviator have a pretty predictable life cycle, which is important to understand if we're going to defend Acornsville from attack. In this deep dive, we take a look at the typical alien's progression from cute little triangle-shaped baby to tentacle-sprouting harbinger of doom.

Spawning baby aliens
--------------------

If we activate the Theme by firing the guns while still on the runway, the game gets started on the process of spawning the first wave of eight baby aliens. The routine responsible for this reckless act of midwifery is SpawnAlien, which is called from part 1 of the main loop.

Aliens are spawned in fields, with no more than one alien per field. There are 14 fields scattered around the map (see the deep dive on placing objects on the map for details), and the SpawnAlien routine tries to spawn one new alien each time it is called, using a brute-force method to find an empty field. This approach doesn't always work, so it's possible for the aliens to spawn sporadically, taking more than eight calls to SpawnAlien to give birth to the first wave.

At the end of this process, eight aliens have been added to the world. Each of them has a state, stored in the alienState table, and each of them has an associated field object, whose ID is stored in the alienObjectId table.

Let's see what happens next...

Alien stages
------------

The evolution of aliens is encoded in the UpdateAliens routine. There are four alien slots that map to objects 30 to 33; at the start of each wave, slot 30 contains all eight newly spawned aliens, which work in a similar way to the groups of trees and hills in objects 6 to 9. Slots 31 to 33, meanwhile, start out empty... but not for long.

All eight aliens in slot 30 start in the dormant state (state 0, which is stored in the alienState table). Dormant aliens are promoted to state 1 in part 2 of UpdateAliens. One alien will be promoted and will start feeding once there is a vacancy in one of slots 31 and 32 (which both start out as vacant, so straight away we promote two dormant aliens). A vacancy is produced when one of the feeding aliens is promoted into an empty alien slot 33 (see below), or when a feeding alien is destroyed.

Once an alien is in state 1, the state gets incremented in part 1 of UpdateAliens, but only on 2 of every 256 main loop iterations. The alien's state increases like this, passing through the four feeding stages and growing all the while (see the next section for more on growth patterns). It keeps progressing until it reaches state 22.

As there can be only one alien flying towards the town at any one time, we have to wait for the attack slot (slot 33) to become vacant, at which point an alien in this state will be put into slot 33, and its state bumped up to 23 in part 3 of UpdateAliens.

Once an alien is in state 23, the state gets incremented in the UpdateAliens routine on 2 of every 256 main loop iterations, until it reaches 27, at which point it will take off and head for the town, before eventually descending to the town at state 28.

Here's a summary of all the alien states:

StageDetailsAliensSlot
0Dormant830
1-7Feeding stage 1231-32
8-11Feeding stage 2231-32
12-15Feeding stage 3231-32
16-21Feeding stage 4231-32
22Finished feeding231-32
23-26Preparing to take off133
27Flying towards Acornsville133
28Descending towards Acornsville for the final attack133

See the deep dive on Aliens attack Acornsville! to see what happens when an alien reaches the final stages.

Alien growth patterns
---------------------

As aliens move through the four feeding stages above, they get bigger. This growth is managed in part 4 of UpdateAliens, which works out if the alien is about to move into a new feeding stage, and if it is, doubling the size of the alien.

The ResizeFeedingAlien routine is responsible for changing the alien's size. It can either double the size of an alien, or reset the alien to the dormant stage, depending on the arguments passed to the routine. Specifically, the routine resizes the alien in slot 31 or 32 by changing the object's scale factor. The object points that make up each object are stored relative to the object's anchor point, and they are stored with a scale factor in bits 4 to 7 of the z-coordinate in the zObjectPoint table. This means we can double the size of the alien by simply adding 1 to the scale factor, which we can do by adding 16 (%00010000) to each z-coordinate. As the scale factor is a power of 2, adding 1 to the scale factor in the top nibble of the z-coordinate will double the size of the object. See the deep dive on 3D objects for more about how objects are stored.

The aliens in slots 30 and 33 doesn't change size, as they are always either small triangles (for slot 30), or fully grown aliens with tentacles (for slot 33). Only the feeding aliens in slots 31 and 32 grow.

New wave
--------

The final task, which is performed by part 5 of UpdateAliens, is to check whether all eight aliens in the wave have been destroyed, and if they have, to start the spawning process all over again.

In the process, the ScorePoints routine is called to make a beep and add 500 points to the score. This is the good news; the bad news is that the value of the alienSpeed variable is increased by 4. This starts out with a value of 10 for each new game, and increases with each new wave to 14, then 18, and finally 22. This variable controls the speed at which the flying alien heads towards the town, so later waves fly more than twice as fast as the initial wave.

If Aviator contains any influences from Geoff Crammond's previous game, Super Invaders, then this is perhaps the most obvious candidate. The aliens in Aviator are relentless and increasingly aggressive in their attack, just like those in his eponymous debut game... though perhaps with a small step up in sophistication.