91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
import "@pixi/layout";
|
|
import { Application, Assets, Container, Sprite } from "pixi.js";
|
|
import { Fridge, Opinator, SmartMonday } from "./games";
|
|
import { backgroundLayout, KeyBoardListener } from "./common";
|
|
|
|
const app = new Application();
|
|
let root = new Container();
|
|
|
|
async function setup() {
|
|
await app.init({ background: "#1099bb", resizeTo: window });
|
|
|
|
root = app.stage;
|
|
const setRootLayout = () => {
|
|
root.layout = {
|
|
width: app.screen.width,
|
|
height: app.screen.height,
|
|
maxWidth: app.screen.width,
|
|
maxHeight: app.screen.height,
|
|
};
|
|
};
|
|
setRootLayout();
|
|
app.renderer.on("resize", () => {
|
|
setRootLayout();
|
|
});
|
|
document.body.appendChild(app.canvas);
|
|
}
|
|
|
|
async function preload() {
|
|
const assets = [
|
|
{
|
|
alias: "background",
|
|
src: "assets/img/background1.jpg",
|
|
},
|
|
{
|
|
alias: "opinator",
|
|
src: "assets/img/opinator.avif",
|
|
},
|
|
{
|
|
alias: "frigo",
|
|
src: "assets/img/frigo.jpg",
|
|
},
|
|
{
|
|
alias: "clubmate",
|
|
src: "assets/img/clubmate.png",
|
|
},
|
|
{
|
|
alias: "clubmate_grey",
|
|
src: "assets/img/clubmate_grey.png",
|
|
},
|
|
{
|
|
alias: "mate_caisse",
|
|
src: "assets/img/caisse.jpg",
|
|
},
|
|
];
|
|
await Assets.load(assets);
|
|
|
|
KeyBoardListener.init();
|
|
}
|
|
|
|
function switchToGame(gameContainer, newGame) {
|
|
//empty previous container
|
|
//create new game and add
|
|
}
|
|
|
|
(async () => {
|
|
await setup();
|
|
await preload();
|
|
|
|
const background = Sprite.from("background");
|
|
background.layout = backgroundLayout;
|
|
|
|
root.addChild(background);
|
|
|
|
const gameContainter = new Container();
|
|
gameContainter.layout = {
|
|
position: "absolute",
|
|
width: "100%",
|
|
height: "100%",
|
|
maxWidth: "100%",
|
|
maxHeight: "100%",
|
|
margin: 0,
|
|
};
|
|
const opinator = new Opinator();
|
|
const fridge = new Fridge();
|
|
const smartMonday = new SmartMonday();
|
|
//gameContainter.addChild(fridge.gameContainer);
|
|
gameContainter.addChild(opinator.gameContainer);
|
|
gameContainter.addChild(smartMonday.gameContainer);
|
|
|
|
root.addChild(gameContainter);
|
|
})();
|