-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1.18 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
import Renderer from "./lib/renderer.js";
import Engine from "./lib/engine.js";
class Game {
constructor(canvas) {
this.engine = new Engine();
this.renderer = new Renderer(canvas, this.engine, 1000, 1460.5);
this.lastTick = performance.now();
this.update(this.lastTick);
this.song = document.createElement("audio");
this.song.src = "./rain_nice_today.mp3";
this.song.loop = true;
this.song.play();
document.querySelector("#music").addEventListener("click", () => {
if(this.song.paused) {
this.song.play();
}
else {
this.song.pause();
}
})
}
update(currentTime) {
requestAnimationFrame(this.update.bind(this));
let tick = currentTime - this.lastTick;
if(tick > 128) {
tick = 128;
}
this.engine.update(tick, currentTime);
this.renderer.update(tick, currentTime);
this.lastTick = currentTime;
}
}
window.addEventListener("load", () => {
window.game = new Game(document.getElementById("canvas"));
});