From af87ff247504a5d935424be55c472406a3b54be1 Mon Sep 17 00:00:00 2001 From: Wojciech Kubicki Date: Mon, 25 Mar 2024 00:11:09 +0100 Subject: [PATCH] fix(tractor): prevent tractor from moving off board --- src/tractor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tractor.py b/src/tractor.py index 1cc10031..b2831d6b 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -23,13 +23,13 @@ class Tractor(pygame.sprite.Sprite): load_dotenv(find_dotenv()) TILE_SIZE = int(os.getenv("TILE_SIZE")) - if direction == "up": + if direction == "up" and self.rect.y > 0: self.rect.y -= TILE_SIZE - elif direction == "down": + elif direction == "down" and self.rect.y < 15 * TILE_SIZE: self.rect.y += TILE_SIZE - elif direction == "left": + elif direction == "left" and self.rect.x > 0: self.rect.x -= TILE_SIZE - elif direction == "right": + elif direction == "right" and self.rect.x < 15 * TILE_SIZE: self.rect.x += TILE_SIZE def update(self):