-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
47 lines (43 loc) · 873 Bytes
/
main.js
File metadata and controls
47 lines (43 loc) · 873 Bytes
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
var width = 600;
var height = 600;
var cellSize = 20;
var fps = 10;
gameCallback = function() {
scoreElement.innerHTML = game.getScore();
console.log("trying to update score... " + game.getScore());
}
window.onload = function() {
game = new Game('canvas', width, height, cellSize, fps, gameCallback);
scoreElement = document.getElementById('score');
}
window.onkeydown = function(ev) {
switch(ev.keyCode) {
case 32:
if(game.isStopped()) {
game.start();
}
else if(game.isPaused()) {
game.resume();
}
else if(game.isRunning()) {
game.pause();
}
break;
case 72:
case 37:
game.left();
break;
case 75:
case 38:
game.up();
break;
case 76:
case 39:
game.right();
break;
case 74:
case 40:
game.down();
break;
}
}