ShatteredSword/src/shattered_sword/Scenes/Levels.ts

144 lines
5.4 KiB
TypeScript
Raw Normal View History

2022-03-31 20:52:05 -04:00
import Scene from "../../Wolfie2D/Scene/Scene";
import ConfigManager from "../Tools/ConfigManager";
import SaveManager from "../Tools/SaveManager";
import Vec2 from "../../Wolfie2D/DataTypes/Vec2";
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
import Button from "../../Wolfie2D/Nodes/UIElements/Button";
import { UIElementType } from "../../Wolfie2D/Nodes/UIElements/UIElementTypes";
import Color from "../../Wolfie2D/Utils/Color";
import Layer from "../../Wolfie2D/Scene/Layer";
import Label from "../../Wolfie2D/Nodes/UIElements/Label";
import MainMenu from "./MainMenu";
2022-04-04 03:23:10 -04:00
import Tutorial from "./Tutorial";
2022-03-31 20:52:05 -04:00
export default class Levels extends Scene {
private primary: Layer;
2022-03-31 20:52:05 -04:00
// TODO
loadScene(){}
startScene(){
const center = this.viewport.getCenter();
// The main menu
this.primary = this.addUILayer("primary");
2022-04-04 03:23:10 -04:00
const tutorial = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y - 200), text: "tutorial "});
tutorial.size.set(200, 50);
tutorial.borderWidth = 2;
tutorial.borderColor = Color.WHITE;
tutorial.backgroundColor = Color.TRANSPARENT;
tutorial.onClickEventId = "tutorial";
const level1 = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y - 150), text: "level 1"});
level1.size.set(200, 50);
level1.borderWidth = 2;
level1.borderColor = Color.WHITE;
level1.backgroundColor = Color.TRANSPARENT;
level1.onClickEventId = "level1";
const level2 = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y - 100), text: "level 2"});
level2.size.set(200, 50);
level2.borderWidth = 2;
level2.borderColor = Color.WHITE;
level2.backgroundColor = Color.TRANSPARENT;
level2.onClickEventId = "level2";
const level3 = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y - 50), text: "level 3"});
level3.size.set(200, 50);
level3.borderWidth = 2;
level3.borderColor = Color.WHITE;
level3.backgroundColor = Color.TRANSPARENT;
level3.onClickEventId = "level3";
const level4 = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y ), text: "level 4"});
level4.size.set(200, 50);
level4.borderWidth = 2;
level4.borderColor = Color.WHITE;
level4.backgroundColor = Color.TRANSPARENT;
level4.onClickEventId = "level4";
const level5 = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y + 50), text: "level 5"});
level5.size.set(200, 50);
level5.borderWidth = 2;
level5.borderColor = Color.WHITE;
level5.backgroundColor = Color.TRANSPARENT;
level5.onClickEventId = "level5";
2022-04-02 21:44:53 -04:00
const StorySceneTester = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y + 100), text: "StorySceneTester"});
StorySceneTester.size.set(200, 50);
StorySceneTester.borderWidth = 2;
StorySceneTester.borderColor = Color.WHITE;
StorySceneTester.backgroundColor = Color.TRANSPARENT;
StorySceneTester.onClickEventId = "StorySceneTester";
const back = this.add.uiElement(UIElementType.BUTTON, "primary", {position: new Vec2(center.x, center.y + 250), text: "Back"});
back.size.set(200, 50);
back.borderWidth = 2;
back.borderColor = Color.WHITE;
back.backgroundColor = Color.TRANSPARENT;
back.onClickEventId = "back";
2022-04-04 03:23:10 -04:00
this.receiver.subscribe("tutorial");
this.receiver.subscribe("level1");
this.receiver.subscribe("level2");
this.receiver.subscribe("level3");
this.receiver.subscribe("level4");
this.receiver.subscribe("level5");
2022-04-02 21:44:53 -04:00
this.receiver.subscribe("StorySceneTester");
this.receiver.subscribe("back");
}
updateScene(){
while(this.receiver.hasNextEvent()){
let event = this.receiver.getNextEvent();
console.log(event);
2022-04-04 03:23:10 -04:00
if(event.type === "tutorial"){
let sceneOptions = {
physics: {
groupNames: ["ground", "player", "enemies"],
collisions:
[
[0, 1, 1],
[1, 0, 0],
[1, 0, 0]
]
}
}
this.sceneManager.changeToScene(Tutorial, {}, sceneOptions);
2022-04-04 03:23:10 -04:00
}
if(event.type === "level1"){
this.sceneManager.changeToScene(MainMenu, {});
}
if(event.type === "level2"){
this.sceneManager.changeToScene(MainMenu, {});
}
if(event.type === "level3"){
this.sceneManager.changeToScene(MainMenu, {});
}
if(event.type === "level4"){
this.sceneManager.changeToScene(MainMenu, {});
}
if(event.type === "level5"){
this.sceneManager.changeToScene(MainMenu, {});
}
if(event.type === "back"){
this.sceneManager.changeToScene(MainMenu, {});
}
}
}
2022-03-31 20:52:05 -04:00
}