-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (31 loc) · 1.06 KB
/
main.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
import { keys, initialize, loop } from "./logic.js";
import { getTile, getCharacter } from "./graphics.js";
import { getBase, getScene, getPlayer } from "./scene.js";
async function setup(base = false) {
const canvas = document.getElementById("canvas");
const context = canvas.getContext("2d");
const subject = await getCharacter(); // Player sprite
let object = getPlayer(); // Player properties
let environment;
if (base) {
environment = getBase(); // Environment base
} else {
const tile = await getTile(); // Environment sprite
environment = getScene(tile); // Environment configuration
}
return { context, environment, object, subject };
}
function main({ context, environment, object, subject }) {
({ environment, object } = initialize(environment, object));
document.onkeydown = function (e) {
keys[e.which] = true;
};
document.onkeyup = function (e) {
keys[e.which] = false;
};
window.onload = () =>
requestAnimationFrame(
loop.bind(loop, context, environment, object, subject)
);
}
main(await setup());