-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (28 loc) · 896 Bytes
/
app.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
import { Game } from './game.js';
import { GameState } from './util.js';
import Pipe from './pipe.js';
window.addEventListener('load', function () {
document.body.style.visibility = 'visible';
const game = new Game(
document.querySelector('.gameWindow'),
document.querySelector('.gameWindow').getContext('2d'),
);
const startbtn = this.document.querySelector('.startbtn');
startbtn.onclick = async function () {
console.log('Start Game');
const result = await game.init();
console.log(result);
game.state = GameState.GAME;
};
function animate() {
//console.log('Animate');
window.requestAnimationFrame(animate);
if (game.state === GameState.GAME) {
game.ctx.clearRect(0, 0, game.canvas.width, game.canvas.height);
game.update();
game.draw();
}
}
window.requestAnimationFrame(animate);
console.log(game.state);
});