How to detect if all enemies are dead
I have a shooting game. I randomly spawn many enemies and if all the enemies are dead, I win the game. The problem is that I do not know how to determine when all the enemies are dead since I randomly spawn all the enemies.
Could anyone help me with this?
Thanks.
Go Download "Sub Run" in App Store.
Comments
As each is spawned increase an attribute by 1, as each is killed reduce that attribute by 1 - when that attribute = 0 all the enemies are dead.
In your enemy actor, add a Change Attribute game.enemyCount to game.enemyCount+1 to the top of your rule list. It should not be inside of a rule... just a behavior on it's own. What that does is when each enemy spawns, it automatically increases the count by one. If you spawn 14 enemies, then game.enemyCount will be 14 after a split-second. Have a rule for when an enemy dies that changes game.enemyCount to game.enemyCount-1.
In your checkForWin actor, have a rule that says When attribute game.enemyCount=0, change to the win scene or whatever you prefer to have happen. The key is that you need to place this rule inside of a timer set to After 0.1 seconds. This timer is necessary because the enemies first need to increase the enemyCount attribute. Without the timer, the checkForWin actor will determine that since game.enemyCount is 0, the game is over.
Edit: didn't see @Socks' answer until after I posted but he's basically saying the same thing.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yeah, but I did my answer as an bleak existentialist poem.
Thanks for the quick answer. I will try it.
Go Download "Sub Run" in App Store.
Thanks man.
Go Download "Sub Run" in App Store.