diff --git a/dist/shattered_sword_assets/jsons/forest_template.json b/dist/shattered_sword_assets/jsons/forest_template.json index 383d6c8..f3960bf 100644 --- a/dist/shattered_sword_assets/jsons/forest_template.json +++ b/dist/shattered_sword_assets/jsons/forest_template.json @@ -52,7 +52,7 @@ "possibility": 1 } ], - "checkPoint": [5, 19, 5, 5] + "startCheckPoint": [25, 19, 5, 5] }, "exit": { "width": 30, @@ -76,7 +76,8 @@ "width": 3, "alt_tile": [0, 478] } - ] + ], + "endCheckPoint": [20, 16, 5, 5] }, "rooms": [ { diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 2ab2926..224d0e5 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -99,36 +99,44 @@ export default class GameLevel extends Scene { protected gameStateStack: Stack; // Story - private storytextLabel: Label; - private storyLayer: Layer; - private story: Story; - private storyProgress: number; - private storySprites: Array; - private storyBGMs: Array; - private currentSpeaker: string; - private currentContent: string; + protected storytextLabel: Label; + protected storyLayer: Layer; + protected story: Story; + protected storyProgress: number; + protected storySprites: Array; + protected storyBGMs: Array; + protected currentSpeaker: string; + protected currentContent: string; //buffs layer - buffLayer: Layer; - buffButton1 : Button; - buffLabel1 : Label; - buffButton2 : Button; - buffLabel2 : Label; - buffButton3 : Button; - buffLabel3: Label; - buffs: Array; + protected buffLayer: Layer; + protected buffButton1 : Button; + protected buffLabel1 : Label; + protected buffButton2 : Button; + protected buffLabel2 : Label; + protected buffButton3 : Button; + protected buffLabel3: Label; + protected buffs: Array; //pause layer - pauseLayer: Layer; - pauseText: Label; - pauseInput: TextInput; - pauseSubmit: Label; - pauseCheatText: Label; + protected pauseLayer: Layer; + protected pauseText: Label; + protected pauseInput: TextInput; + protected pauseSubmit: Label; + protected pauseCheatText: Label; protected randomSeed: number; protected rmg: RandomMapGenerator; protected map: TiledTilemapData; + protected startCheckPoint: Rect; + protected endCheckPoint: Rect; + protected touchedStartCheckPoint: boolean = false; + protected touchedEndCheckPoint: boolean = false; + protected static gameTimer: number = 0; + protected gameStarted: boolean = false; + protected timerLable: Label; + startpos: Vec2; loadScene(): void { //can load player sprite here @@ -198,8 +206,10 @@ export default class GameLevel extends Scene { this.subscribeToEvents(); this.addUI(); - const checkPoint = this.rmg.getCheckPoint(); - this.addLevelEnd(new Vec2(checkPoint[0], checkPoint[1]), new Vec2(checkPoint[2], checkPoint[3])); + let startCheckPoint = this.rmg.getStartCheckPoint(); + this.startCheckPoint = this.addCheckPoint(new Vec2(startCheckPoint[0], startCheckPoint[1]), new Vec2(startCheckPoint[2], startCheckPoint[3]), "startStory", "startTimer"); + let endCheckPoint = this.rmg.getEndCheckPoint(); + this.endCheckPoint = this.addCheckPoint(new Vec2(endCheckPoint[0], endCheckPoint[1]), new Vec2(endCheckPoint[2], endCheckPoint[3]), "endStory", "nextLevel"); // Create an enemies array // Send the player and enemies to the battle manager @@ -250,7 +260,30 @@ export default class GameLevel extends Scene { updateScene(deltaT: number){ - + if (this.gameStateStack.peek() === GameState.GAMING) { + if (this.gameStarted) { + GameLevel.gameTimer += deltaT; + 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.textColor = Color.BLACK; + } + else { + this.timerLable.textColor = Color.RED; + } + } + // Handle events and update the UI if needed while(this.receiver.hasNextEvent()){ let event = this.receiver.getNextEvent(); @@ -326,6 +359,18 @@ export default class GameLevel extends Scene { this.sceneManager.changeToScene(GameOver, {}); } break; + case "startStory": + this.playStartStory(); + break; + case "endStory": + this.playEndStory(); + break; + case "startTimer": + this.startTimer(); + break; + case "nextLevel": + this.goToNextLevel(); + break; } } @@ -435,10 +480,10 @@ export default class GameLevel extends Scene { } */ - if (InputWrapper.isInventoryJustPressed()) { - console.log("LoadingStory"); - this.storyLoader("shattered_sword_assets/jsons/story.json"); - } + // if (InputWrapper.isInventoryJustPressed()) { + // console.log("LoadingStory"); + // this.storyLoader("shattered_sword_assets/jsons/story.json"); + // } @@ -503,6 +548,10 @@ export default class GameLevel extends Scene { this.receiver.subscribe("buff2"); this.receiver.subscribe("buff3"); this.receiver.subscribe("cheat"); + this.receiver.subscribe("startStory"); + this.receiver.subscribe("startTimer"); + this.receiver.subscribe("endStory"); + this.receiver.subscribe("nextLevel"); } // TODO - @@ -693,9 +742,12 @@ export default class GameLevel extends Scene { this.pauseSubmit.onClickEventId = "cheat"; this.pauseSubmit.borderWidth = 3; - this.livesCountLabel =