Fix not erasing the previous waiter position

This commit is contained in:
s450026 2020-04-02 23:26:17 +02:00
parent 486a6a9d42
commit 4fef084602

View File

@ -8,16 +8,23 @@ class Waiter(pygame.sprite.Sprite):
pygame.sprite.Sprite.__init__(self)
self.moveX = 0
self.moveY = 0
self.clearX = 0
self.clearY = 0
self.frame = 0
self.image = waiter
self.imageWaiter = waiter
self.imageFloor = floor
def move(self, x, y):
self.moveX += x
self.moveY -= y
def clear(self, x, y):
cx = self.moveX + x
cy = self.moveY + y
screen.blit(self.imageFloor, (cx * block_size, cy * block_size))
def update(self):
screen.blit(floor, ())
screen.blit(waiter, (self.moveX * block_size, self.moveY * block_size))
screen.blit(self.imageWaiter, (self.moveX * block_size, self.moveY * block_size))
# SETUP
@ -38,8 +45,6 @@ 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))
@ -57,14 +62,18 @@ def main():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
waiterPly.move(-rect, 0)
waiterPly.clear(rect, 0)
if event.key == pygame.K_RIGHT:
waiterPly.move(rect, 0)
waiterPly.clear(-rect, 0)
if event.key == pygame.K_UP:
waiterPly.move(0, rect)
waiterPly.clear(0, rect)
if event.key == pygame.K_DOWN:
waiterPly.move(0, -rect)
waiterPly.clear(0, -rect)
waiterPly.update()
pygame.display.update()
pygame.display.flip()
clock.tick(fps)