Feat(Enemy) - Update boss and checkpoint positions; add alive state to enemy for improved behavior.

This commit is contained in:
Félix MARQUET
2025-04-11 10:52:51 +02:00
parent a5613bf079
commit 05ca554578
2 changed files with 10 additions and 7 deletions

View File

@@ -795,7 +795,7 @@
{ {
"id": "boss", "id": "boss",
"type": "boss", "type": "boss",
"x": 10000, "x": 11300,
"y": 1200, "y": 1200,
"health": 3, "health": 3,
"damage": 1, "damage": 1,
@@ -869,8 +869,8 @@
"checkpoints": [ "checkpoints": [
{ {
"id": "checkpoint1", "id": "checkpoint1",
"x": 6000, "x": 6300,
"y": 975, "y": 875,
"width": 50, "width": 50,
"height": 125, "height": 125,
"sprite": "assets/map/checkpoints/checkpoint.png" "sprite": "assets/map/checkpoints/checkpoint.png"

View File

@@ -62,6 +62,7 @@ class Enemy(Entity):
# State variables # State variables
self.is_attacking = False self.is_attacking = False
self.detected_player = False self.detected_player = False
self.alive = True
def load_gif_frames(self, gif_path, size=(80, 80)): def load_gif_frames(self, gif_path, size=(80, 80)):
"""Load frames from a GIF file""" """Load frames from a GIF file"""
@@ -195,6 +196,7 @@ class Enemy(Entity):
pygame.event.Event(pygame.USEREVENT, {"action": "add_projectiles"}) pygame.event.Event(pygame.USEREVENT, {"action": "add_projectiles"})
) )
player.add_projectiles() player.add_projectiles()
self.alive = False
return True return True
return False return False
@@ -219,10 +221,6 @@ class Enemy(Entity):
Boss behavior: combine horizontal chase with turret-like attacks Boss behavior: combine horizontal chase with turret-like attacks
""" """
# Follow the player horizontally (x axis) # Follow the player horizontally (x axis)
if abs(player.pos.x - self.pos.x) > 50:
direction = 1 if player.pos.x > self.pos.x else -1
self.pos.x += direction * self.speed
self.direction = direction
# Attack the player if within range # Attack the player if within range
distance_to_player = vec( distance_to_player = vec(
@@ -230,6 +228,11 @@ class Enemy(Entity):
).length() ).length()
if distance_to_player <= self.attack_range: if distance_to_player <= self.attack_range:
if abs(player.pos.x - self.pos.x) > 50:
direction = 1 if player.pos.x > self.pos.x else -1
self.pos.x += direction * self.speed
self.direction = direction
self.attack_timer += 1 / FPS self.attack_timer += 1 / FPS
if self.attack_timer >= self.attack_interval: if self.attack_timer >= self.attack_interval: