-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartGame.js
27 lines (25 loc) · 902 Bytes
/
startGame.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
function startGame() {
myGamePiece = new Circle(300, 240,20,"blue");
myObstacle = new Circle(rand(), 0, 20, "red");
myGameArea.start();
}
var myGameArea = {
canvas : document.createElement("canvas"),
start : function() {
this.context = this.canvas.getContext("2d");
this.canvas.width = 600;
this.canvas.height = 270;
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.interval = setInterval(updateGameArea, 30);
window.addEventListener('keydown', function (e) {
myGameArea.keys = (myGameArea.keys || []);
myGameArea.keys[e.keyCode] = true;
})
window.addEventListener('keyup', function (e) {
myGameArea.keys[e.keyCode] = false;
})
},
clear : function() {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}