Code cleanup, added more functionality. Floating coffins that spawn items, graves can spawn zombies, etc.
This commit is contained in:
41
src/enemy.py
41
src/enemy.py
@@ -24,12 +24,19 @@ class Enemy(Object):
|
||||
|
||||
# Movement and behavior properties
|
||||
self.movingRight = True # Initial direction
|
||||
self.movementSpeed = 0.03 # Slightly slower than player
|
||||
self.movementSpeed = 0.03 # Base speed
|
||||
self.patrolStart = self.xRange[0]
|
||||
self.patrolEnd = self.xRange[0] + self.movementRange
|
||||
self.lastAttackTime = 0
|
||||
self.attackCooldown = 1000 # 1 second between attacks
|
||||
|
||||
# Enemy type specific adjustments
|
||||
if enemyType == "zombie":
|
||||
self.movementSpeed *= 0.6 # Zombies are slower
|
||||
self.damage = 10 # Zombies do massive damage
|
||||
self.health = 3 # Easier to kill than goblins
|
||||
self.attackCooldown = 1500 # Slower attack rate
|
||||
|
||||
@property
|
||||
def xPos(self):
|
||||
"""Current x position"""
|
||||
@@ -45,16 +52,26 @@ class Enemy(Object):
|
||||
if not self.isActive or self.health <= 0:
|
||||
return
|
||||
|
||||
# Update position based on patrol behavior
|
||||
if self.movingRight:
|
||||
self.xPos += self.movementSpeed
|
||||
if self.xPos >= self.patrolEnd:
|
||||
self.movingRight = False
|
||||
else:
|
||||
self.xPos -= self.movementSpeed
|
||||
if self.xPos <= self.patrolStart:
|
||||
# Zombie behavior - always chase player
|
||||
if self.enemyType == "zombie":
|
||||
# Determine direction to player
|
||||
if player.xPos > self.xPos:
|
||||
self.movingRight = True
|
||||
|
||||
self.xPos += self.movementSpeed
|
||||
else:
|
||||
self.movingRight = False
|
||||
self.xPos -= self.movementSpeed
|
||||
else:
|
||||
# Normal patrol behavior for other enemies
|
||||
if self.movingRight:
|
||||
self.xPos += self.movementSpeed
|
||||
if self.xPos >= self.patrolEnd:
|
||||
self.movingRight = False
|
||||
else:
|
||||
self.xPos -= self.movementSpeed
|
||||
if self.xPos <= self.patrolStart:
|
||||
self.movingRight = True
|
||||
|
||||
# Check for attack opportunity
|
||||
if self.can_attack(currentTime, player):
|
||||
self.attack(currentTime, player)
|
||||
@@ -103,3 +120,7 @@ class Enemy(Object):
|
||||
if self.channel:
|
||||
obj_stop(self.channel)
|
||||
self.channel = None
|
||||
# Play death sound if available
|
||||
deathSound = f"{self.enemyType}_death"
|
||||
if deathSound in self.sounds:
|
||||
self.sounds[deathSound].play()
|
||||
|
Reference in New Issue
Block a user