-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.ts
51 lines (42 loc) · 1.59 KB
/
game.ts
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
46
47
48
49
50
51
import {values} from "@softwareventures/dictionary";
import {DisplayMode, Engine, Loader} from "excalibur";
import Menu from "./menu/menu.js";
import Music from "./music/music.js";
import {Performance} from "./performance/performance.js";
import resources from "./resources.js";
import Title from "./title/title.js";
export default class Game {
public readonly width = 640;
public readonly height = 480;
public readonly music = new Music();
public active = false;
public tempo = "";
public bpm = 0;
public stars = 0;
public readonly engine = new Engine({
viewport: {width: this.width, height: this.height},
resolution: {width: this.width, height: this.height},
displayMode: DisplayMode.Fixed,
antialiasing: false,
suppressHiDPIScaling: true,
suppressPlayButton: true
});
private anyKeyPressed = false;
public start(): void {
const loader = new Loader(values(resources));
this.engine.start(loader).then(
() => {
this.engine.input.keyboard.on("press", () => (this.anyKeyPressed = true));
this.engine.on("postframe", () => (this.anyKeyPressed = false));
this.engine.addScene("title", new Title(this));
this.engine.addScene("menu", new Menu(this));
this.engine.addScene("performance", new Performance(this));
this.engine.goToScene("title");
},
reason => void console.error("", reason)
);
}
public wasAnyKeyPressed(): boolean {
return this.anyKeyPressed;
}
}