From a840990bdcabf45fb0d377478ba0ab27222434ae Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Mon, 23 Dec 2024 18:32:29 +0100 Subject: initial commit --- src/main.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main.js (limited to 'src/main.js') diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..6822351 --- /dev/null +++ b/src/main.js @@ -0,0 +1,38 @@ +///////////////////// IMPORTS ////////////////////// +import { Boshy } from "./entities/boshy.js" +import { SCENE, SCENES } from "./scenes.js" + + +///////////////////// GLOBALS ////////////////////// +export let boshy +export const bullets = { + list: [], + remove: instance => { bullets.list = bullets.list.filter(b => b != instance) }, + clear: _ => { bullets.list.forEach(b => b.remove()) } +} + +///////////////////// GAME LOGIC ////////////////////// +export function start() { + console.log("game start") + changeScene(SCENES.PREQUEL) +} + +export function update() { + boshy.update() + bullets.list.forEach((bullet) => bullet.update()) + SCENE.update() +} + +export function draw() { + boshy.draw() + bullets.list.forEach((bullet) => bullet.draw()) + SCENE.draw() +} + + +///////////////////// SCENE METHODS ////////////////////// +export function changeScene(scene) { + SCENE.load(scene) + bullets.clear() + boshy = new Boshy() +} -- cgit v1.2.3