From d12d1e1d3c793800f3fee7c331d87b8efc3640a9 Mon Sep 17 00:00:00 2001 From: koneko <67551503+koneko@users.noreply.github.com> Date: Sun, 26 Jan 2025 23:16:05 +0100 Subject: [PATCH] gems are properly awarded, just need to show to the player --- public/assets/json/Gems.json | 2 +- public/maps.tiled-session | 2 +- src/classes/game/Gem.ts | 6 ++--- src/classes/game/MissionStats.ts | 14 +++++++++++ src/classes/gui/Tooltip.ts | 4 ++-- src/scenes/Game.ts | 40 +++++++++++++++++++++++++------- 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/public/assets/json/Gems.json b/public/assets/json/Gems.json index 1177329..61d55e3 100644 --- a/public/assets/json/Gems.json +++ b/public/assets/json/Gems.json @@ -1,7 +1,7 @@ [ { "name": "Fire Gem", - "description": "Forged from molten lava, the Fire Gem imbues your tower's attacks and adds 50% extra fire damage. It can be merged with any gem and is common.", + "description": "Forged from molten lava, the Fire Gem imbues your tower's attacks and adds 50% extra fire damage. It can be merged with any gem and is common. This text shouldn't be long.", "type": "Fire", "totalLevels": 2, "textures": [], diff --git a/public/maps.tiled-session b/public/maps.tiled-session index f9cf226..abcd439 100644 --- a/public/maps.tiled-session +++ b/public/maps.tiled-session @@ -36,7 +36,7 @@ "scale": 0.5, "selectedLayer": 0, "viewCenter": { - "x": 1070, + "x": 570, "y": 448 } }, diff --git a/src/classes/game/Gem.ts b/src/classes/game/Gem.ts index b9ccea7..5ac0400 100644 --- a/src/classes/game/Gem.ts +++ b/src/classes/game/Gem.ts @@ -4,9 +4,9 @@ import GameAssets from '../Assets'; export default class Gem { public texture: PIXI.Texture; public level: number = 1; - public gemDefinition: GemDefinition; + public definition: GemDefinition; constructor(gemType: GemType) { - this.gemDefinition = GameAssets.Gems[gemType]; - this.texture = this.gemDefinition.textures[0]; + this.definition = GameAssets.Gems[gemType]; + this.texture = this.definition.textures[0]; } } diff --git a/src/classes/game/MissionStats.ts b/src/classes/game/MissionStats.ts index e8457d9..98ea993 100644 --- a/src/classes/game/MissionStats.ts +++ b/src/classes/game/MissionStats.ts @@ -3,6 +3,7 @@ import { Engine } from '../Bastion'; import GameObject from '../GameObject'; import * as PIXI from 'pixi.js'; import { WaveManagerEvents } from './WaveManager'; +import Gem from './Gem'; export default class MissionStats extends GameObject { private hp: number = 100; @@ -10,6 +11,10 @@ export default class MissionStats extends GameObject { private goldText: PIXI.Text; private healthText: PIXI.Text; private waveText: PIXI.Text; + private inventory: Gem[] = []; + + // TODO: implement score keeping for leaderboards. + private score: number = 0; public getHP() { return this.hp; @@ -44,6 +49,15 @@ export default class MissionStats extends GameObject { this.goldText.text = this.gold; } + public giveGem(gem: Gem) { + this.inventory.push(gem); + Engine.GameScene.events.emit('givegem', gem); + } + + public getInventory() { + return this.inventory; + } + constructor(initialHP: number, initialGold: number) { super(); this.hp = initialHP; diff --git a/src/classes/gui/Tooltip.ts b/src/classes/gui/Tooltip.ts index 32eba83..b6767f3 100644 --- a/src/classes/gui/Tooltip.ts +++ b/src/classes/gui/Tooltip.ts @@ -178,8 +178,8 @@ export default class Tooltip extends GuiObject { this.gemAmount.alpha = 0; this.gemDescriptionText.alpha = 1; - this.titleText.text = `Lv. ${gem.level} ` + gem.gemDefinition.name; - this.gemDescriptionText.text = gem.gemDefinition.description; + this.titleText.text = `Lv. ${gem.level} ` + gem.definition.name; + this.gemDescriptionText.text = gem.definition.description; } public Show(x, y) { this.container.alpha = 1; diff --git a/src/scenes/Game.ts b/src/scenes/Game.ts index f6a3cfb..f48a66a 100644 --- a/src/scenes/Game.ts +++ b/src/scenes/Game.ts @@ -85,6 +85,7 @@ export class GameScene extends Scene { this.tooltip = new Tooltip(new PIXI.Rectangle(0, 0, 350, 160)); // Added custom button logic to still keep all the regular events for the button, just have an icon instead of text. // TODO: maybe make this better? add like a seperate class for icon buttons or smth + // nevermind, i can't be bothered to do this, and this works fine. this.changeRoundButton.CustomButtonLogic = () => { this.changeRoundButton.buttonIcon = new PIXI.Sprite({ texture: GameAssets.PlayIconTexture, @@ -157,6 +158,9 @@ export class GameScene extends Scene { this.dimGraphics.rect(0, 0, Engine.app.canvas.width, Engine.app.canvas.height); this.dimGraphics.fill({ color: 0x000000, alpha: 0.5 }); } + public UndarkenScreen() { + this.dimGraphics.clear(); + } private OfferPlayerGems() { Engine.Grid.gridInteractionEnabled = false; Engine.GameScene.sidebar.towerTab.resetTint(); @@ -165,24 +169,41 @@ export class GameScene extends Scene { let gemsToOffer = this.mission.rounds[this.currentRound].offeredGems; this.DarkenScreen(); this.offerGemsSprite = new PIXI.NineSliceSprite({ - width: 400, - height: 200, + width: 380, + height: 150, texture: GameAssets.Frame01Texture, leftWidth: 100, topHeight: 100, rightWidth: 100, bottomHeight: 100, zIndex: this.dimGraphics.zIndex + 1, - x: Engine.app.canvas.width / 2 - 200, - y: Engine.app.canvas.height / 2 - 100, + x: Engine.app.canvas.width / 2 - 190, + y: Engine.app.canvas.height / 2 - 75, }); Engine.GameMaster.currentScene.stage.addChildAt(this.offerGemsSprite, 0); + let offerText = new PIXI.Text({ + x: Engine.app.canvas.width / 4, + y: Engine.app.canvas.height / 4, + zIndex: this.dimGraphics.zIndex + 1, + text: 'Choose a Gem as your reward for beating this round!', + style: { + fontSize: 40, + fill: 'orange', + fontWeight: 'bold', + stroke: { + color: 0x000000, + width: 5, + }, + }, + }); + // offerText.x -= offerText.width; + Engine.GameMaster.currentScene.stage.addChildAt(offerText, 0); gemsToOffer.forEach((gType, index) => { let _Gem = new Gem(gType); let vGem = new VisualGemSlot(0, Engine.app.stage, _Gem); this.visualGems.push(vGem); - vGem.container.x = this.offerGemsSprite.x + 69 * (index + 1); - vGem.container.y = this.offerGemsSprite.y + 50; + vGem.container.x = this.offerGemsSprite.x - 15 + 69 * (index + 1); + vGem.container.y = this.offerGemsSprite.y + 40; vGem.container.onpointermove = () => { Engine.GameScene.tooltip.SetContentGem(_Gem); Engine.GameScene.tooltip.Show(Engine.MouseX, Engine.MouseY); @@ -192,16 +213,18 @@ export class GameScene extends Scene { }; vGem.onClick = () => { Engine.GameScene.tooltip.Hide(); + offerText.destroy(); this.PlayerPickedGem(_Gem); }; }); } private PlayerPickedGem(gem: Gem) { this.offerGemsSprite.destroy(); - this.dimGraphics.clear(); + this.UndarkenScreen(); this.visualGems.forEach((item) => item.destroy()); Engine.Grid.gridInteractionEnabled = true; - Engine.NotificationManager.Notify(gem.gemDefinition.name + ' added to your inventory.', 'gemaward'); + this.MissionStats.giveGem(gem); + Engine.NotificationManager.Notify(gem.definition.name + ' added to your inventory.', 'gemaward'); } private ShowScoreScreen(lost) { @@ -238,5 +261,4 @@ export class GameScene extends Scene { Engine.GameMaster.currentScene.stage.removeChildren(); Engine.GameMaster.changeScene(new MissionPickerScene()); } - public onTowerPlaced() {} }