-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenemy.js
More file actions
65 lines (51 loc) · 1.81 KB
/
enemy.js
File metadata and controls
65 lines (51 loc) · 1.81 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
import { makeSpell } from "./attacks.js";
export function enemy(p) {
return {
sprite: null,
enemies: null,
animations: {},
health: 1,
speed: 3,
isDead: false,
setup() {
this.enemies = new p.Group();
this.enemies.collider = 'none';
this.enemies.scale = 2;
this.enemies.debug = false;
console.log(p.minute());
},
preload() {
this.loadAnimations();
},
loadAnimations() {
this.animations.idle = p.loadAnimation('assets/golemIdle.png',
{ frameSize: [16, 16], frames: 4 });
this.animations.idle.frameDelay = 17;
this.animations.run = p.loadAnimation('assets/golemIdle.png',
{ frameSize: [16, 16], frames: 4 });
this.animations.run.frameDelay = 5;
},
spawn(x, y) {
this.sprite = new this.enemies.Sprite(x, y, 12, 16);
//this.sprite.mode = 'UNAWARE';
// console.log(this.sprite.mode);
this.sprite.addAni(this.animations.idle);
},
behavior(wizard) {
for (let i = 0; i < this.enemies.length; i++) {
if (p.millis() % 2 == 0) {
this.enemies[i].moveTo(wizard.posx, wizard.posy, 2);
}
//console.log('enemies length: ' + this.enemies.length);
if (this.enemies[i].overlaps(wizard.sprite) && !wizard.GDLMode) {
wizard.die();
}
for (let j = 0; j < wizard.spells.length; j++) {
if (this.enemies[i].overlaps(wizard.spells[j].spellSprite)) {
this.enemies[i].life = 0;
}
}
}
},
};
}