-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (28 loc) · 849 Bytes
/
index.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 {
canvas, context, startScreen, loadingFinished, loadingProgress,
} from './js/Canvas.js';
import Game from './js/classes/Game.js';
startScreen();
// sounds.bgmusic.play();
const game = new Game(canvas, context);
let imageLoadProgress = 0;
let audioLoadProgress = 0;
let gameIsReady = false;
function mainLoop() {
window.requestAnimationFrame(mainLoop);
if (game.gameStarted) {
game.gameLoop();
} else {
if (!gameIsReady) {
imageLoadProgress = game.images.loadProgress();
audioLoadProgress = game.sounds.loadProgress();
loadingProgress((imageLoadProgress + audioLoadProgress) / 2);
if (imageLoadProgress === 1 && audioLoadProgress === 1) {
gameIsReady = true;
loadingFinished();
}
}
if (actions.any.pressed === true && gameIsReady) game.startGame();
}
}
mainLoop();