forked from maglob/cave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcave.js
46 lines (46 loc) · 918 Bytes
/
cave.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
function init() {
function tick() {
frame++;
if (ship.controls.left)
ship.a -= 4;
if (ship.controls.right)
ship.a += 4;
var e = document.getElementById("ship");
e.setAttribute("transform", "translate("+ ship.x +","+ ship.y +") rotate("+ ship.a +")");
if (frame<1000)
setTimeout(tick, 50);
}
function keydown(e) {
switch(e.keyCode) {
case 65:
ship.controls.left = true;
break;
case 68:
ship.controls.right = true;
break;
}
}
function keyup(e) {
switch(e.keyCode) {
case 65:
ship.controls.left = false;
break;
case 68:
ship.controls.right = false;
break;
}
}
var frame = 0;
var ship = {
x: 200,
y: 100,
a: 0,
controls: {
left: false,
right: false
}
};
document.onkeydown = keydown;
document.onkeyup = keyup;
tick();
}