class Weapon: def __init__(self, name, damage, range, attackSound, hitSound, cooldown=500, attackDuration=200): self.name = name self.damage = damage self.range = range # Range in tiles self.attackSound = attackSound self.hitSound = hitSound self.cooldown = cooldown # Milliseconds between attacks self.attackDuration = attackDuration # Milliseconds the attack is active self.lastAttackTime = 0 def can_attack(self, currentTime): """Check if enough time has passed since last attack""" return currentTime - self.lastAttackTime >= self.cooldown def get_attack_range(self, playerPos, facingRight): """Calculate the area that this attack would hit""" if facingRight: return (playerPos, playerPos + self.range) else: return (playerPos - self.range, playerPos) def start_attack(self, currentTime): """Begin an attack and return True if allowed""" if self.can_attack(currentTime): self.lastAttackTime = currentTime return True return False def is_attack_active(self, currentTime): """Check if the attack is still in its active frames""" timeSinceAttack = currentTime - self.lastAttackTime return 0 <= timeSinceAttack <= self.attackDuration