-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.js
42 lines (36 loc) · 942 Bytes
/
player.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
const MOVE_SPEED = 0.01;
const JUMP = -0.02;
const PLAYER_SIZE = new Vector(1.5, 2.25); //new Vector(3, 4.5);
class Player extends Entity {
/**
* @param {Vector} position
*/
constructor(position) {
super(position, PLAYER_SIZE);
this.colour = "red";
this.facing = "right";
}
/**
*
* @param {Number} lapse
* @param {Entity[]} entities
*/
update(lapse, entities) {
// controls:
this.motion.x = 0;
if (keys[key_mapping.left]) {
this.motion.x -= MOVE_SPEED;
this.facing = "left";
}
if (keys[key_mapping.right]) {
this.motion.x += MOVE_SPEED;
this.facing = "right";
}
if (rising_edge(key_mapping.up)) {
this.motion.y = JUMP;
}
this.motion.y += GRAVITY;
super.update(lapse, entities);
return true;
}
}