mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
Basic sounds
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
import { _decorator, Component, Node, AudioClip } from "cc";
|
||||
import { AppRoot } from "../../AppRoot/AppRoot";
|
||||
import { AudioPlayer } from "../../Services/AudioPlayer/AudioPlayer";
|
||||
import { ItemManager, ItemType } from "../Items/ItemManager";
|
||||
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
|
||||
import { Player } from "../Unit/Player/Player";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GameAudioAdapter")
|
||||
export class GameAudioAdapter extends Component {
|
||||
@property(AudioClip) private music: AudioClip;
|
||||
@property(AudioClip) private enemyHit: AudioClip;
|
||||
@property(AudioClip) private weaponSwing: AudioClip;
|
||||
@property(AudioClip) private xpPickup: AudioClip;
|
||||
@property(AudioClip) private goldPickup: AudioClip;
|
||||
@property(AudioClip) private healthPotionPickup: AudioClip;
|
||||
@property(AudioClip) private levelUp: AudioClip;
|
||||
|
||||
private audioPlayer: AudioPlayer;
|
||||
|
||||
public init(enemyManager: EnemyManager): void {
|
||||
public init(player: Player, enemyManager: EnemyManager, itemManager: ItemManager): void {
|
||||
AppRoot.Instance.AudioPlayer.playMusic(this.music);
|
||||
|
||||
this.audioPlayer = AppRoot.Instance.AudioPlayer;
|
||||
|
||||
player.Weapon.WeaponStrikeEvent.on(() => this.audioPlayer.playSound(this.weaponSwing), this);
|
||||
player.Level.LevelUpEvent.on(() => this.audioPlayer.playSound(this.levelUp), this);
|
||||
|
||||
itemManager.PickupEvent.on(this.playPickupItemSound, this);
|
||||
|
||||
enemyManager.EnemyAddedEvent.on(this.addEnemyListeners, this);
|
||||
enemyManager.EnemyRemovedEvent.on(this.removeEnemyListeners, this);
|
||||
}
|
||||
@@ -29,4 +44,23 @@ export class GameAudioAdapter extends Component {
|
||||
private playEnemyHitSound(): void {
|
||||
this.audioPlayer.playSound(this.enemyHit);
|
||||
}
|
||||
|
||||
private playPickupItemSound(itemType: ItemType): void {
|
||||
let clipToPlay: AudioClip;
|
||||
switch (itemType) {
|
||||
case ItemType.XP:
|
||||
clipToPlay = this.xpPickup;
|
||||
break;
|
||||
case ItemType.Gold:
|
||||
clipToPlay = this.goldPickup;
|
||||
break;
|
||||
case ItemType.HealthPotion:
|
||||
clipToPlay = this.healthPotionPickup;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this.audioPlayer.playSound(clipToPlay);
|
||||
}
|
||||
}
|
||||
|
@@ -18,15 +18,15 @@ import { Pauser } from "./Pauser";
|
||||
import { TestValues } from "./TestGameRunner";
|
||||
import { GameUI } from "./UI/GameUI";
|
||||
import { EnemyManager } from "./Unit/Enemy/EnemyManager";
|
||||
import { EnemyProjectileLauncher } from "./Unit/Enemy/ProjectileLauncher.cs/EnemyProjectileLauncher";
|
||||
import { MetaUpgrades } from "./Unit/MetaUpgrades/MetaUpgrades";
|
||||
import { Player, PlayerData } from "./Unit/Player/Player";
|
||||
import { HaloProjectileLauncher } from "./Unit/Player/ProjectileLauncher/HaloProjectileLauncher";
|
||||
import { ProjectileLauncher } from "./Unit/Player/ProjectileLauncher/ProjectileLauncher";
|
||||
import { ProjectileData } from "./Unit/Player/ProjectileLauncher/ProjectileData";
|
||||
import { ProjectileLauncher } from "./Unit/Player/ProjectileLauncher/ProjectileLauncher";
|
||||
import { WaveProjectileLauncher } from "./Unit/Player/ProjectileLauncher/WaveProjectileLauncher";
|
||||
import { Upgrader } from "./Upgrades/Upgrader";
|
||||
import { MetaUpgradeType } from "./Upgrades/UpgradeType";
|
||||
import { EnemyProjectileLauncher } from "./Unit/Enemy/ProjectileLauncher.cs/EnemyProjectileLauncher";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -144,7 +144,7 @@ export class Game extends Component {
|
||||
this.player.Level.addXp(testValues.startXP);
|
||||
}
|
||||
|
||||
this.gameAudioAdapter.init(this.enemyManager);
|
||||
this.gameAudioAdapter.init(this.player, this.enemyManager, this.itemManager);
|
||||
this.gamePauser.resume();
|
||||
|
||||
while (!this.gameResult.hasExitManually && this.player.Health.IsAlive) await delay(100);
|
||||
|
@@ -1,4 +1,6 @@
|
||||
import { Component, random, randomRange, Vec3, _decorator } from "cc";
|
||||
import { ISignal } from "../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../Services/EventSystem/Signal";
|
||||
import { ItemSettings } from "../Data/GameSettings";
|
||||
import { GameResult } from "../Game";
|
||||
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||
@@ -24,6 +26,8 @@ export class ItemManager extends Component {
|
||||
private gameResult: GameResult;
|
||||
private healthPerPotion: number;
|
||||
|
||||
private pickupEvent = new Signal<ItemType>();
|
||||
|
||||
public init(enemyManager: EnemyManager, player: Player, gameResult: GameResult, settings: ItemSettings): void {
|
||||
this.player = player;
|
||||
this.gameResult = gameResult;
|
||||
@@ -38,8 +42,13 @@ export class ItemManager extends Component {
|
||||
this.pickupEffectManager.init();
|
||||
}
|
||||
|
||||
public get PickupEvent(): ISignal<ItemType> {
|
||||
return this.pickupEvent;
|
||||
}
|
||||
|
||||
public pickupXP(xp: XP): void {
|
||||
this.pickupEffectManager.showEffect(xp.node.worldPosition);
|
||||
this.pickupEvent.trigger(ItemType.XP);
|
||||
|
||||
this.player.Level.addXp(xp.Value);
|
||||
xp.pickup();
|
||||
@@ -47,6 +56,7 @@ export class ItemManager extends Component {
|
||||
|
||||
public pickupGold(gold: Gold): void {
|
||||
this.pickupEffectManager.showEffect(gold.node.worldPosition);
|
||||
this.pickupEvent.trigger(ItemType.Gold);
|
||||
|
||||
gold.pickup();
|
||||
this.gameResult.goldCoins++;
|
||||
@@ -54,6 +64,7 @@ export class ItemManager extends Component {
|
||||
|
||||
public pickupHealthPotion(healthPotion: HealthPotion): void {
|
||||
this.pickupEffectManager.showEffect(healthPotion.node.worldPosition);
|
||||
this.pickupEvent.trigger(ItemType.HealthPotion);
|
||||
|
||||
healthPotion.pickup();
|
||||
this.player.Health.heal(this.healthPerPotion);
|
||||
@@ -110,3 +121,9 @@ export class ItemManager extends Component {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
export enum ItemType {
|
||||
XP,
|
||||
Gold,
|
||||
HealthPotion
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { Animation, AnimationState, Component, _decorator } from "cc";
|
||||
import { ISignal } from "../../../../Services/EventSystem/ISignal";
|
||||
import { Signal } from "../../../../Services/EventSystem/Signal";
|
||||
import { GameTimer } from "../../../../Services/GameTimer";
|
||||
import { WeaponSettings } from "../../../Data/GameSettings";
|
||||
|
||||
import { UpgradableCollider } from "./UpgradableCollider";
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -10,6 +11,8 @@ export class Weapon extends Component {
|
||||
@property(Animation) private weaponAnimation: Animation;
|
||||
@property(UpgradableCollider) private upgradableCollider: UpgradableCollider;
|
||||
|
||||
private weaponStrikeEvent = new Signal<Weapon>();
|
||||
|
||||
private strikeTimer: GameTimer;
|
||||
private strikeState: AnimationState;
|
||||
private damage: number;
|
||||
@@ -33,6 +36,10 @@ export class Weapon extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public get WeaponStrikeEvent(): ISignal<Weapon> {
|
||||
return this.weaponStrikeEvent;
|
||||
}
|
||||
|
||||
public get Collider(): UpgradableCollider {
|
||||
return this.upgradableCollider;
|
||||
}
|
||||
@@ -51,6 +58,7 @@ export class Weapon extends Component {
|
||||
private strike(): void {
|
||||
this.node.active = true;
|
||||
this.weaponAnimation.play(this.strikeState.name);
|
||||
this.weaponStrikeEvent.trigger(this);
|
||||
}
|
||||
|
||||
private endStrike(): void {
|
||||
|
Reference in New Issue
Block a user