-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
39 lines (35 loc) · 952 Bytes
/
controller.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
let keypressed = undefined;
function Keypress(event) {
let key = event.code;
if (key == "KeyA") {
keypressed = "left" ;
} else if (key == "KeyD") {
keypressed = "right";
} else if (key == "KeyW") {
keypressed = "up";
} else if (key == "KeyS") {
keypressed = "down";
}
}
function Shoot(event){
let key = event.code;
if (key == "Space" && status == "idle") {
let {x, y} = ship.cannon();
let {x: vx, y: vy} = trig(0, 0, ship.angle, 10);
bullets.push(new Bullet(x, y, vx, vy, "white"));
}
}
function KeypressReset() {
keypressed = undefined;
}
function PlayerMovement() {
if (keypressed == "up") {
ship.speed += ship.acc;
} else if (keypressed == "down") {
ship.speed -= ship.acc;
} else if (keypressed == "left"){
ship.angle -= ship.turn;
} else if (keypressed == "right") {
ship.angle += ship.turn;
}
}