Code cleanup, added more functionality. Floating coffins that spawn items, graves can spawn zombies, etc.
This commit is contained in:
29
src/projectile.py
Normal file
29
src/projectile.py
Normal file
@@ -0,0 +1,29 @@
|
||||
class Projectile:
|
||||
def __init__(self, projectile_type, start_x, direction):
|
||||
self.type = projectile_type
|
||||
self.x = start_x
|
||||
self.direction = direction
|
||||
self.speed = 0.2 # Projectiles move faster than player
|
||||
self.isActive = True
|
||||
self.damage = 5 # All projectiles do same damage for now
|
||||
self.range = 10 # Maximum travel distance in tiles
|
||||
self.start_x = start_x
|
||||
|
||||
def update(self):
|
||||
"""Update projectile position and check if it should still exist"""
|
||||
if not self.isActive:
|
||||
return False
|
||||
|
||||
self.x += self.direction * self.speed
|
||||
|
||||
# Check if projectile has gone too far
|
||||
if abs(self.x - self.start_x) > self.range:
|
||||
self.isActive = False
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def hit_enemy(self, enemy):
|
||||
"""Handle hitting an enemy"""
|
||||
enemy.take_damage(self.damage)
|
||||
self.isActive = False # Projectile is destroyed on hit
|
Reference in New Issue
Block a user