游戏可以运行

This commit is contained in:
2026-05-20 20:53:02 +08:00
parent a174a4bcd4
commit e5aa78e8be
7 changed files with 233 additions and 24 deletions

View File

@@ -22,6 +22,11 @@ class Tower:
self.splash = data.get("splash", 0)
self.slow_factor = data.get("slow_factor", 0)
self.slow_duration = data.get("slow_duration", 0)
self.poison_dps = data.get("poison_dps", 0)
self.poison_duration = data.get("poison_duration", 0)
self.chain_count = data.get("chain_count", 0)
self.chain_range = data.get("chain_range", 0)
self.chain_decay = data.get("chain_decay", 0)
self.cooldown = 0
self.target = None
@@ -54,11 +59,16 @@ class Tower:
if self.target and self.cooldown <= 0:
self.cooldown = self.fire_rate
proj_type = {"arrow": "arrow", "cannon": "cannon", "slow": "slow"}[self.type]
proj_type = {
"arrow": "arrow", "cannon": "cannon", "slow": "slow",
"sniper": "sniper", "poison": "poison", "lightning": "lightning",
}[self.type]
projectiles.append(Projectile(
self.x, self.y, self.target, self.damage,
proj_type=proj_type, splash=self.splash,
slow_factor=self.slow_factor, slow_duration=self.slow_duration,
poison_dps=self.poison_dps, poison_duration=self.poison_duration,
chain_count=self.chain_count, chain_range=self.chain_range, chain_decay=self.chain_decay,
))
def draw(self, surface):
@@ -74,6 +84,25 @@ class Tower:
points = [(ix, iy - 14), (ix + 14, iy), (ix, iy + 14), (ix - 14, iy)]
pygame.draw.polygon(surface, self.color, points)
pygame.draw.polygon(surface, COLOR_BLACK, points, 2)
elif self.type == "sniper":
pts = [(ix, iy - 16), (ix + 14, iy + 12), (ix - 14, iy + 12)]
pygame.draw.polygon(surface, self.color, pts)
pygame.draw.polygon(surface, COLOR_BLACK, pts, 2)
pygame.draw.line(surface, (200, 200, 255), (ix, iy - 10), (ix, iy + 6), 2)
elif self.type == "poison":
pts = []
for i in range(6):
angle = math.pi / 3 * i - math.pi / 6
pts.append((ix + int(14 * math.cos(angle)), iy + int(14 * math.sin(angle))))
pygame.draw.polygon(surface, self.color, pts)
pygame.draw.polygon(surface, COLOR_BLACK, pts, 2)
elif self.type == "lightning":
pts = [
(ix - 2, iy - 14), (ix + 6, iy - 4), (ix, iy - 4),
(ix + 4, iy + 14), (ix - 4, iy + 2), (ix + 1, iy + 2),
]
pygame.draw.polygon(surface, self.color, pts)
pygame.draw.polygon(surface, COLOR_BLACK, pts, 2)
if self.target and self.target.alive:
pygame.draw.line(surface, (*self.color, ), (ix, iy), (int(self.target.x), int(self.target.y)), 1)