游戏可以运行
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import pygame
|
||||
import math
|
||||
from game.config import ENEMY_DATA, PATH_WAYPOINTS, COLOR_BLACK, COLOR_GREEN, COLOR_RED
|
||||
from game.config import ENEMY_DATA, PATH_WAYPOINTS, COLOR_BLACK, COLOR_GREEN, COLOR_RED, COLOR_BLUE
|
||||
from game.utils import distance
|
||||
|
||||
|
||||
class Enemy:
|
||||
@@ -17,6 +18,20 @@ class Enemy:
|
||||
self.alive = True
|
||||
self.reached_end = False
|
||||
|
||||
# Shield
|
||||
self.max_shield = data.get("shield_hp", 0)
|
||||
self.shield_hp = self.max_shield
|
||||
|
||||
# Poison DoT
|
||||
self.poison_timer = 0
|
||||
self.poison_dps = 0
|
||||
|
||||
# Healer
|
||||
self.heal_range = data.get("heal_range", 0)
|
||||
self.heal_amount = data.get("heal_amount", 0)
|
||||
self.heal_interval = data.get("heal_interval", 2.0)
|
||||
self.heal_timer = self.heal_interval
|
||||
|
||||
self.x, self.y = PATH_WAYPOINTS[0]
|
||||
self.waypoint_index = 1
|
||||
self.slow_timer = 0
|
||||
@@ -25,21 +40,50 @@ class Enemy:
|
||||
self.speed = self.base_speed * factor
|
||||
self.slow_timer = duration
|
||||
|
||||
def apply_poison(self, dps, duration):
|
||||
self.poison_dps = dps
|
||||
self.poison_timer = duration
|
||||
|
||||
def take_damage(self, damage):
|
||||
self.hp -= damage
|
||||
if self.shield_hp > 0:
|
||||
absorbed = min(self.shield_hp, damage)
|
||||
self.shield_hp -= absorbed
|
||||
damage -= absorbed
|
||||
if damage > 0:
|
||||
self.hp -= damage
|
||||
if self.hp <= 0:
|
||||
self.hp = 0
|
||||
self.alive = False
|
||||
|
||||
def update(self, dt):
|
||||
def update(self, dt, enemies=None):
|
||||
if not self.alive:
|
||||
return
|
||||
|
||||
# Poison DoT
|
||||
if self.poison_timer > 0:
|
||||
self.poison_timer -= dt
|
||||
self.hp -= self.poison_dps * dt
|
||||
if self.hp <= 0:
|
||||
self.hp = 0
|
||||
self.alive = False
|
||||
return
|
||||
|
||||
# Slow
|
||||
if self.slow_timer > 0:
|
||||
self.slow_timer -= dt
|
||||
if self.slow_timer <= 0:
|
||||
self.speed = self.base_speed
|
||||
|
||||
# Healer ability
|
||||
if self.type == "healer" and enemies:
|
||||
self.heal_timer -= dt
|
||||
if self.heal_timer <= 0:
|
||||
self.heal_timer = self.heal_interval
|
||||
for e in enemies:
|
||||
if e is not self and e.alive and distance(self.x, self.y, e.x, e.y) <= self.heal_range:
|
||||
e.hp = min(e.hp + self.heal_amount, e.max_hp)
|
||||
|
||||
# Movement
|
||||
if self.waypoint_index >= len(PATH_WAYPOINTS):
|
||||
self.reached_end = True
|
||||
self.alive = False
|
||||
@@ -62,14 +106,43 @@ class Enemy:
|
||||
if not self.alive:
|
||||
return
|
||||
ix, iy = int(self.x), int(self.y)
|
||||
|
||||
# Healer aura
|
||||
if self.type == "healer":
|
||||
aura = pygame.Surface((self.heal_range * 2, self.heal_range * 2), pygame.SRCALPHA)
|
||||
pygame.draw.circle(aura, (255, 130, 170, 30), (self.heal_range, self.heal_range), self.heal_range)
|
||||
surface.blit(aura, (ix - self.heal_range, iy - self.heal_range))
|
||||
|
||||
# Poison tint
|
||||
if self.poison_timer > 0:
|
||||
pygame.draw.circle(surface, (0, 180, 0), (ix, iy), self.size + 3)
|
||||
|
||||
pygame.draw.circle(surface, self.color, (ix, iy), self.size)
|
||||
pygame.draw.circle(surface, COLOR_BLACK, (ix, iy), self.size, 2)
|
||||
|
||||
# Boss eyes
|
||||
if self.type == "boss":
|
||||
for offset in [(-6, -6), (6, -6)]:
|
||||
pygame.draw.circle(surface, (255, 200, 0), (ix + offset[0], iy + offset[1]), 4)
|
||||
pygame.draw.circle(surface, COLOR_BLACK, (ix + offset[0], iy + offset[1]), 4, 1)
|
||||
|
||||
# Shield ring
|
||||
if self.type == "shield" and self.shield_hp > 0:
|
||||
shield_ratio = self.shield_hp / self.max_shield
|
||||
arc_color = COLOR_BLUE
|
||||
pygame.draw.circle(surface, arc_color, (ix, iy), self.size + 4, 2)
|
||||
|
||||
# Swarm wings
|
||||
if self.type == "swarm":
|
||||
for dx_off in [-4, 4]:
|
||||
pygame.draw.line(surface, (200, 255, 200), (ix + dx_off, iy - 3), (ix + dx_off * 2, iy - 7), 1)
|
||||
|
||||
# Healer cross
|
||||
if self.type == "healer":
|
||||
pygame.draw.rect(surface, (255, 255, 255), (ix - 1, iy - 5, 3, 10))
|
||||
pygame.draw.rect(surface, (255, 255, 255), (ix - 5, iy - 1, 10, 3))
|
||||
|
||||
# Health bar
|
||||
bar_w = self.size * 2 + 4
|
||||
if self.type == "boss":
|
||||
bar_w = self.size * 3
|
||||
@@ -79,3 +152,10 @@ class Enemy:
|
||||
ratio = self.hp / self.max_hp
|
||||
pygame.draw.rect(surface, COLOR_RED, (bx, by, bar_w, bar_h))
|
||||
pygame.draw.rect(surface, COLOR_GREEN, (bx, by, int(bar_w * ratio), bar_h))
|
||||
|
||||
# Shield bar
|
||||
if self.max_shield > 0 and self.shield_hp > 0:
|
||||
s_bar_h = 3
|
||||
s_ratio = self.shield_hp / self.max_shield
|
||||
pygame.draw.rect(surface, (80, 80, 80), (bx, by - s_bar_h - 1, bar_w, s_bar_h))
|
||||
pygame.draw.rect(surface, COLOR_BLUE, (bx, by - s_bar_h - 1, int(bar_w * s_ratio), s_bar_h))
|
||||
|
||||
Reference in New Issue
Block a user