Browse Source

Implemented player movement

master
Elis Axelsson 4 years ago
parent
commit
244ecd5185
  1. 22
      watersteal.py

22
watersteal.py

@ -38,20 +38,36 @@ bucketrect.bottomleft = (width * 0.9, (height / 4 * 3))
player = Player(pygame, (0, 0, 0), (60, 100)).getPlayer()
playerrect = player.get_rect()
playerrect.bottomleft = (10, (height / 4 * 3))
playerspeed = 0
while True:
# Handle events
for event in pygame.event.get():
# Handle keypresses
if event.type == pygame.KEYDOWN:
pressedKeys = pygame.key.get_pressed()
pressedKeys = pygame.key.get_pressed()
# Handle keydown
if event.type == pygame.KEYDOWN:
if pressedKeys[pygame.K_q]:
sys.exit()
if pressedKeys[pygame.K_RIGHT]:
playerspeed = 1
if pressedKeys[pygame.K_LEFT]:
playerspeed = -1
# Handle keyup
if event.type == pygame.KEYUP:
# Stop player if no key is pressed
if (pressedKeys[pygame.K_RIGHT] + pressedKeys[pygame.K_LEFT]) == 0:
playerspeed = 0;
if event.type == pygame.QUIT:
sys.exit()
# Move player
playerrect = playerrect.move((playerspeed, 0))
# Move ball
ballrect = ballrect.move(speed)

Loading…
Cancel
Save