forked from aframevr/a-blast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy1.js
66 lines (65 loc) · 1.78 KB
/
enemy1.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
55
56
57
58
59
60
61
62
63
64
65
66
/* globals ABLAST */
ABLAST.registerEnemy(
// name
'enemy1',
// data
{
components: {
enemy: {
name: 'enemy1',
bulletName: 'enemy-fast',
color: '#FF7D00',
scale: 0.6,
health: 1
},
'collision-helper': {
debug: false,
radius: 0.3
},
'json-model': {
src: '#enemy1',
texturePath: 'url(assets/images/)',
singleModel: true
}
},
poolSize: 10
},
// implementation
{
init: function () {
this.shootingDelay = 5000;
this.warmUpTime = 1000;
this.reset();
},
reset: function () {
var el = this.el;
var sc = this.data.scale;
this.actualShootingDelay = this.shootingDelay + Math.floor(this.shootingDelay * Math.random());
el.addEventListener('model-loaded', function(event) {
el.getObject3D('mesh').scale.set(sc, sc, sc);
});
this.lastShoot = undefined;
this.willShootEmited = false;
},
tick: function (time, delta) {
if (this.lastShoot == undefined ) {
this.lastShoot = time;
}
else if (time - this.lastShoot > this.actualShootingDelay) {
// don't shoot when behind the player
var pos = this.el.getAttribute('position');
if (pos.z < 0 && pos.y > 0) {
this.el.components.enemy.shoot(time, delta);
this.lastShoot = time;
this.willShootEmited = false;
this.actualShootingDelay = this.shootingDelay * (Math.random() < 0.5 ? 2 : 1);
}
}
else if (!this.willShootEmited && time - this.lastShoot > this.actualShootingDelay - this.warmUpTime) {
this.el.components.enemy.willShoot(time, delta, this.warmUpTime);
this.willShootEmited = true;
}
},
onHit: function (type) {}
}
);