Win when all enemies are removed

Hello,

I am new to MakeCode and trying to figure out something I think should be simple. How can I end the game when all my enemies are destroyed. I tried a If/Then with Enemies = Zero, but it seems like you cannot compare that. I did see someone mention arrays, but I am not sure how to do that.

Any help would be appreciated. Just making a knock-off Pac Man for fun.

Thanks,

At game start make a variable called totalGhosts and set it to 3 (or whatever number of ghosts you have). In the block where you detect your pacman eating a ghost change totalGhosts by -1. In game update block do a logic statement If totalGhosts = 0 then Reset Game with Win condition.

1 Like

okay, so use a variable as a type of score count. If an enemy is destroyed, then the variable will +1. And so depending on the number of enemies in your game (we’ll say 10), then later you would say if the variable = 10, then you win.

1 Like

That work too! I would have thought of making my own variable instead of try to read the sprite types. Thank you, both!!

1 Like

Thank you!!! That makes complete sense!