feat(tractor): print out on what tile type the tractor is currently on

This commit is contained in:
Wojciech Kubicki 2024-03-25 00:38:40 +01:00
parent af87ff2475
commit eaaac9f277

View File

@ -25,12 +25,16 @@ class Tractor(pygame.sprite.Sprite):
if direction == "up" and self.rect.y > 0: if direction == "up" and self.rect.y > 0:
self.rect.y -= TILE_SIZE self.rect.y -= TILE_SIZE
self.print_tile_type()
elif direction == "down" and self.rect.y < 15 * TILE_SIZE: elif direction == "down" and self.rect.y < 15 * TILE_SIZE:
self.rect.y += TILE_SIZE self.rect.y += TILE_SIZE
self.print_tile_type()
elif direction == "left" and self.rect.x > 0: elif direction == "left" and self.rect.x > 0:
self.rect.x -= TILE_SIZE self.rect.x -= TILE_SIZE
self.print_tile_type()
elif direction == "right" and self.rect.x < 15 * TILE_SIZE: elif direction == "right" and self.rect.x < 15 * TILE_SIZE:
self.rect.x += TILE_SIZE self.rect.x += TILE_SIZE
self.print_tile_type()
def update(self): def update(self):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
@ -42,3 +46,12 @@ class Tractor(pygame.sprite.Sprite):
self.move('up') self.move('up')
if keys[pygame.K_DOWN]: if keys[pygame.K_DOWN]:
self.move('down') self.move('down')
def print_tile_type(self):
load_dotenv(find_dotenv())
TILE_SIZE = int(os.getenv("TILE_SIZE"))
x = self.rect.x // TILE_SIZE
y = self.rect.y // TILE_SIZE
tile_type = self.field.tiles.sprites()[y * 16 + x].type
print(f"The tractor is on a {tile_type} tile.")