• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 13. Detecting Collisions > Keeping Track of Your Enemies

Keeping Track of Your Enemies

In order to check for collisions between the bullets and the enemy ships, as well as your ship and the enemy ships, you will need to know which sprites are enemies. You could create a list of enemies at the start of each level and use that to check against. But that's a little too manual, and also problematic: if you added or deleted more enemies in a level, the list would need to be updated to prevent errors.

Creating the Enemy List

Instead, of manually creating and updating the list, you can have the enemy ships themselves update the list. We'll call this list enemyList, and it will be cleared at the start of each level. Each enemy sprite will then add its sprite number to the list, within the beginSprite handler of the enemy_move behavior.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint