Compare commits
2 Commits
e6566cee48
...
a7db089ce4
Author | SHA1 | Date | |
---|---|---|---|
|
a7db089ce4 | ||
|
a1d4895a7a |
@ -25,17 +25,17 @@ 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()
|
||||
|
||||
@ -43,13 +43,11 @@ class Tractor(pygame.sprite.Sprite):
|
||||
def update(self):
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT]:
|
||||
self.move('left')
|
||||
self.rotate('left')
|
||||
if keys[pygame.K_RIGHT]:
|
||||
self.move('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")
|
||||
@ -103,3 +101,38 @@ class Tractor(pygame.sprite.Sprite):
|
||||
|
||||
return neighbors
|
||||
|
||||
|
||||
def rotate(self, rotate):
|
||||
match (self.direction, rotate):
|
||||
case ("north", "left"):
|
||||
self.image = pygame.image.load('images/tractor/west.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'west'
|
||||
case ("north", "right"):
|
||||
self.image = pygame.image.load('images/tractor/east.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'east'
|
||||
case ("east", "right"):
|
||||
self.image = pygame.image.load('images/tractor/south.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'south'
|
||||
case ("east", "left"):
|
||||
self.image = pygame.image.load('images/tractor/north.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'north'
|
||||
case ("south", "right"):
|
||||
self.image = pygame.image.load('images/tractor/west.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'west'
|
||||
case ("south", "left"):
|
||||
self.image = pygame.image.load('images/tractor/east.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'east'
|
||||
case ("west", "left"):
|
||||
self.image = pygame.image.load('images/tractor/south.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'south'
|
||||
case ("west", "right"):
|
||||
self.image = pygame.image.load('images/tractor/north.png').convert_alpha()
|
||||
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
self.direction = 'north'
|
||||
|
Loading…
Reference in New Issue
Block a user