something

This commit is contained in:
koneko 2024-09-22 19:47:05 +02:00
parent 754c863e60
commit cc51c3831d
6 changed files with 63 additions and 3 deletions

0
src/classes/GUI.ts Normal file
View File

15
src/classes/Game.ts Normal file
View File

@ -0,0 +1,15 @@
import { Renderer } from "./Renderer.ts";
import { BaseScene, SceneType, makeSceneFromType } from "./Scenes.ts";
export class Game {
public Renderer: Renderer;
public currentScene: BaseScene;
constructor(sceneType: SceneType) {
this.Renderer = new Renderer();
this.changeScene(sceneType);
}
changeScene(sceneType): void {
if (this.currentScene != undefined) this.currentScene.destroy();
this.currentScene = makeSceneFromType(sceneType);
}
}

View File

@ -5,6 +5,7 @@ export enum CellType {
Path,
NoBuild,
Build,
Undefined,
}
export class Cell {
@ -33,8 +34,11 @@ export class Grid {
x: x,
y: y,
});
for (let index = 0; index < rows * columns; index++) {
// const cell = new Cell();
for (let y = 0; y < rows; y++) {
for (let x = 0; x < columns; x++) {
let cell = new Cell(x, y, CellType.Undefined);
this.cells.push(cell);
}
}
}
@ -51,4 +55,6 @@ export class Grid {
pixelsToGridUnits(pixels: number): number {
return pixels / this.getPixelScalingFactor();
}
render() {}
}

5
src/classes/Renderer.ts Normal file
View File

@ -0,0 +1,5 @@
import * as PIXI from "pixi.js";
export class Renderer {
constructor() {}
}

31
src/classes/Scenes.ts Normal file
View File

@ -0,0 +1,31 @@
import * as PIXI from "pixi.js";
export function makeSceneFromType(type: SceneType) {
if (type == SceneType.MainMenu) {
return new MainMenu();
}
if (type == SceneType.MissionSelect) {
return new MissionSelect();
}
}
export enum SceneType {
MainMenu,
MissionSelect,
}
export class BaseScene {
public type: SceneType = null;
public destroy(): boolean {
return true; // return when destroyed
}
}
export class MainMenu extends BaseScene {
public type: SceneType = SceneType.MainMenu;
public;
}
export class MissionSelect extends BaseScene {
public type: SceneType = SceneType.MissionSelect;
}

View File

@ -1,12 +1,15 @@
import * as PIXI from "pixi.js";
import { Game } from "./classes/Game.ts";
import { SceneType } from "./classes/Scenes.ts";
(async () => {
const app = new PIXI.Application();
await app.init({
width: 640,
height: 360,
resizeTo: document.body,
backgroundColor: "white",
});
document.body.appendChild(app.canvas);
globalThis.Game = new Game(SceneType.MainMenu);
})();