Fixed attack sound sometimes not playing. Fixed a problem where a single attack was doing multiple attack damage. The means I reaqlly need to reword the first three levels, because they are very hard now lol.

This commit is contained in:
Storm Dragon
2025-02-06 15:20:47 -05:00
parent edad61a027
commit ffbb9da992
3 changed files with 16 additions and 11 deletions

View File

@@ -138,4 +138,4 @@ class Catapult(Object):
pumpkin.stop_sound(self.sounds, player.xPos)
pumpkin.isActive = False
self.activePumpkins.remove(pumpkin)
speak("Hit by a pumpkin!")
self.sounds['player_takes_damage'].play()

View File

@@ -202,15 +202,10 @@ class Level:
# Check for enemy hits
for enemy in self.enemies:
if enemy.isActive and enemy.xPos >= attackRange[0] and enemy.xPos <= attackRange[1]:
if self.weapon_hit_channel is None or not self.weapon_hit_channel.get_busy():
self.weapon_hit_channel = self.sounds[self.player.currentWeapon.hitSound].play()
self.weapon_hit_channel = play_sound(self.sounds[self.player.currentWeapon.hitSound])
enemy.take_damage(self.player.currentWeapon.damage)
else:
# Reset weapon hit channel when not attacking
if self.weapon_hit_channel is not None and not self.weapon_hit_channel.get_busy():
self.weapon_hit_channel = None
# Only damage and play sound if this is a new hit for this attack
if self.player.currentWeapon.register_hit(enemy, currentTime):
play_sound(self.sounds[self.player.currentWeapon.hitSound])
enemy.take_damage(self.player.currentWeapon.damage)
# Check for coffin hits
for obj in self.objects:

View File

@@ -8,6 +8,7 @@ class Weapon:
self.cooldown = cooldown # Milliseconds between attacks
self.attackDuration = attackDuration # Milliseconds the attack is active
self.lastAttackTime = 0
self.hitEnemies = set()
def can_attack(self, currentTime):
"""Check if enough time has passed since last attack"""
@@ -24,6 +25,7 @@ class Weapon:
"""Begin an attack and return True if allowed"""
if self.can_attack(currentTime):
self.lastAttackTime = currentTime
self.hitEnemies.clear() # Clear hit enemies for new attack
return True
return False
@@ -31,3 +33,11 @@ class Weapon:
"""Check if the attack is still in its active frames"""
timeSinceAttack = currentTime - self.lastAttackTime
return 0 <= timeSinceAttack <= self.attackDuration
def register_hit(self, enemy, currentTime):
"""Register a hit on an enemy for this attack. Returns True if it's a new hit."""
if self.is_attack_active(currentTime):
if enemy not in self.hitEnemies:
self.hitEnemies.add(enemy)
return True
return False