36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
"use strict";
|
|
// import {Intro as game_intro} from "./Intro";
|
|
// import game_play from "./game.js";
|
|
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
|
|
|
|
function init() {
|
|
let ctx, canvas = document.createElement("canvas");
|
|
canvas.width = 360; // window.innerWidth
|
|
canvas.height = 640; // window.innerHeight
|
|
ctx = canvas.getContext('2d');
|
|
document.body.insertBefore(canvas, document.body.childNodes[0]);
|
|
let container = document.querySelector("body");
|
|
let resize = (e) => {
|
|
container.clientWidth / container.clientHeight > 1
|
|
? (canvas.style.height = "100vh") && (canvas.style.width = "auto")
|
|
: (canvas.style.height = "auto") && (canvas.style.width = "100vw");
|
|
};
|
|
resize();
|
|
container.onresize = resize;
|
|
|
|
|
|
let key = new Keyboard(), board;
|
|
function runBoard(stage) {
|
|
switch (stage) {
|
|
case 1: board = new GamePlay(ctx, key); break;
|
|
default: board = new GameIntro(ctx, key); break;
|
|
}
|
|
board
|
|
.run()
|
|
.then(stage => runBoard(stage), e => { });;
|
|
}
|
|
runBoard(0);
|
|
}
|