Browse Source

Make it possible to pick up the bucket

master
Elis Axelsson 4 years ago
parent
commit
656440a515
  1. 18
      watersteal.py

18
watersteal.py

@ -39,6 +39,7 @@ player = Player(pygame, (0, 0, 0), (60, 100)).getPlayer()
playerrect = player.get_rect()
playerrect.bottomleft = (10, (height / 4 * 3))
playerspeed = 0
playerHasBucket = False
while True:
# Handle events
@ -56,6 +57,13 @@ while True:
if pressedKeys[pygame.K_LEFT]:
playerspeed = -1
if pressedKeys[pygame.K_SPACE]:
if playerrect.colliderect(bucketrect):
# Move bucket to player hand
bucketrect.top = bucketrect.top - 60
bucketrect.left = playerrect.right
playerHasBucket = True
# Handle keyup
if event.type == pygame.KEYUP:
# Stop player if no key is pressed
@ -71,6 +79,16 @@ while True:
# Move ball
ballrect = ballrect.move(speed)
# Move bucket if player moves
if playerHasBucket:
bucketrect = bucketrect.move((playerspeed, 0))
# If player get rekt by the ball, move player back to start position
if playerrect.colliderect(ballrect):
playerrect.left = 0
playerHasBucket = False
bucketrect.bottomleft = (width * 0.9, (height / 4 * 3))
# Direct ball movement
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]

Loading…
Cancel
Save