tower building check function
This commit is contained in:
@@ -9,6 +9,7 @@ fire_interval = 1000 # ms zwischen Schüssen
|
|||||||
respawn_delay = 10000 # ms bis neues Feld spawnt
|
respawn_delay = 10000 # ms bis neues Feld spawnt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Tower:
|
class Tower:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
# Feld und Tower -> None wenn nicht aktiv
|
# Feld und Tower -> None wenn nicht aktiv
|
||||||
@@ -30,3 +31,21 @@ class Tower:
|
|||||||
if not any(rect.colliderect(b) for b in blocked_rects):
|
if not any(rect.colliderect(b) for b in blocked_rects):
|
||||||
self.field_rect = rect
|
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