游戏可以运行
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import pygame
|
||||
import math
|
||||
from game.config import COLOR_WHITE, COLOR_ORANGE, COLOR_CYAN
|
||||
from game.config import COLOR_WHITE, COLOR_ORANGE, COLOR_CYAN, COLOR_DARK_GREEN, COLOR_BRIGHT_PURPLE
|
||||
from game.utils import distance
|
||||
|
||||
|
||||
class Projectile:
|
||||
def __init__(self, x, y, target, damage, proj_type="arrow", splash=0, slow_factor=0, slow_duration=0):
|
||||
def __init__(self, x, y, target, damage, proj_type="arrow", splash=0,
|
||||
slow_factor=0, slow_duration=0,
|
||||
poison_dps=0, poison_duration=0,
|
||||
chain_count=0, chain_range=0, chain_decay=0):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.target = target
|
||||
@@ -14,6 +17,11 @@ class Projectile:
|
||||
self.splash = splash
|
||||
self.slow_factor = slow_factor
|
||||
self.slow_duration = slow_duration
|
||||
self.poison_dps = poison_dps
|
||||
self.poison_duration = poison_duration
|
||||
self.chain_count = chain_count
|
||||
self.chain_range = chain_range
|
||||
self.chain_decay = chain_decay
|
||||
self.speed = 400
|
||||
self.alive = True
|
||||
|
||||
@@ -39,6 +47,7 @@ class Projectile:
|
||||
|
||||
def _hit(self, enemies):
|
||||
self.alive = False
|
||||
|
||||
if self.proj_type == "cannon" and self.splash > 0:
|
||||
for e in enemies:
|
||||
if e.alive and distance(self.target.x, self.target.y, e.x, e.y) <= self.splash:
|
||||
@@ -49,6 +58,33 @@ class Projectile:
|
||||
if self.proj_type == "slow" and self.target.alive:
|
||||
self.target.apply_slow(self.slow_factor, self.slow_duration)
|
||||
|
||||
if self.proj_type == "poison" and self.target.alive:
|
||||
self.target.apply_poison(self.poison_dps, self.poison_duration)
|
||||
|
||||
if self.proj_type == "lightning" and self.chain_count > 0:
|
||||
self._chain_lightning(enemies, self.target, self.damage, self.chain_count)
|
||||
|
||||
def _chain_lightning(self, enemies, source, damage, chains_left):
|
||||
if chains_left <= 0:
|
||||
return
|
||||
hit = [self.target, source]
|
||||
current = source
|
||||
current_damage = damage
|
||||
for _ in range(chains_left):
|
||||
current_damage *= self.chain_decay
|
||||
best = None
|
||||
best_dist = self.chain_range
|
||||
for e in enemies:
|
||||
if e.alive and e not in hit:
|
||||
d = distance(current.x, current.y, e.x, e.y)
|
||||
if d < best_dist:
|
||||
best_dist = d
|
||||
best = e
|
||||
if best:
|
||||
best.take_damage(current_damage)
|
||||
hit.append(best)
|
||||
current = best
|
||||
|
||||
def draw(self, surface):
|
||||
if not self.alive:
|
||||
return
|
||||
@@ -59,3 +95,12 @@ class Projectile:
|
||||
pygame.draw.circle(surface, COLOR_ORANGE, (ix, iy), 5)
|
||||
elif self.proj_type == "slow":
|
||||
pygame.draw.circle(surface, COLOR_CYAN, (ix, iy), 4)
|
||||
elif self.proj_type == "sniper":
|
||||
pygame.draw.circle(surface, (150, 180, 255), (ix, iy), 4)
|
||||
pygame.draw.circle(surface, COLOR_WHITE, (ix, iy), 2)
|
||||
elif self.proj_type == "poison":
|
||||
pygame.draw.circle(surface, COLOR_DARK_GREEN, (ix, iy), 5)
|
||||
pygame.draw.circle(surface, (100, 255, 100), (ix, iy), 3)
|
||||
elif self.proj_type == "lightning":
|
||||
pygame.draw.circle(surface, COLOR_BRIGHT_PURPLE, (ix, iy), 5)
|
||||
pygame.draw.circle(surface, (255, 255, 255), (ix, iy), 2)
|
||||
|
||||
Reference in New Issue
Block a user