From a7db089ce4d3d4d879565efc2d2af80b44a0edc5 Mon Sep 17 00:00:00 2001 From: Wojciech Kubicki Date: Wed, 10 Apr 2024 17:41:16 +0200 Subject: [PATCH] feat(tractor): implement tank controls --- src/tractor.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/tractor.py b/src/tractor.py index 355a2865..25ae2f05 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -25,19 +25,19 @@ class Tractor(pygame.sprite.Sprite): surface.blit(self.image, self.rect) - def move(self, direction): - if direction == "up" and self.rect.y > 0: + def move(self): + if self.direction == "north" and self.rect.y > 0: self.rect.y -= TILE_SIZE self.log_info() - elif direction == "down" and self.rect.y < 15 * TILE_SIZE: + elif self.direction == "south" and self.rect.y < 15 * TILE_SIZE: self.rect.y += TILE_SIZE self.log_info() - elif direction == "left" and self.rect.x > 0: + elif self.direction == "west" and self.rect.x > 0: self.rect.x -= TILE_SIZE self.log_info() - elif direction == "right" and self.rect.x < 15 * TILE_SIZE: + elif self.direction == "east" and self.rect.x < 15 * TILE_SIZE: self.rect.x += TILE_SIZE - self.log_info() + self.log_info() def update(self): @@ -47,9 +47,7 @@ class Tractor(pygame.sprite.Sprite): if keys[pygame.K_RIGHT]: self.rotate('right') if keys[pygame.K_UP]: - self.move('up') - if keys[pygame.K_DOWN]: - self.move('down') + self.move() if keys[pygame.K_r]: self.water = 50 print(f"💧 replenished water level: {self.water} litres\n")