From 05ca554578f5350f5584ad0ac539795825dc5721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= <72651575+BreizhHardware@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:52:51 +0200 Subject: [PATCH] Feat(Enemy) - Update boss and checkpoint positions; add alive state to enemy for improved behavior. --- map/levels/3.json | 6 +++--- src/Entity/Enemy.py | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/map/levels/3.json b/map/levels/3.json index 8426671..8b51705 100644 --- a/map/levels/3.json +++ b/map/levels/3.json @@ -795,7 +795,7 @@ { "id": "boss", "type": "boss", - "x": 10000, + "x": 11300, "y": 1200, "health": 3, "damage": 1, @@ -869,8 +869,8 @@ "checkpoints": [ { "id": "checkpoint1", - "x": 6000, - "y": 975, + "x": 6300, + "y": 875, "width": 50, "height": 125, "sprite": "assets/map/checkpoints/checkpoint.png" diff --git a/src/Entity/Enemy.py b/src/Entity/Enemy.py index f0730f8..096521d 100644 --- a/src/Entity/Enemy.py +++ b/src/Entity/Enemy.py @@ -62,6 +62,7 @@ class Enemy(Entity): # State variables self.is_attacking = False self.detected_player = False + self.alive = True def load_gif_frames(self, gif_path, size=(80, 80)): """Load frames from a GIF file""" @@ -195,6 +196,7 @@ class Enemy(Entity): pygame.event.Event(pygame.USEREVENT, {"action": "add_projectiles"}) ) player.add_projectiles() + self.alive = False return True return False @@ -219,10 +221,6 @@ class Enemy(Entity): Boss behavior: combine horizontal chase with turret-like attacks """ # 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 distance_to_player = vec( @@ -230,6 +228,11 @@ class Enemy(Entity): ).length() 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 if self.attack_timer >= self.attack_interval: