mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
Chest and magnet spawning
This commit is contained in:
@@ -20,6 +20,8 @@ export class GameAudioAdapter extends Component {
|
||||
@property(AudioClip) private xpPickup: AudioClip;
|
||||
@property(AudioClip) private goldPickup: AudioClip;
|
||||
@property(AudioClip) private healthPotionPickup: AudioClip;
|
||||
@property(AudioClip) private magnetPickup: AudioClip;
|
||||
@property(AudioClip) private chestPickup: AudioClip;
|
||||
@property(AudioClip) private levelUp: AudioClip;
|
||||
@property(AudioClip) private horizontalProjectileLaunch: AudioClip;
|
||||
@property(AudioClip) private diagonalProjectileLaunch: AudioClip;
|
||||
@@ -89,6 +91,12 @@ export class GameAudioAdapter extends Component {
|
||||
case ItemType.HealthPotion:
|
||||
clipToPlay = this.healthPotionPickup;
|
||||
break;
|
||||
case ItemType.Magnet:
|
||||
clipToPlay = this.magnetPickup;
|
||||
break;
|
||||
case ItemType.Chest:
|
||||
clipToPlay = this.chestPickup;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -127,6 +127,8 @@ export class EnemySettings {
|
||||
public xpReward = 0;
|
||||
public goldReward = 0;
|
||||
public healthPotionRewardChance = 0;
|
||||
public magnetRewardChance = 0;
|
||||
public chestRewardChance = 0;
|
||||
}
|
||||
|
||||
export class ItemSettings {
|
||||
|
@@ -49,6 +49,8 @@ export class ItemManager extends Component {
|
||||
this.itemTypeToAction.set(ItemType.XP, this.addXP.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.Gold, this.addGold.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.HealthPotion, this.useHealthPotion.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.Magnet, this.activateMagnet.bind(this));
|
||||
this.itemTypeToAction.set(ItemType.Chest, this.giveRandomSkill.bind(this));
|
||||
}
|
||||
|
||||
public get PickupEvent(): ISignal<ItemType> {
|
||||
@@ -78,6 +80,10 @@ export class ItemManager extends Component {
|
||||
this.player.Health.heal(this.healthPerPotion);
|
||||
}
|
||||
|
||||
private activateMagnet(): void {}
|
||||
|
||||
private giveRandomSkill(): void {}
|
||||
|
||||
private addEnemyListeners(enemy: Enemy): void {
|
||||
enemy.DeathEvent.on(this.trySpawnItems, this);
|
||||
}
|
||||
@@ -89,7 +95,9 @@ export class ItemManager extends Component {
|
||||
private trySpawnItems(enemy: Enemy): void {
|
||||
this.trySpawnXP(enemy);
|
||||
this.trySpawnGold(enemy);
|
||||
this.trySpawnHealthPotion(enemy);
|
||||
ItemManager.trySpawnOnce(enemy.HealthPotionRewardChance, this.healthPotionSpawner, this.getRandomPosition(enemy));
|
||||
ItemManager.trySpawnOnce(enemy.MagnetRewardChance, this.magnetSpawner, this.getRandomPosition(enemy));
|
||||
ItemManager.trySpawnOnce(enemy.ChestRewardChance, this.chestSpawner, this.getRandomPosition(enemy));
|
||||
}
|
||||
|
||||
private trySpawnXP(enemy: Enemy): void {
|
||||
@@ -112,19 +120,16 @@ export class ItemManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
private trySpawnHealthPotion(enemy: Enemy): void {
|
||||
if (enemy.HealthPotionRewardChance <= 0) return;
|
||||
|
||||
console.log("random: " + random() + " chance " + enemy.HealthPotionRewardChance);
|
||||
if (random() < enemy.HealthPotionRewardChance) {
|
||||
this.healthPotionSpawner.spawn(enemy.node.worldPosition);
|
||||
private static trySpawnOnce(chance: number, itemSpawner: ItemSpawner, worldPosition: Vec3): void {
|
||||
if (random() < chance) {
|
||||
itemSpawner.spawn(worldPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private getRandomPosition(enemy: Enemy): Vec3 {
|
||||
const position: Vec3 = enemy.node.worldPosition;
|
||||
position.x += randomRange(-10, 10);
|
||||
position.y += randomRange(-10, 10);
|
||||
position.x += randomRange(-15, 15);
|
||||
position.y += randomRange(-15, 15);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
@@ -29,6 +29,8 @@ export class Enemy extends Component {
|
||||
private xpReward: number;
|
||||
private goldReward: number;
|
||||
private healthPotionRewardChance: number;
|
||||
private magnetRewardChance: number;
|
||||
private chestRewardChance: number;
|
||||
|
||||
private endOfLifetimeTriggered = false;
|
||||
|
||||
@@ -44,6 +46,8 @@ export class Enemy extends Component {
|
||||
this.xpReward = settings.xpReward;
|
||||
this.goldReward = settings.goldReward;
|
||||
this.healthPotionRewardChance = settings.healthPotionRewardChance;
|
||||
this.magnetRewardChance = settings.magnetRewardChance;
|
||||
this.chestRewardChance = settings.chestRewardChance;
|
||||
|
||||
this.node.setWorldPosition(position);
|
||||
this.node.active = true;
|
||||
@@ -88,6 +92,14 @@ export class Enemy extends Component {
|
||||
return this.healthPotionRewardChance;
|
||||
}
|
||||
|
||||
public get MagnetRewardChance(): number {
|
||||
return this.magnetRewardChance;
|
||||
}
|
||||
|
||||
public get ChestRewardChance(): number {
|
||||
return this.chestRewardChance;
|
||||
}
|
||||
|
||||
public get LifetimeEndedEvent(): ISignal<Enemy> {
|
||||
return this.lifetimeEndedEvent;
|
||||
}
|
||||
|
Reference in New Issue
Block a user