From 9e979b6fe733442c5f7e952c6782d3e7655798ba Mon Sep 17 00:00:00 2001 From: Renge Date: Sun, 17 Apr 2022 19:46:10 -0400 Subject: [PATCH] feat: integrated story into GameLevel --- src/main.ts | 2 +- src/shattered_sword/Scenes/GameLevel.ts | 154 ++++++++++++++- src/shattered_sword/Scenes/SceneWithStory.ts | 185 ------------------- src/shattered_sword/Tools/InputWrapper.ts | 2 +- 4 files changed, 152 insertions(+), 191 deletions(-) delete mode 100644 src/shattered_sword/Scenes/SceneWithStory.ts diff --git a/src/main.ts b/src/main.ts index 74cf20a..eff57eb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,7 +12,7 @@ import WeaponTypeRegistry from "./shattered_sword/Registry/WeaponTypeRegistry"; // Set up options for our game let options = { - canvasSize: {x : 1200, y:1000}, + canvasSize: {x : window.innerWidth, y:window.innerHeight}, //canvasSize: {x: window.innerWidth, y: window.innerHeight}, // The size of the game clearColor: {r: 0, g: 0, b: 0}, // The color the game clears to inputs: [ diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 154c0c0..c368348 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -7,7 +7,7 @@ import { GraphicType } from "../../Wolfie2D/Nodes/Graphics/GraphicTypes"; import Point from "../../Wolfie2D/Nodes/Graphics/Point"; import Rect from "../../Wolfie2D/Nodes/Graphics/Rect"; import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; -import Label from "../../Wolfie2D/Nodes/UIElements/Label"; +import Label, { HAlign } from "../../Wolfie2D/Nodes/UIElements/Label"; import { UIElementType } from "../../Wolfie2D/Nodes/UIElements/UIElementTypes"; import Scene from "../../Wolfie2D/Scene/Scene"; import Timer from "../../Wolfie2D/Timing/Timer"; @@ -31,6 +31,8 @@ import CanvasNode from "../../Wolfie2D/Nodes/CanvasNode"; import { Enemy } from "../Tools/RandomMapGenerator"; import Stack from "../../Wolfie2D/DataTypes/Stack"; import InputWrapper from "../Tools/InputWrapper"; +import Story from "../Tools/DataTypes/Story"; +import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite"; @@ -78,6 +80,16 @@ 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; + //buffs layer buffLayer: Layer; buffButton1 : Button; @@ -185,7 +197,7 @@ export default class GameLevel extends Scene { while(this.receiver.hasNextEvent()){ let event = this.receiver.getNextEvent(); - if (this.gameStateStack.peek() == GameState.GAMING) { + if (this.gameStateStack.peek() === GameState.GAMING) { switch(event.type){ case Player_Events.ENEMY_KILLED: @@ -211,7 +223,7 @@ export default class GameLevel extends Scene { } } - else if (this.gameStateStack.peek() == GameState.BUFF) { + else if (this.gameStateStack.peek() === GameState.BUFF) { switch(event.type){ case "buff1": (this.player._ai).addBuff(this.buffs[0]); @@ -231,6 +243,11 @@ export default class GameLevel extends Scene { } } } + if (this.gameStateStack.peek() === GameState.STORY) { + if (InputWrapper.isNextJustPressed() && this.gameStateStack.peek() === GameState.STORY) { + this.updateStory(); + } + } //update health UI let playerAI = (this.player.ai); @@ -258,6 +275,11 @@ export default class GameLevel extends Scene { }); } + if (InputWrapper.isInventoryJustPressed()) { + console.log("LoadingStory"); + this.storyLoader("shattered_sword_assets/jsons/story.json"); + } + } @@ -284,6 +306,13 @@ export default class GameLevel extends Scene { this.addLayer("primary", 1); this.buffLayer = this.addUILayer("buffLayer"); //TODO - test depth later, may be just a regular Layer + + + this.storyLayer = this.addUILayer("story"); + this.storyLayer.disable(); + + + this.receiver.subscribe("loadStory"); } /** @@ -630,7 +659,7 @@ export default class GameLevel extends Scene { protected incPlayerLife(amt: number): void { GameLevel.livesCount += amt; this.livesCountLabel.text = "Lives: " + GameLevel.livesCount; - if (GameLevel.livesCount == 0){ + if (GameLevel.livesCount === 0){ InputWrapper.disableInput(); this.player.disablePhysics(); this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "player_death", loop: false, holdReference: false}); @@ -663,6 +692,123 @@ export default class GameLevel extends Scene { } } + + async storyLoader(storyPath: string) { + if (this.gameStateStack.peek() === GameState.STORY) { + return; + } + this.setGameState(GameState.STORY); + const response = await (await fetch(storyPath)).json(); + this.story = response; + console.log("story:", this.story); + if (this.story.bgm) { + this.storyBGMs = new Array; + this.story.bgm.forEach((bgm) => { + + if (this.load.getAudio(bgm.key)) { + this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true }); + } + else { + this.load.singleAudio(bgm.key, bgm.path, () => { + this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true }); + }) + } + this.storyBGMs.push(bgm.key); + }) + } + this.currentSpeaker = this.story.texts[0].speaker; + this.currentContent = this.story.texts[0].content; + this.storyLayer.enable(); + this.storytextLabel =