-
Notifications
You must be signed in to change notification settings - Fork 1
/
human-spawner.js
54 lines (53 loc) · 1.33 KB
/
human-spawner.js
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
53
54
'use strict';
class HumanSpawner {
constructor () {
this.totalTime = 0;
this.nextHuman = 0;
this.nextEnemy = 0;
this.nextBuilding = 15000;
this.isSpawnable = false;
}
spawnNextHuman () {
let frequency = 8000 / ((this.totalTime / 22) + 1);
this.nextHuman = game.rnd.integerInRange(frequency / 2, frequency);
waveAttack.humans.push(new Human(game.rnd.integerInRange(HumanType.MAN, HumanType.MAN_FLY)));
}
spawnNextEnemy () {
let frequency = 10000 / ((game.humansKilled + 1) / 3);
this.nextEnemy = game.rnd.integerInRange(frequency / 2, frequency);
waveAttack.humans.push(new Human(HumanType.MISSILE_FAN));
}
spawnNextBuilding () {
this.nextBuilding = 15000;
waveAttack.building = new Building();
}
activateSpawn() {
this.isSpawnable = true;
}
desactivateSpawn() {
this.isSpawnable = false;
}
update(deltaTime) {
if (!this.isSpawnable)
return;
this.totalTime += deltaTime;
this.nextHuman -= deltaTime * 1000;
if (this.nextHuman < 0) {
this.spawnNextHuman();
}
if (game.humansKilled > 0) {
this.nextEnemy -= deltaTime * 1000;
if (this.nextEnemy < 0) {
this.spawnNextEnemy();
}
if (!game.building) {
this.nextBuilding -= deltaTime * 1000;
if (this.nextBuilding < 0) {
this.spawnNextBuilding();
}
} else {
game.building.update(deltaTime);
}
}
}
}