forked from BogomilDimitrov/JavaScriptGameFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.js
More file actions
39 lines (31 loc) · 1.14 KB
/
player.js
File metadata and controls
39 lines (31 loc) · 1.14 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
var Player = (function(){
function Player(x, y) {
this.position = new Vector2(x, y);
this.movement = {left: false, right : false, up: false, down : false};
this.velocity = 20;
this.width = 40;
this.height = 52;
this.animation = new Animation( this.width, this.height, 0, 0, 22, 'ressources/images/robin.png', 22, 5, 5);
this.boundingBox = new Rectangle ( x, y, this.width, this.height)
}
Player.prototype.update = function() {
if(this.movement.right) {
this.position.x += this.velocity;
} else if(this.movement.left) {
this.position.x -= this.velocity;
}
if(this.movement.up) {
this.position.y -= this.velocity;
} else if(this.movement.down) {
this.position.y += this.velocity;
}
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();
};
Player.prototype.render = function(ctx) {
this.animation.draw(ctx);
};
return Player;
}());