-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenemies.js
More file actions
74 lines (61 loc) · 1.8 KB
/
enemies.js
File metadata and controls
74 lines (61 loc) · 1.8 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var golems; // variable for golem group
/*
// more complicated than using groups
// base class for enemies
class enemy {
// enemy class methods
constructor(x, y, w, h) {
this.sprite = new Sprite();
}
// abstract methods - for implementation in extended classes
moveRight() {}
moveLeft() {}
moveDown() {}
moveUp() {}
behavior() {}
attack() {}
// class attributes
sprite;
speed;
}
*/
// function to create golem enemy group - run in preload
function createGolemGroup() {
golems = new Group();
golems.scale = 3;
golems.collider = 'kinematic';
golems.debug = true;
// golems.overlaps(wizard.sprite);
}
var golemSpeed = 2;
// outside of golem class so it applies to all golem objects
function golemBehavior() {
// hold 'o' key to activate golem behavior
if (kb.pressing('o')) {
for (let i = 0; i < golems.length; i++) {
// moves golem to wizard
golems[i].moveTo(wizard.posx, wizard.posy, golemSpeed)
// "kills" wizard if golem hits him - do we need an attack animation?
if (golems[i].overlaps(wizard.sprite)) {
// replace with death function once its done
wizard.sprite.position.x = 25;
wizard.sprite.position.y = 25;
}
// kills golem if it is hit
for (let j = 0; j < spells.length; j++) {
if (golems[i].overlaps(spells[j].sprite)) {
golems[i].life = 0;
}
}
}
}
}
// sublcass for golem enemy
class golem {
constructor(x, y) {
// last two numbers change sprite physical size - uncomment debug to see
this.sprite = new golems.Sprite(x, y, 12, 16)
this.sprite.addAni(golemIdle);
}
sprite;
}