diff --git a/main.py b/main.py index 016ffe0..32f4ea2 100644 --- a/main.py +++ b/main.py @@ -10,10 +10,11 @@ if __name__ == "__main__": fps = 40 graphics = Graphics() waiter = Waiter(graphics) + direction = 0 # init functions graphics.drawBackground(waiter.matrix) - graphics.update(waiter.X, waiter.Y) + graphics.update(waiter.X, waiter.Y, waiter.direction) while True: for event in pygame.event.get(): @@ -29,7 +30,7 @@ if __name__ == "__main__": break graphics.clear(waiter.X, waiter.Y) - waiter.update(event, graphics) - graphics.update(waiter.X, waiter.Y) + waiter.update(event, graphics, direction) + graphics.update(waiter.X, waiter.Y, waiter.direction) pygame.display.flip() clock.tick(fps) diff --git a/resources/images/waiter-down.png b/resources/images/waiter-down.png new file mode 100644 index 0000000..1dfcda9 Binary files /dev/null and b/resources/images/waiter-down.png differ diff --git a/resources/images/waiter-left.png b/resources/images/waiter-left.png new file mode 100644 index 0000000..b73a519 Binary files /dev/null and b/resources/images/waiter-left.png differ diff --git a/resources/images/waiter-right.png b/resources/images/waiter-right.png new file mode 100644 index 0000000..0dab824 Binary files /dev/null and b/resources/images/waiter-right.png differ diff --git a/resources/images/waiter-up.png b/resources/images/waiter-up.png new file mode 100644 index 0000000..4961d84 Binary files /dev/null and b/resources/images/waiter-up.png differ diff --git a/src/__pycache__/graphics.cpython-37.pyc b/src/__pycache__/graphics.cpython-37.pyc new file mode 100644 index 0000000..a06bfb5 Binary files /dev/null and b/src/__pycache__/graphics.cpython-37.pyc differ diff --git a/src/__pycache__/matrix.cpython-37.pyc b/src/__pycache__/matrix.cpython-37.pyc new file mode 100644 index 0000000..01dd607 Binary files /dev/null and b/src/__pycache__/matrix.cpython-37.pyc differ diff --git a/src/__pycache__/tile.cpython-37.pyc b/src/__pycache__/tile.cpython-37.pyc new file mode 100644 index 0000000..465e2fb Binary files /dev/null and b/src/__pycache__/tile.cpython-37.pyc differ diff --git a/src/__pycache__/waiter.cpython-37.pyc b/src/__pycache__/waiter.cpython-37.pyc new file mode 100644 index 0000000..19e2854 Binary files /dev/null and b/src/__pycache__/waiter.cpython-37.pyc differ diff --git a/src/graphics.py b/src/graphics.py index 6424701..8e67265 100644 --- a/src/graphics.py +++ b/src/graphics.py @@ -10,6 +10,10 @@ class Graphics: 'bar_floor': pygame.image.load('../resources/images/waiter.png'), # 'table': pygame.image.load('../resources/images/table3.png'), 'waiter': pygame.image.load('../resources/images/waiter.png'), + 'waiter-down': pygame.image.load('../resources/images/waiter-down.png'), + 'waiter-left': pygame.image.load('../resources/images/waiter-left.png'), + 'waiter-right': pygame.image.load('../resources/images/waiter-right.png'), + 'waiter-up': pygame.image.load('../resources/images/waiter-up.png'), 'table2': pygame.image.load('../resources/images/table2.png'), 'table3': pygame.image.load('../resources/images/table3.png'), 'chair': pygame.image.load('../resources/images/waiter.png'), @@ -35,5 +39,13 @@ class Graphics: def clear(self, x, y): self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) - def update(self, x, y): + def update(self, x, y, direction): + if direction == 1: + self.screen.blit(self.image['waiter-up'], (x * self.block_size, y * self.block_size)) + if direction == 2: + self.screen.blit(self.image['waiter-right'], (x * self.block_size, y * self.block_size)) + if direction == 3: + self.screen.blit(self.image['waiter-down'], (x * self.block_size, y * self.block_size)) + if direction == 4: + self.screen.blit(self.image['waiter-left'], (x * self.block_size, y * self.block_size)) self.screen.blit(self.image['waiter'], (x * self.block_size, y * self.block_size)) diff --git a/src/waiter.py b/src/waiter.py index b6e1de5..e43e456 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -9,6 +9,7 @@ class Waiter(pygame.sprite.Sprite): pygame.sprite.Sprite.__init__(self) self.X = 0 self.Y = 0 + self.direction = 0 self.frame = 0 self.matrix = Matrix(graphics=graphics) @@ -19,14 +20,34 @@ class Waiter(pygame.sprite.Sprite): self.X += x self.Y += y - def update(self, event, graphics): + def arrow(self, direction): + self.direction = direction + + def update(self, event, graphics, direction): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: - self.move(-1, 0, graphics) + self.arrow(4) + #self.move(-1, 0, graphics) if event.key == pygame.K_RIGHT: - self.move(1, 0, graphics) + self.arrow(2) + #self.move(1, 0, graphics) if event.key == pygame.K_UP: - self.move(0, -1, graphics) + self.arrow(1) + #self.move(0, -1, graphics) if event.key == pygame.K_DOWN: - self.move(0, 1, graphics) + self.arrow(3) + #self.move(0, 1, graphics) + if event.key == pygame.K_SPACE: + #up + if self.direction == 1: + self.move(0, -1, graphics) + #righ + if self.direction == 2: + self.move(1, 0, graphics) + #down + if self.direction == 3: + self.move(0, 1, graphics) + #left + if self.direction == 4: + self.move(-1, 0, graphics) print(self.X, self.Y)