Add moving based on directions
This commit is contained in:
parent
74dd8fac0b
commit
84abac95e7
7
main.py
7
main.py
@ -10,10 +10,11 @@ if __name__ == "__main__":
|
|||||||
fps = 40
|
fps = 40
|
||||||
graphics = Graphics()
|
graphics = Graphics()
|
||||||
waiter = Waiter(graphics)
|
waiter = Waiter(graphics)
|
||||||
|
direction = 0
|
||||||
|
|
||||||
# init functions
|
# init functions
|
||||||
graphics.drawBackground(waiter.matrix)
|
graphics.drawBackground(waiter.matrix)
|
||||||
graphics.update(waiter.X, waiter.Y)
|
graphics.update(waiter.X, waiter.Y, waiter.direction)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@ -29,7 +30,7 @@ if __name__ == "__main__":
|
|||||||
break
|
break
|
||||||
|
|
||||||
graphics.clear(waiter.X, waiter.Y)
|
graphics.clear(waiter.X, waiter.Y)
|
||||||
waiter.update(event, graphics)
|
waiter.update(event, graphics, direction)
|
||||||
graphics.update(waiter.X, waiter.Y)
|
graphics.update(waiter.X, waiter.Y, waiter.direction)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(fps)
|
clock.tick(fps)
|
||||||
|
BIN
resources/images/waiter-down.png
Normal file
BIN
resources/images/waiter-down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
resources/images/waiter-left.png
Normal file
BIN
resources/images/waiter-left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
resources/images/waiter-right.png
Normal file
BIN
resources/images/waiter-right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
resources/images/waiter-up.png
Normal file
BIN
resources/images/waiter-up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
src/__pycache__/graphics.cpython-37.pyc
Normal file
BIN
src/__pycache__/graphics.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/matrix.cpython-37.pyc
Normal file
BIN
src/__pycache__/matrix.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/tile.cpython-37.pyc
Normal file
BIN
src/__pycache__/tile.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/waiter.cpython-37.pyc
Normal file
BIN
src/__pycache__/waiter.cpython-37.pyc
Normal file
Binary file not shown.
@ -10,6 +10,10 @@ class Graphics:
|
|||||||
'bar_floor': pygame.image.load('../resources/images/waiter.png'), #
|
'bar_floor': pygame.image.load('../resources/images/waiter.png'), #
|
||||||
'table': pygame.image.load('../resources/images/table3.png'),
|
'table': pygame.image.load('../resources/images/table3.png'),
|
||||||
'waiter': pygame.image.load('../resources/images/waiter.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'),
|
'table2': pygame.image.load('../resources/images/table2.png'),
|
||||||
'table3': pygame.image.load('../resources/images/table3.png'),
|
'table3': pygame.image.load('../resources/images/table3.png'),
|
||||||
'chair': pygame.image.load('../resources/images/waiter.png'),
|
'chair': pygame.image.load('../resources/images/waiter.png'),
|
||||||
@ -35,5 +39,13 @@ class Graphics:
|
|||||||
def clear(self, x, y):
|
def clear(self, x, y):
|
||||||
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size))
|
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))
|
self.screen.blit(self.image['waiter'], (x * self.block_size, y * self.block_size))
|
||||||
|
@ -9,6 +9,7 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.X = 0
|
self.X = 0
|
||||||
self.Y = 0
|
self.Y = 0
|
||||||
|
self.direction = 0
|
||||||
self.frame = 0
|
self.frame = 0
|
||||||
self.matrix = Matrix(graphics=graphics)
|
self.matrix = Matrix(graphics=graphics)
|
||||||
|
|
||||||
@ -19,14 +20,34 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
self.X += x
|
self.X += x
|
||||||
self.Y += y
|
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.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
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:
|
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:
|
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:
|
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)
|
print(self.X, self.Y)
|
||||||
|
Loading…
Reference in New Issue
Block a user