-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
49 lines (47 loc) · 1.31 KB
/
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
43
44
45
46
47
48
49
export class Player {
x = 838
y = 700
r = 80
velX = 0
velY = 0
row = 3
menu
update(menu){
this.menu = menu
this.x += this.velX
this.y += this.velY
this.velX = this.velX *.95
this.velY = this.velY *.99
this.velY += .5
if (this.y <= 100 && this.velY <0) {
this.velY = 0
this.y = 100
}
}
Input(){
document.addEventListener('keydown', (event) => {
var code = event.code;
//alert(`Key pressed ${name} \r\n Key code value: ${code}`);
if (!this.menu) {
if (code == "ArrowRight" || code == "KeyD") {
if (this.row < 5) {
this.velX += 15
this.row++
}
}
if (code == "ArrowLeft" || code == "KeyA") {
if (this.row > 1) {
this.velX -= 15
this.row--
}
}
if (code == "ArrowUp" || code == "KeyW") {
this.velY -= 20
}
if (code == "ArrowDown" || code == "KeyS") {
this.velY += 20
}
}
}, false);
}
}