forked from BogomilDimitrov/JavaScriptGameFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.js
More file actions
36 lines (29 loc) · 1.1 KB
/
enemy.js
File metadata and controls
36 lines (29 loc) · 1.1 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
var Enemy = (function () {
function Enemy(x, y) {
this.width = 76;
this.height = 85;
this.velocity = 1.5;
this.velocityModifier = 0;
this.movement = {left: false, right : false, up: false, down : false};
this.isHit = false;
this.position = new Vector2(x, y);
this.animation = new Animation(this.width, this.height, 0, 0, 8, 'ressources/images/bird.png', 8, 3, 3);
this.boundingBox = new Rectangle(x, y, this.width, this.height);
}
Enemy.prototype.update = function () {
if(this.movement.right && !this.isHit) {
this.position.x += this.velocity + this.velocityModifier;
}
if(this.movement.down && this.isHit) {
this.position.y += this.velocity + this.velocityModifier;
}
this.animation.position.set(this.position.x, this.position.y);
this.boundingBox.x = this.position.x;
this.boundingBox.y = this.position.y;
this.animation.update();
};
Enemy.prototype.render = function(ctx) {
this.animation.draw(ctx);
};
return Enemy;
}());