Added gold count to the game

This commit is contained in:
Martin 2023-01-12 15:50:21 +01:00
parent b1153cd670
commit a8416732d7
4 changed files with 1124 additions and 642 deletions

File diff suppressed because it is too large Load Diff

View File

@ -76,6 +76,7 @@ export class Game extends Component {
public start(): void { public start(): void {
this.gamePauser.pause(); this.gamePauser.pause();
Game.instance = this; Game.instance = this;
this.blackScreen.active = true;
} }
public async play(userData: UserData, settings: GameSettings, translationData: TranslationData, testValues?: TestValues): Promise<GameResult> { public async play(userData: UserData, settings: GameSettings, translationData: TranslationData, testValues?: TestValues): Promise<GameResult> {
@ -206,7 +207,7 @@ export class Game extends Component {
const modalLauncher = new GameModalLauncher(AppRoot.Instance.ModalWindowManager, this.player, this.gamePauser, upgrader, translationData); const modalLauncher = new GameModalLauncher(AppRoot.Instance.ModalWindowManager, this.player, this.gamePauser, upgrader, translationData);
this.itemManager.init(this.enemyManager, this.player, this.gameResult, modalLauncher, settings.items); this.itemManager.init(this.enemyManager, this.player, this.gameResult, modalLauncher, settings.items);
this.gameUI.init(this.player, modalLauncher); this.gameUI.init(this.player, modalLauncher, this.itemManager, this.gameResult);
this.background.init(this.player.node); this.background.init(this.player.node);
if (testValues) { if (testValues) {

View File

@ -64,9 +64,8 @@ export class ItemManager extends Component {
if (!this.itemTypeToAction.has(item.ItemType)) throw new Error("Does not have behaviour set for " + item.ItemType); if (!this.itemTypeToAction.has(item.ItemType)) throw new Error("Does not have behaviour set for " + item.ItemType);
this.pickupEffectManager.showEffect(item.node.worldPosition); this.pickupEffectManager.showEffect(item.node.worldPosition);
this.pickupEvent.trigger(item.ItemType);
this.itemTypeToAction.get(item.ItemType)(); this.itemTypeToAction.get(item.ItemType)();
this.pickupEvent.trigger(item.ItemType);
item.pickup(); item.pickup();
} }

View File

@ -1,5 +1,8 @@
import { Component, Label, ProgressBar, _decorator } from "cc"; import { Component, Label, ProgressBar, _decorator } from "cc";
import { UIButton } from "../../Services/UI/Button/UIButton"; import { UIButton } from "../../Services/UI/Button/UIButton";
import { GameResult } from "../Game";
import { ItemManager } from "../Items/ItemManager";
import { ItemType } from "../Items/ItemType";
import { GameModalLauncher } from "../ModalWIndows/GameModalLauncher"; import { GameModalLauncher } from "../ModalWIndows/GameModalLauncher";
import { Player } from "../Unit/Player/Player"; import { Player } from "../Unit/Player/Player";
import { UnitLevel } from "../Unit/UnitLevel"; import { UnitLevel } from "../Unit/UnitLevel";
@ -10,17 +13,23 @@ const { ccclass, property } = _decorator;
export class GameUI extends Component { export class GameUI extends Component {
@property(ProgressBar) private xpBar: ProgressBar; @property(ProgressBar) private xpBar: ProgressBar;
@property(Label) private timeAliveText: Label; @property(Label) private timeAliveText: Label;
@property(Label) private goldLabel: Label;
@property(UIButton) private pauseBtn: UIButton; @property(UIButton) private pauseBtn: UIButton;
private playerLevel: UnitLevel; private playerLevel: UnitLevel;
private modalLauncher: GameModalLauncher; private modalLauncher: GameModalLauncher;
private gameResult: GameResult;
public init(player: Player, modalLauncher: GameModalLauncher): void { public init(player: Player, modalLauncher: GameModalLauncher, itemManager: ItemManager, gameResult: GameResult): void {
this.playerLevel = player.Level; this.playerLevel = player.Level;
this.modalLauncher = modalLauncher; this.modalLauncher = modalLauncher;
this.gameResult = gameResult;
this.playerLevel.XpAddedEvent.on(this.updateProgressBar, this); this.playerLevel.XpAddedEvent.on(this.updateProgressBar, this);
this.playerLevel.LevelUpEvent.on(this.updateProgressBar, this); this.playerLevel.LevelUpEvent.on(this.updateProgressBar, this);
itemManager.PickupEvent.on(this.tryUpdateGoldLabel, this);
this.xpBar.progress = 0; this.xpBar.progress = 0;
this.pauseBtn.InteractedEvent.on(this.showPauseWindow, this); this.pauseBtn.InteractedEvent.on(this.showPauseWindow, this);
@ -30,6 +39,12 @@ export class GameUI extends Component {
this.xpBar.progress = this.playerLevel.XP / this.playerLevel.RequiredXP; this.xpBar.progress = this.playerLevel.XP / this.playerLevel.RequiredXP;
} }
private tryUpdateGoldLabel(itemType: ItemType): void {
if (itemType !== ItemType.Gold) return;
this.goldLabel.string = this.gameResult.goldCoins.toString();
}
private showPauseWindow(): void { private showPauseWindow(): void {
console.log("Show pause window"); console.log("Show pause window");
this.modalLauncher.showPauseModal(); this.modalLauncher.showPauseModal();