Ghost enemy added, boss for level 10. Levels updated, probably still not final version, but getting close.
This commit is contained in:
37
src/enemy.py
37
src/enemy.py
@@ -43,6 +43,20 @@ class Enemy(Object):
|
||||
self.damage = level.player.get_max_health() # Instant death
|
||||
self.health = 1 # Easy to kill
|
||||
self.attackCooldown = 1500 # Slower attack rate
|
||||
elif enemyType == "ghost":
|
||||
self.isVulnerable = False
|
||||
self.vulnerabilityTimer = 0
|
||||
self.vulnerabilityDuration = kwargs.get('vulnerability_duration', 3000) # Default 3 seconds
|
||||
self.invulnerabilityDuration = kwargs.get('invulnerability_duration', 5000) # Default 5 seconds
|
||||
self.movementSpeed *= kwargs.get('speed_multiplier', 0.8) # Default 80% speed
|
||||
self.health = kwargs.get('health', 3) # Default 3 HP
|
||||
self.damage = kwargs.get('damage', 2) # Default 2 damage
|
||||
self.attackRange = kwargs.get('attack_range', 1) # Use provided or default 1
|
||||
self.attackCooldown = kwargs.get('attack_cooldown', 1200) # Default 1.2 seconds
|
||||
self.attackPattern = kwargs.get('attack_pattern', {
|
||||
'type': 'hunter',
|
||||
'turn_threshold': 2
|
||||
})
|
||||
elif enemyType == "spider":
|
||||
speedMultiplier = kwargs.get('speed_multiplier', 2.0)
|
||||
self.movementSpeed *= speedMultiplier # Spiders are faster
|
||||
@@ -76,6 +90,25 @@ class Enemy(Object):
|
||||
if not self.isActive or self.health <= 0:
|
||||
return
|
||||
|
||||
# Ghost vulnerability state management
|
||||
if self.enemyType == "ghost":
|
||||
if self.isVulnerable and (currentTime - self.vulnerabilityTimer > self.vulnerabilityDuration):
|
||||
# Switch to invulnerable
|
||||
self.isVulnerable = False
|
||||
self.vulnerabilityTimer = currentTime
|
||||
# Change sound back to base ghost sound
|
||||
if self.channel:
|
||||
obj_stop(self.channel)
|
||||
self.channel = obj_play(self.sounds, "ghost", player.xPos, self.xPos)
|
||||
elif not self.isVulnerable and (currentTime - self.vulnerabilityTimer > self.invulnerabilityDuration):
|
||||
# Switch to vulnerable
|
||||
self.isVulnerable = True
|
||||
self.vulnerabilityTimer = currentTime
|
||||
# Change to vulnerable sound
|
||||
if self.channel:
|
||||
obj_stop(self.channel)
|
||||
self.channel = obj_play(self.sounds, "ghost_is_vulnerable", player.xPos, self.xPos)
|
||||
|
||||
# Check if player has entered territory
|
||||
if not self.hunting:
|
||||
if self.patrolStart <= player.xPos <= self.patrolEnd:
|
||||
@@ -142,6 +175,10 @@ class Enemy(Object):
|
||||
|
||||
def take_damage(self, amount):
|
||||
"""Handle enemy taking damage"""
|
||||
# Ghost can only take damage when vulnerable
|
||||
if self.enemyType == "ghost" and not self.isVulnerable:
|
||||
return
|
||||
|
||||
self.health -= amount
|
||||
if self.health <= 0:
|
||||
self.die()
|
||||
|
Reference in New Issue
Block a user