summaryrefslogtreecommitdiff
path: root/src/main.js
blob: 68223510c87fa8a42d1a9762a3649d82daa2127e (plain)
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
///////////////////// 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()
}