Add simple movement

This commit is contained in:
s450026 2020-04-02 22:28:30 +02:00
parent c6bdef1aff
commit 486a6a9d42
4 changed files with 51 additions and 8 deletions

BIN
resources/images/floor.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
resources/images/table.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
resources/images/waiter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -1,28 +1,71 @@
import sys
import pygame
# WAITER
class Waiter(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.moveX = 0
self.moveY = 0
self.frame = 0
self.image = waiter
def move(self, x, y):
self.moveX += x
self.moveY -= y
def update(self):
screen.blit(floor, ())
screen.blit(waiter, (self.moveX * block_size, self.moveY * block_size))
# SETUP
pygame.init()
screen = pygame.display.set_mode((700, 750))
done = False
block_size = 50
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
screen.fill(WHITE)
clock = pygame.time.Clock()
fps = 40
ani = 40
rect = 1
floor = pygame.image.load('../resources/images/floor.jpg')
table = pygame.image.load('../resources/images/table.png')
waiter = pygame.image.load('../resources/images/waiter.png')
def drawBackground():
for y in range(15):
for x in range(14):
# rect = pygame.Rect(x * block_size, y * block_size, block_size - 1, block_size - 1)
# pygame.draw.rect(screen, floor, rect)
screen.blit(floor, (x * block_size, y * block_size))
waiterPly = Waiter()
def main():
for y in range(15):
for x in range(14):
rect = pygame.Rect(x * block_size, y * block_size, block_size - 1, block_size - 1)
pygame.draw.rect(screen, BLUE, rect)
drawBackground()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
waiterPly.move(-rect, 0)
if event.key == pygame.K_RIGHT:
waiterPly.move(rect, 0)
if event.key == pygame.K_UP:
waiterPly.move(0, rect)
if event.key == pygame.K_DOWN:
waiterPly.move(0, -rect)
waiterPly.update()
pygame.display.update()
clock.tick(fps)
main()