Added some additional sound effects
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -19,6 +19,12 @@ class Pushwall {
|
||||
///
|
||||
/// Only one pushwall can be active (moving) at any given time.
|
||||
class PushwallManager {
|
||||
/// Creates a pushwall manager with an optional sound dispatch callback.
|
||||
PushwallManager({this.onPlaySound});
|
||||
|
||||
/// Optional callback used to emit audio cues when pushwalls activate.
|
||||
final void Function(int sfxId)? onPlaySound;
|
||||
|
||||
final Map<String, Pushwall> pushwalls = {};
|
||||
Pushwall? activePushwall;
|
||||
|
||||
@@ -121,6 +127,7 @@ class PushwallManager {
|
||||
int checkY = targetY + pw.dirY;
|
||||
if (wallGrid[checkY][checkX] == 0) {
|
||||
activePushwall = pw;
|
||||
onPlaySound?.call(WolfSound.pushWall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,34 +135,55 @@ class Player {
|
||||
ammo = newAmmo;
|
||||
}
|
||||
|
||||
bool tryPickup(Collectible item) {
|
||||
/// Attempts to collect [item] and returns the SFX to play.
|
||||
///
|
||||
/// Returns `null` when the item was not collected (for example: full health).
|
||||
int? tryPickup(Collectible item) {
|
||||
bool pickedUp = false;
|
||||
int? pickupSfxId;
|
||||
|
||||
switch (item.type) {
|
||||
case CollectibleType.health:
|
||||
if (health >= 100) return false;
|
||||
heal(item.mapId == MapObject.dogFoodDecoration ? 4 : 25);
|
||||
if (health >= 100) return null;
|
||||
heal(item.mapId == MapObject.food ? 4 : 25);
|
||||
pickupSfxId = item.mapId == MapObject.food
|
||||
? WolfSound.healthSmall
|
||||
: WolfSound.healthLarge;
|
||||
pickedUp = true;
|
||||
break;
|
||||
|
||||
case CollectibleType.ammo:
|
||||
if (ammo >= 99) return false;
|
||||
if (ammo >= 99) return null;
|
||||
int previousAmmo = ammo;
|
||||
addAmmo(8);
|
||||
if (currentWeapon is Knife && previousAmmo <= 0) {
|
||||
requestWeaponSwitch(WeaponType.pistol);
|
||||
}
|
||||
pickupSfxId = WolfSound.getAmmo;
|
||||
pickedUp = true;
|
||||
break;
|
||||
|
||||
case CollectibleType.treasure:
|
||||
if (item.mapId == MapObject.cross) score += 100;
|
||||
if (item.mapId == MapObject.chalice) score += 500;
|
||||
if (item.mapId == MapObject.chest) score += 1000;
|
||||
if (item.mapId == MapObject.crown) score += 5000;
|
||||
if (item.mapId == MapObject.cross) {
|
||||
score += 100;
|
||||
pickupSfxId = WolfSound.treasure1;
|
||||
}
|
||||
if (item.mapId == MapObject.chalice) {
|
||||
score += 500;
|
||||
pickupSfxId = WolfSound.treasure2;
|
||||
}
|
||||
if (item.mapId == MapObject.chest) {
|
||||
score += 1000;
|
||||
pickupSfxId = WolfSound.treasure3;
|
||||
}
|
||||
if (item.mapId == MapObject.crown) {
|
||||
score += 5000;
|
||||
pickupSfxId = WolfSound.treasure4;
|
||||
}
|
||||
if (item.mapId == MapObject.extraLife) {
|
||||
heal(100);
|
||||
addAmmo(25);
|
||||
pickupSfxId = WolfSound.extraLife;
|
||||
}
|
||||
pickedUp = true;
|
||||
break;
|
||||
@@ -175,6 +196,7 @@ class Player {
|
||||
}
|
||||
addAmmo(8);
|
||||
requestWeaponSwitch(WeaponType.machineGun);
|
||||
pickupSfxId = WolfSound.getMachineGun;
|
||||
pickedUp = true;
|
||||
}
|
||||
if (item.mapId == MapObject.chainGun) {
|
||||
@@ -184,6 +206,7 @@ class Player {
|
||||
}
|
||||
addAmmo(8);
|
||||
requestWeaponSwitch(WeaponType.chainGun);
|
||||
pickupSfxId = WolfSound.getGatling;
|
||||
pickedUp = true;
|
||||
}
|
||||
break;
|
||||
@@ -191,10 +214,11 @@ class Player {
|
||||
case CollectibleType.key:
|
||||
if (item.mapId == MapObject.goldKey) hasGoldKey = true;
|
||||
if (item.mapId == MapObject.silverKey) hasSilverKey = true;
|
||||
pickupSfxId = WolfSound.getAmmo;
|
||||
pickedUp = true;
|
||||
break;
|
||||
}
|
||||
return pickedUp;
|
||||
return pickedUp ? pickupSfxId : null;
|
||||
}
|
||||
|
||||
bool fire(int currentTime) {
|
||||
|
||||
@@ -22,6 +22,9 @@ class WolfEngine {
|
||||
}) : audio = audio ?? CliSilentAudio(),
|
||||
doorManager = DoorManager(
|
||||
onPlaySound: (sfxId) => audio?.playSoundEffect(sfxId),
|
||||
),
|
||||
pushwallManager = PushwallManager(
|
||||
onPlaySound: (sfxId) => audio?.playSoundEffect(sfxId),
|
||||
);
|
||||
|
||||
/// Total milliseconds elapsed since the engine was initialized.
|
||||
@@ -54,7 +57,7 @@ class WolfEngine {
|
||||
FrameBuffer frameBuffer;
|
||||
|
||||
/// Handles the detection and movement of secret "Pushwalls".
|
||||
final PushwallManager pushwallManager = PushwallManager();
|
||||
final PushwallManager pushwallManager;
|
||||
|
||||
// --- World State ---
|
||||
|
||||
@@ -203,6 +206,7 @@ class WolfEngine {
|
||||
|
||||
/// Handles floor transitions, including the "Level 10" secret floor logic.
|
||||
void _onLevelCompleted({bool isSecretExit = false}) {
|
||||
audio.playSoundEffect(WolfSound.levelDone);
|
||||
audio.stopMusic();
|
||||
final currentEpisode = data.episodes[_currentEpisodeIndex];
|
||||
|
||||
@@ -335,6 +339,13 @@ class WolfEngine {
|
||||
|
||||
for (Entity entity in entities) {
|
||||
if (entity is Enemy) {
|
||||
if (entity.state == EntityState.dead &&
|
||||
entity.isDying &&
|
||||
!entity.hasPlayedDeathSound) {
|
||||
audio.playSoundEffect(entity.deathSoundId);
|
||||
entity.hasPlayedDeathSound = true;
|
||||
}
|
||||
|
||||
// --- ANIMATION TRANSITION FIX (SAFE VERSION) ---
|
||||
// We check if the enemy is in the 'dead' state and currently 'isDying'.
|
||||
// Inside WolfEngine._updateEntities
|
||||
@@ -397,7 +408,9 @@ class WolfEngine {
|
||||
}
|
||||
} else if (entity is Collectible) {
|
||||
if (player.position.distanceTo(entity.position) < 0.5) {
|
||||
if (player.tryPickup(entity)) {
|
||||
final pickupSfxId = player.tryPickup(entity);
|
||||
if (pickupSfxId != null) {
|
||||
audio.playSoundEffect(pickupSfxId);
|
||||
itemsToRemove.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user