Guest User

Untitled

a guest
Nov 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. WIDTH = 800
  2. HEIGHT = 500
  3.  
  4. player = Rect((20, HEIGHT - 70), (50, 50))
  5.  
  6. jumping = False
  7. velocity = 8
  8. gravity = 1
  9. ground = HEIGHT - 70
  10.  
  11. platforms = [
  12. Rect((0, HEIGHT-20), (WIDTH, 10)),
  13. Rect((100, HEIGHT - 100), (100, 10)),
  14. Rect((300, HEIGHT - 200), (100, 10)),
  15. Rect((500, HEIGHT - 250), (100, 10)),
  16. ]
  17.  
  18. def player_move():
  19. global jumping, velocity, ground
  20.  
  21. ''' Horizontal Movement '''
  22. if keyboard.left and player.left > 20:
  23. player.x -= 20
  24. if keyboard.right and player.right < WIDTH -20:
  25. player.x += 20
  26.  
  27. ''' Jumping '''
  28. if not jumping and keyboard[keys.SPACE]:
  29. jumping = True
  30. elif jumping:
  31. if velocity > 0:
  32. up_force = (velocity ** 2)
  33. else:
  34. up_force = (-velocity ** 2)
  35.  
  36. player.y -= up_force
  37. velocity -= gravity
  38.  
  39. if player.y > ground:
  40. player.y = ground
  41. jumping = False
  42. velocity = 8
  43.  
  44. ground = platforms[0].y-50
  45.  
  46. for platform in platforms:
  47. if player.colliderect(platform):
  48. ground = platform.y - 50
  49.  
  50.  
  51.  
  52. def draw():
  53. screen.fill((0,100,200))
  54.  
  55. for platform in platforms:
  56. screen.draw.filled_rect(platform, (255,0,0))
  57.  
  58. screen.draw.filled_rect(player, (200, 200, 0))
  59.  
  60. def update():
  61. player_move()
Add Comment
Please, Sign In to add comment