feat(tractor): rotate tractor on left-right arrow keys
This commit is contained in:
parent
e6566cee48
commit
a1d4895a7a
@ -43,9 +43,9 @@ 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]:
|
||||
@ -103,3 +103,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