changed ball and bar for a sprite
This commit is contained in:
38
assets/js/index.js
Normal file
38
assets/js/index.js
Normal file
@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
// import {Intro as game_intro} from "./Intro";
|
||||
// import game_play from "./game.js";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
|
||||
|
||||
let resources = new Resources();
|
||||
|
||||
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user