Game Development Reference
Colliding with the enemies
If the player touches any of the enemies, the health meter at the top-left corner of the stage is
reduced, as shown in Figure 8-21.
Figure 8-21. When an enemy touches the player, the health meter is reduced.
This is the code in the @qjcakjKja[I]j]can that causes it to happen:
Before the meter can be reduced, the code has to check whether the enemy objects are actually on
the stage. You can find out if an object exists by checking whether it has a jqhh value like this:
The code needs to find out whether the ajaiuKja object exists because if it makes a reference to
an object that doesn't actually exist, the compiler will generate a deluge of errors when the program
runs. The enemy objects can be removed from the game by being shot by the player's bullets, so
there's a chance they might not actually exist at some point. You can't take the chance that the code
might not be able to find them.