2020-03-23 20:55:52 +01:00
|
|
|
import sys
|
|
|
|
import pygame
|
|
|
|
|
2020-04-02 22:28:30 +02:00
|
|
|
|
|
|
|
# WAITER
|
|
|
|
class Waiter(pygame.sprite.Sprite):
|
|
|
|
def __init__(self):
|
|
|
|
pygame.sprite.Sprite.__init__(self)
|
|
|
|
self.moveX = 0
|
|
|
|
self.moveY = 0
|
2020-04-02 23:26:17 +02:00
|
|
|
self.clearX = 0
|
|
|
|
self.clearY = 0
|
2020-04-02 22:28:30 +02:00
|
|
|
self.frame = 0
|
2020-04-02 23:26:17 +02:00
|
|
|
self.imageWaiter = waiter
|
|
|
|
self.imageFloor = floor
|
2020-04-02 22:28:30 +02:00
|
|
|
|
|
|
|
def move(self, x, y):
|
|
|
|
self.moveX += x
|
|
|
|
self.moveY -= y
|
|
|
|
|
2020-04-02 23:26:17 +02:00
|
|
|
def clear(self, x, y):
|
|
|
|
cx = self.moveX + x
|
|
|
|
cy = self.moveY + y
|
|
|
|
screen.blit(self.imageFloor, (cx * block_size, cy * block_size))
|
|
|
|
|
2020-04-02 22:28:30 +02:00
|
|
|
def update(self):
|
2020-04-02 23:26:17 +02:00
|
|
|
screen.blit(self.imageWaiter, (self.moveX * block_size, self.moveY * block_size))
|
2020-04-02 22:28:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
# SETUP
|
2020-03-23 20:55:52 +01:00
|
|
|
pygame.init()
|
2020-04-02 20:37:21 +02:00
|
|
|
screen = pygame.display.set_mode((700, 750))
|
2020-03-23 20:55:52 +01:00
|
|
|
done = False
|
2020-04-02 20:37:21 +02:00
|
|
|
block_size = 50
|
2020-04-02 22:28:30 +02:00
|
|
|
clock = pygame.time.Clock()
|
|
|
|
fps = 40
|
|
|
|
ani = 40
|
|
|
|
rect = 1
|
2020-03-23 20:55:52 +01:00
|
|
|
|
2020-04-02 22:28:30 +02:00
|
|
|
floor = pygame.image.load('../resources/images/floor.jpg')
|
|
|
|
table = pygame.image.load('../resources/images/table.png')
|
|
|
|
waiter = pygame.image.load('../resources/images/waiter.png')
|
2020-03-23 20:55:52 +01:00
|
|
|
|
2020-04-02 22:28:30 +02:00
|
|
|
|
|
|
|
def drawBackground():
|
2020-04-02 20:37:21 +02:00
|
|
|
for y in range(15):
|
|
|
|
for x in range(14):
|
2020-04-02 22:28:30 +02:00
|
|
|
screen.blit(floor, (x * block_size, y * block_size))
|
|
|
|
|
|
|
|
|
|
|
|
waiterPly = Waiter()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
drawBackground()
|
2020-03-23 20:55:52 +01:00
|
|
|
|
|
|
|
while not done:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit()
|
2020-04-02 22:28:30 +02:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
|
|
|
waiterPly.move(-rect, 0)
|
2020-04-02 23:26:17 +02:00
|
|
|
waiterPly.clear(rect, 0)
|
2020-04-02 22:28:30 +02:00
|
|
|
if event.key == pygame.K_RIGHT:
|
|
|
|
waiterPly.move(rect, 0)
|
2020-04-02 23:26:17 +02:00
|
|
|
waiterPly.clear(-rect, 0)
|
2020-04-02 22:28:30 +02:00
|
|
|
if event.key == pygame.K_UP:
|
|
|
|
waiterPly.move(0, rect)
|
2020-04-02 23:26:17 +02:00
|
|
|
waiterPly.clear(0, rect)
|
2020-04-02 22:28:30 +02:00
|
|
|
if event.key == pygame.K_DOWN:
|
|
|
|
waiterPly.move(0, -rect)
|
2020-04-02 23:26:17 +02:00
|
|
|
waiterPly.clear(0, -rect)
|
2020-04-02 22:28:30 +02:00
|
|
|
waiterPly.update()
|
2020-04-02 23:26:17 +02:00
|
|
|
pygame.display.flip()
|
2020-04-02 22:28:30 +02:00
|
|
|
clock.tick(fps)
|
2020-03-23 20:55:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
main()
|