fix(tractor): prevent tractor from moving off board

This commit is contained in:
Wojciech Kubicki 2024-03-25 00:11:09 +01:00
parent 8dceac3ebe
commit af87ff2475

View File

@ -23,13 +23,13 @@ class Tractor(pygame.sprite.Sprite):
load_dotenv(find_dotenv()) load_dotenv(find_dotenv())
TILE_SIZE = int(os.getenv("TILE_SIZE")) TILE_SIZE = int(os.getenv("TILE_SIZE"))
if direction == "up": if direction == "up" and self.rect.y > 0:
self.rect.y -= TILE_SIZE self.rect.y -= TILE_SIZE
elif direction == "down": elif direction == "down" and self.rect.y < 15 * TILE_SIZE:
self.rect.y += TILE_SIZE self.rect.y += TILE_SIZE
elif direction == "left": elif direction == "left" and self.rect.x > 0:
self.rect.x -= TILE_SIZE self.rect.x -= TILE_SIZE
elif direction == "right": elif direction == "right" and self.rect.x < 15 * TILE_SIZE:
self.rect.x += TILE_SIZE self.rect.x += TILE_SIZE
def update(self): def update(self):