Fix not erasing the previous waiter position
This commit is contained in:
parent
486a6a9d42
commit
4fef084602
21
src/main.py
21
src/main.py
@ -8,16 +8,23 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.moveX = 0
|
self.moveX = 0
|
||||||
self.moveY = 0
|
self.moveY = 0
|
||||||
|
self.clearX = 0
|
||||||
|
self.clearY = 0
|
||||||
self.frame = 0
|
self.frame = 0
|
||||||
self.image = waiter
|
self.imageWaiter = waiter
|
||||||
|
self.imageFloor = floor
|
||||||
|
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
self.moveX += x
|
self.moveX += x
|
||||||
self.moveY -= y
|
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):
|
def update(self):
|
||||||
screen.blit(floor, ())
|
screen.blit(self.imageWaiter, (self.moveX * block_size, self.moveY * block_size))
|
||||||
screen.blit(waiter, (self.moveX * block_size, self.moveY * block_size))
|
|
||||||
|
|
||||||
|
|
||||||
# SETUP
|
# SETUP
|
||||||
@ -38,8 +45,6 @@ waiter = pygame.image.load('../resources/images/waiter.png')
|
|||||||
def drawBackground():
|
def drawBackground():
|
||||||
for y in range(15):
|
for y in range(15):
|
||||||
for x in range(14):
|
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))
|
screen.blit(floor, (x * block_size, y * block_size))
|
||||||
|
|
||||||
|
|
||||||
@ -57,14 +62,18 @@ def main():
|
|||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
waiterPly.move(-rect, 0)
|
waiterPly.move(-rect, 0)
|
||||||
|
waiterPly.clear(rect, 0)
|
||||||
if event.key == pygame.K_RIGHT:
|
if event.key == pygame.K_RIGHT:
|
||||||
waiterPly.move(rect, 0)
|
waiterPly.move(rect, 0)
|
||||||
|
waiterPly.clear(-rect, 0)
|
||||||
if event.key == pygame.K_UP:
|
if event.key == pygame.K_UP:
|
||||||
waiterPly.move(0, rect)
|
waiterPly.move(0, rect)
|
||||||
|
waiterPly.clear(0, rect)
|
||||||
if event.key == pygame.K_DOWN:
|
if event.key == pygame.K_DOWN:
|
||||||
waiterPly.move(0, -rect)
|
waiterPly.move(0, -rect)
|
||||||
|
waiterPly.clear(0, -rect)
|
||||||
waiterPly.update()
|
waiterPly.update()
|
||||||
pygame.display.update()
|
pygame.display.flip()
|
||||||
clock.tick(fps)
|
clock.tick(fps)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user