projectile movement and tower despawn
This commit is contained in:
+34
-1
@@ -4,7 +4,7 @@ import math
|
||||
from src.settings import TOWER_COST, PROJECTILE_DMG, PROJECTILE_SPEED, COLOR_PROJECTILE, TOWER_TIMER
|
||||
|
||||
tower_size = 30
|
||||
prjectile_size = 8
|
||||
projectile_size = 8
|
||||
fire_interval = 1000 # ms zwischen Schüssen
|
||||
respawn_delay = 10000 # ms bis neues Feld spawnt
|
||||
|
||||
@@ -69,6 +69,39 @@ class Tower:
|
||||
|
||||
self.last_shot = now
|
||||
|
||||
# Bewegung der Projektile und Kollision mit Monster prüfen
|
||||
for p in self.projectiles[:]:
|
||||
p["x"] += p["vel_x"]
|
||||
p["y"] += p["vel_y"]
|
||||
|
||||
if monster_rect and pygame.Rect(int(p["x"]), int(p["y"]), projectile_size, projectile_size).colliderect(monster_rect):
|
||||
total_damage += PROJECTILE_DMG
|
||||
self.projectiles.remove(p)
|
||||
|
||||
# wenn der Tower abgelaufen ist, soll er despawnen und ein Timer starten
|
||||
if self.tower_rect and self.tower_start and now - self.tower_start >= TOWER_TIMER:
|
||||
self.tower_rect = None
|
||||
self.despawn_timer = now
|
||||
self.projectiles = []
|
||||
|
||||
# ein neues Feld soll spawnen nach dem Respawn Delay
|
||||
if not self.tower_rect and not self.field_rect and self.despawn_time:
|
||||
if now - self.despawn_time >= respawn_delay:
|
||||
self.spawn_field(room_rect, blocked_rects)
|
||||
self.despawn_time = None
|
||||
|
||||
return total_damage
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user