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 ...

Get Haxe Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.