-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.js
45 lines (36 loc) · 1.15 KB
/
play.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
//note - use Firebase for auth - just key/value pairs - save as bonus feature
const changeBackgroundImage = require('./background');
const Game = require('./lib/game');
const ui = require('./lib/ui');
const database = require('./lib/db');
const gameLoop = require('./lib/game_loop');
window.addEventListener("load", () => {
const currentHighscores = ui.getScoreData(database);
const canvas = document.getElementById('game-canvas');
canvas.width = 800;
canvas.height = 500;
const ctx = canvas.getContext('2d');
ctx.fillStyle = "black";
ctx.rect(0, 0, 800, 500);
ctx.fill();
let bgNum = 1;
setTimeout(setInterval( () => {
let nextNum = changeBackgroundImage(bgNum);
bgNum = nextNum;
}, 10000), 10000);
$("#audio-toggle").click( () => {
let audio = $("audio")[0];
if (audio.paused) {
audio.play();
$("#audio-logo").attr("src", "./assets/speaker.png");
} else {
audio.pause();
$("#audio-logo").attr("src", "./assets/mute.png");
}
});
$('form').on('submit', (e) => { ui.submitHighScore(e); });
let game = new Game(ctx, 20);
window.setInterval(() => {
gameLoop(ctx, game);
}, 25);
});