Instantiating enemies and adding interaction
Next, we'll go back to PlayState
and create instances of our enemies, and then make enemies disappear when they're clicked. Finally, we'll then add to our score every time the player clicks on an enemy.
Adding new imports
Before adding functionality, we'll need to import some more classes we'll be using in PlayState
:
import flixel.plugin.MouseEventManager; import flixel.FlxObject; import flixel.util.FlxTimer;
Adding variables
Next, we'll add the new variables we'll need to track:
private var numEnemies:Int = 20; private var score:Int = 0; private var enemyPointValue:Int = 155; private var enemies:Array<Enemy>;
These variables are pretty straightforward: numEnemies
is the number of enemies we'll spawn in the game, score
is the player's current score, and enemyPointValue
is the number of points that will be added to your score each time an enemy is clicked. Finally, enemies
is an array that will...