-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyController.pde
52 lines (45 loc) · 1.11 KB
/
EnemyController.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class EnemyController {
ArrayList<Enemy> enemies;
Timer timer;
float spawnDelay;
int maxTotalPower;
int totalPower;
EnemyController() {
enemies = new ArrayList();
timer = new Timer();
spawnDelay = 3;
maxTotalPower = 20;
}
void update() {
if (timer.time > spawnDelay && totalPower < maxTotalPower) {
createEnemy();
timer.time= 0;
}
ArrayList<Enemy> collidedEnemies = new ArrayList();
for (Enemy enemy : enemies) {
enemy.update();
if (enemy.isFlagged) {
totalPower -= enemy.power;
collidedEnemies.add(enemy);
}
}
enemies.removeAll(collidedEnemies);
timer.update();
}
private void createEnemy() {
Enemy e = new Enemy();
e.x = boss.x;
e.y = boss.y;
int damage = (int) random(1, 6);
int speed = (int) random(1, 6);
int health = (int) random(1, 6);
e.power = damage + speed + health;
e.damage = 1 * damage;
e.speed = 1 * speed;
e.health = 1 * health;
e.size = 70 / (2 * e.speed);
spawnDelay = e.power / 2.0;
e.init();
enemies.add(e);
}
}