gems are properly awarded, just need to show to the player

This commit is contained in:
koneko 2025-01-26 23:16:05 +01:00
parent 5ea6017547
commit d12d1e1d3c
6 changed files with 52 additions and 16 deletions

View File

@ -1,7 +1,7 @@
[ [
{ {
"name": "Fire Gem", "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", "type": "Fire",
"totalLevels": 2, "totalLevels": 2,
"textures": [], "textures": [],

View File

@ -36,7 +36,7 @@
"scale": 0.5, "scale": 0.5,
"selectedLayer": 0, "selectedLayer": 0,
"viewCenter": { "viewCenter": {
"x": 1070, "x": 570,
"y": 448 "y": 448
} }
}, },

View File

@ -4,9 +4,9 @@ import GameAssets from '../Assets';
export default class Gem { export default class Gem {
public texture: PIXI.Texture; public texture: PIXI.Texture;
public level: number = 1; public level: number = 1;
public gemDefinition: GemDefinition; public definition: GemDefinition;
constructor(gemType: GemType) { constructor(gemType: GemType) {
this.gemDefinition = GameAssets.Gems[gemType]; this.definition = GameAssets.Gems[gemType];
this.texture = this.gemDefinition.textures[0]; this.texture = this.definition.textures[0];
} }
} }

View File

@ -3,6 +3,7 @@ import { Engine } from '../Bastion';
import GameObject from '../GameObject'; import GameObject from '../GameObject';
import * as PIXI from 'pixi.js'; import * as PIXI from 'pixi.js';
import { WaveManagerEvents } from './WaveManager'; import { WaveManagerEvents } from './WaveManager';
import Gem from './Gem';
export default class MissionStats extends GameObject { export default class MissionStats extends GameObject {
private hp: number = 100; private hp: number = 100;
@ -10,6 +11,10 @@ export default class MissionStats extends GameObject {
private goldText: PIXI.Text; private goldText: PIXI.Text;
private healthText: PIXI.Text; private healthText: PIXI.Text;
private waveText: PIXI.Text; private waveText: PIXI.Text;
private inventory: Gem[] = [];
// TODO: implement score keeping for leaderboards.
private score: number = 0;
public getHP() { public getHP() {
return this.hp; return this.hp;
@ -44,6 +49,15 @@ export default class MissionStats extends GameObject {
this.goldText.text = this.gold; 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) { constructor(initialHP: number, initialGold: number) {
super(); super();
this.hp = initialHP; this.hp = initialHP;

View File

@ -178,8 +178,8 @@ export default class Tooltip extends GuiObject {
this.gemAmount.alpha = 0; this.gemAmount.alpha = 0;
this.gemDescriptionText.alpha = 1; this.gemDescriptionText.alpha = 1;
this.titleText.text = `Lv. ${gem.level} ` + gem.gemDefinition.name; this.titleText.text = `Lv. ${gem.level} ` + gem.definition.name;
this.gemDescriptionText.text = gem.gemDefinition.description; this.gemDescriptionText.text = gem.definition.description;
} }
public Show(x, y) { public Show(x, y) {
this.container.alpha = 1; this.container.alpha = 1;

View File

@ -85,6 +85,7 @@ export class GameScene extends Scene {
this.tooltip = new Tooltip(new PIXI.Rectangle(0, 0, 350, 160)); 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. // 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 // 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.CustomButtonLogic = () => {
this.changeRoundButton.buttonIcon = new PIXI.Sprite({ this.changeRoundButton.buttonIcon = new PIXI.Sprite({
texture: GameAssets.PlayIconTexture, 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.rect(0, 0, Engine.app.canvas.width, Engine.app.canvas.height);
this.dimGraphics.fill({ color: 0x000000, alpha: 0.5 }); this.dimGraphics.fill({ color: 0x000000, alpha: 0.5 });
} }
public UndarkenScreen() {
this.dimGraphics.clear();
}
private OfferPlayerGems() { private OfferPlayerGems() {
Engine.Grid.gridInteractionEnabled = false; Engine.Grid.gridInteractionEnabled = false;
Engine.GameScene.sidebar.towerTab.resetTint(); Engine.GameScene.sidebar.towerTab.resetTint();
@ -165,24 +169,41 @@ export class GameScene extends Scene {
let gemsToOffer = this.mission.rounds[this.currentRound].offeredGems; let gemsToOffer = this.mission.rounds[this.currentRound].offeredGems;
this.DarkenScreen(); this.DarkenScreen();
this.offerGemsSprite = new PIXI.NineSliceSprite({ this.offerGemsSprite = new PIXI.NineSliceSprite({
width: 400, width: 380,
height: 200, height: 150,
texture: GameAssets.Frame01Texture, texture: GameAssets.Frame01Texture,
leftWidth: 100, leftWidth: 100,
topHeight: 100, topHeight: 100,
rightWidth: 100, rightWidth: 100,
bottomHeight: 100, bottomHeight: 100,
zIndex: this.dimGraphics.zIndex + 1, zIndex: this.dimGraphics.zIndex + 1,
x: Engine.app.canvas.width / 2 - 200, x: Engine.app.canvas.width / 2 - 190,
y: Engine.app.canvas.height / 2 - 100, y: Engine.app.canvas.height / 2 - 75,
}); });
Engine.GameMaster.currentScene.stage.addChildAt(this.offerGemsSprite, 0); 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) => { gemsToOffer.forEach((gType, index) => {
let _Gem = new Gem(gType); let _Gem = new Gem(gType);
let vGem = new VisualGemSlot(0, Engine.app.stage, _Gem); let vGem = new VisualGemSlot(0, Engine.app.stage, _Gem);
this.visualGems.push(vGem); this.visualGems.push(vGem);
vGem.container.x = this.offerGemsSprite.x + 69 * (index + 1); vGem.container.x = this.offerGemsSprite.x - 15 + 69 * (index + 1);
vGem.container.y = this.offerGemsSprite.y + 50; vGem.container.y = this.offerGemsSprite.y + 40;
vGem.container.onpointermove = () => { vGem.container.onpointermove = () => {
Engine.GameScene.tooltip.SetContentGem(_Gem); Engine.GameScene.tooltip.SetContentGem(_Gem);
Engine.GameScene.tooltip.Show(Engine.MouseX, Engine.MouseY); Engine.GameScene.tooltip.Show(Engine.MouseX, Engine.MouseY);
@ -192,16 +213,18 @@ export class GameScene extends Scene {
}; };
vGem.onClick = () => { vGem.onClick = () => {
Engine.GameScene.tooltip.Hide(); Engine.GameScene.tooltip.Hide();
offerText.destroy();
this.PlayerPickedGem(_Gem); this.PlayerPickedGem(_Gem);
}; };
}); });
} }
private PlayerPickedGem(gem: Gem) { private PlayerPickedGem(gem: Gem) {
this.offerGemsSprite.destroy(); this.offerGemsSprite.destroy();
this.dimGraphics.clear(); this.UndarkenScreen();
this.visualGems.forEach((item) => item.destroy()); this.visualGems.forEach((item) => item.destroy());
Engine.Grid.gridInteractionEnabled = true; 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) { private ShowScoreScreen(lost) {
@ -238,5 +261,4 @@ export class GameScene extends Scene {
Engine.GameMaster.currentScene.stage.removeChildren(); Engine.GameMaster.currentScene.stage.removeChildren();
Engine.GameMaster.changeScene(new MissionPickerScene()); Engine.GameMaster.changeScene(new MissionPickerScene());
} }
public onTowerPlaced() {}
} }