More content added, weapons, coin collecting, basic combat.

This commit is contained in:
Storm Dragon
2025-01-30 19:11:33 -05:00
parent 0d115b2bef
commit 53009373c2
10 changed files with 344 additions and 63 deletions

33
src/weapon.py Normal file
View File

@@ -0,0 +1,33 @@
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