From 4fef084602ac1d8ccd39b109dbc60b9c86cfdd7a Mon Sep 17 00:00:00 2001 From: s450026 Date: Thu, 2 Apr 2020 23:26:17 +0200 Subject: [PATCH] Fix not erasing the previous waiter position --- src/main.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 98504a6..0dcd5e4 100644 --- a/src/main.py +++ b/src/main.py @@ -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)