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

@@ -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