-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
55 lines (51 loc) · 1.5 KB
/
game.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
50
51
52
53
54
55
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
const gameTop = 0;
const gameBottom = canvas.height;
const gameLeft = 0;
const gameRight = canvas.width;
/*
*
* Use these for keyboard event handling if needed
* For example, in the draw function:
* if (rightPressed && (characterX + character.width) <= gameRight) characterX += 1
*
*/
// let rightPressed = false;
// let leftPressed = false;
// let upPressed = false;
// let downPressed = false;
// document.addEventListener('keydown', keyDownHandler, false);
// document.addEventListener('keyup', keyUpHandler, false);
// function keyDownHandler(e) {
// if (e.keyCode === 39) {
// rightPressed = true;
// } else if (e.keyCode === 37) {
// leftPressed = true;
// } else if (e.keyCode === 38) {
// upPressed = true;
// } else if (e.keyCode === 40) {
// downPressed = true;
// }
// }
// function keyUpHandler(e) {
// if (e.keyCode === 39) {
// rightPressed = false;
// } else if (e.keyCode === 37) {
// leftPressed = false;
// } else if (e.keyCode === 38) {
// upPressed = false;
// } else if (e.keyCode === 40) {
// downPressed = false;
// }
// }
function draw() {
// Clear the canvas before drawing new elements in every frame
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Insert game ending code in 'if' statement
// if ('something terrible and game-ending happens') {
// alert("GAME OVER");
// document.location.reload();
// }
}
setInterval(draw, 10);