feat: GameFinish Scene

This commit is contained in:
Renge 2022-05-09 11:49:54 -04:00
parent 66ea625148
commit f03d864ed6
2 changed files with 57 additions and 15 deletions

View File

@ -0,0 +1,36 @@
import Vec2 from "../../Wolfie2D/DataTypes/Vec2";
import Label from "../../Wolfie2D/Nodes/UIElements/Label";
import { UIElementType } from "../../Wolfie2D/Nodes/UIElements/UIElementTypes";
import Scene from "../../Wolfie2D/Scene/Scene";
import Color from "../../Wolfie2D/Utils/Color";
import { GameState } from "../sword_enums";
import InputWrapper from "../Tools/InputWrapper";
import GameLevel from "./GameLevel";
import MainMenu from "./MainMenu";
export default class GameFinish extends Scene {
startScene() {
InputWrapper.setState(GameState.PAUSE);
InputWrapper.randomSeed = undefined;
const center = this.viewport.getCenter();
this.addUILayer("primary");
const congra = <Label>this.add.uiElement(UIElementType.LABEL, "primary", {position: new Vec2(center.x, center.y), text: "CONGRATULATION!"});
congra.textColor = Color.GREEN;
congra.fontSize = 100;
const time = <Label>this.add.uiElement(UIElementType.LABEL, "primary", {position: new Vec2(center.x, center.y + 100), text: ("You finished the game in " + GameLevel.gameTimeToString())});
time.textColor = Color.WHITE;
const hint = <Label>this.add.uiElement(UIElementType.LABEL, "primary", {position: new Vec2(center.x, center.y + 200), text: "Click to go back to Main Menu"});
hint.textColor = Color.WHITE;
}
updateScene(){
if(InputWrapper.isLeftMouseJustPressed()){
this.sceneManager.changeToScene(MainMenu);
}
}
}

View File

@ -40,7 +40,9 @@ import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
import TextInput from "../../Wolfie2D/Nodes/UIElements/TextInput";
import { TiledTilemapData } from "../../Wolfie2D/DataTypes/Tilesets/TiledData";
import GameOver from "./GameOver";
import GameFinish from "./GameFinish";
import MainMenu from "./MainMenu";
import MapTemplate from "../Tools/DataTypes/MapTemplate";
// TODO
/**
@ -240,6 +242,24 @@ export default class GameLevel extends Scene {
this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "level_music", loop: true, holdReference: true});
}
static gameTimeToString(): string {
let tmp = "";
let minutes = Math.floor(GameLevel.gameTimer / 60);
if (minutes >= 10) {
tmp = minutes.toString();
}
else {
tmp = "0" + minutes.toString();
}
let seconds = Math.floor(GameLevel.gameTimer % 60);
if (seconds >= 10) {
tmp += ":" + seconds.toString();
}
else {
tmp += ":0" + seconds.toString();
}
return tmp;
}
updateScene(deltaT: number){
@ -251,20 +271,7 @@ export default class GameLevel extends Scene {
else {
this.timerLable.textColor = Color.RED;
}
let minutes = Math.floor(GameLevel.gameTimer / 60);
if (minutes >= 10) {
this.timerLable.text = minutes.toString();
}
else {
this.timerLable.text = "0" + minutes.toString();
}
let seconds = Math.floor(GameLevel.gameTimer % 60);
if (seconds >= 10) {
this.timerLable.text += ":" + seconds.toString();
}
else {
this.timerLable.text += ":0" + seconds.toString();
}
this.timerLable.text = GameLevel.gameTimeToString();
}
// Handle events and update the UI if needed
@ -1179,5 +1186,4 @@ export default class GameLevel extends Scene {
this.pauseInput.text = "";
}
}