tower building check function

This commit is contained in:
Lukas Kammerhofer
2026-05-08 16:16:55 +02:00
parent b9a1bff5e4
commit 7a42484ded
+19
View File
@@ -9,6 +9,7 @@ fire_interval = 1000 # ms zwischen Schüssen
respawn_delay = 10000 # ms bis neues Feld spawnt
class Tower:
def __init__(self) -> None:
# Feld und Tower -> None wenn nicht aktiv
@@ -30,3 +31,21 @@ class Tower:
if not any(rect.colliderect(b) for b in blocked_rects):
self.field_rect = rect
return
def try_build(self, player_rect: pygame.Rect, keys: pygame.key.ScancodeWrapper, ects):
# Baut Tower wenn Spieler E drückt, auf Feld steht und genug ects hat
if not self.field.rect or self.tower.rect:
return False
if not (self.field_rect.colliderect(player_rect) and keys[pygame.K_e] and ects.balance >= TOWER_COST):
return False
ects.balance -= TOWER_COST
self.tower_rect = self.field_rect
self.field_rect = None
self.tower_start = pygame.time.get_ticks()
return True