tower building check function
This commit is contained in:
+20
-1
@@ -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
|
||||
@@ -29,4 +30,22 @@ class Tower:
|
||||
# freie Position finden - nicht auf dem Tisch oder blockierten Rects
|
||||
if not any(rect.colliderect(b) for b in blocked_rects):
|
||||
self.field_rect = rect
|
||||
return
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user