shh_algo_PY

Sample - Student Platformer

Apr 24th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.44 KB | None | 0 0
  1. import play
  2. import pygame
  3. from random import randint
  4.  
  5. play.set_backdrop("beige")
  6.  
  7. death = play.new_box(color = "beige", width = 1000, height = 30, x = 0, y = -300)
  8. sea = play.new_image("seaside.jpg", size = 27.5, x = 0, y = 85)
  9.  
  10. score_txt = play.new_text(words = 'Completion:', x=play.screen.right-160, y=play.screen.top-30, size=70)
  11. score = play.new_text(words = '0', x=play.screen.right-65, y=play.screen.top-30, size=70)
  12. percentage = play.new_text(words = '%', x=play.screen.right-30, y=play.screen.top-30, size=70)
  13.  
  14. text = play.new_text(color = "grey", words='Tap W to jump, LEFT/RIGHT to move', x=0, y=play.screen.bottom+60, size=70)
  15.  
  16. #player
  17. player = play.new_box(width = 20, height = 35, x = -380, y = 175, color = "beige", border_color = "brown", border_width = 2.5)
  18.  
  19. #platforms
  20. platforms = []  
  21.  
  22. platform_1 = play.new_box(width = 150, height = 10, x = -350, y = 150, color = "brown")
  23. platforms.append(platform_1)
  24.  
  25. platform_2 = play.new_box(width = 150, height = 10, x = 350, y = 150, color = "brown")
  26. platforms.append(platform_2)
  27.  
  28. platform_3 = play.new_box(width = 150, height = 10, x = 0, y = 100, color = "brown")
  29. platforms.append(platform_3)
  30.  
  31. platform_4 = play.new_box(width = 125, height = 10, x = -360, y = 105, angle = 45, color = "brown")
  32. platforms.append(platform_4)
  33.  
  34. platform_5 = play.new_box(width = 125, height = 10, x = 360, y = 105, angle = -45, color = "brown")
  35. platforms.append(platform_5)
  36.  
  37. platform_6 = play.new_box(width = 150, height = 10, x = -120, y = 0, color = "brown")
  38. platforms.append(platform_6)
  39.  
  40. platform_7 = play.new_box(width = 150, height = 10, x = 120, y = 0, color = "brown")
  41. platforms.append(platform_7)
  42.  
  43. #shells
  44. shells = []
  45.  
  46. shell_1 = play.new_image(image = "shell-removebg-preview.png", size = 7.5, x = -120, y = 25)
  47. shells.append(shell_1)
  48.  
  49. shell_2 = play.new_image(image = "shell-removebg-preview.png", size = 7.5, x = 0, y = 125)
  50. shells.append(shell_2)
  51.  
  52. shell_3 = play.new_image(image = "shell-removebg-preview.png", size = 7.5, x = 120, y = 25)
  53. shells.append(shell_3)
  54.  
  55. shell_4 = play.new_image(image = "shell-removebg-preview.png", size = 7.5, x = 300, y = 175)
  56. shells.append(shell_4)
  57.  
  58. @play.when_program_starts
  59. def start():
  60.     player.start_physics(can_move = True, stable = True, obeys_gravity = True, mass = 100, friction = 1.0, bounciness = 0.1)
  61.  
  62.     for platform in platforms:
  63.         platform.start_physics(can_move = False, stable = True, obeys_gravity = False, mass = 10)
  64.  
  65. @play.repeat_forever
  66. async def game():
  67.     if play.key_is_pressed("a"):
  68.         player.physics.x_speed = -10
  69.  
  70.     if play.key_is_pressed("d"):
  71.         player.physics.x_speed = 10
  72.  
  73.     if play.key_is_pressed("w"):
  74.         if player.is_touching(platform_1):
  75.             player.physics.y_speed = 50
  76.        
  77.         elif player.is_touching(platform_2):
  78.             player.physics.y_speed = 50
  79.  
  80.         elif player.is_touching(platform_3):
  81.             player.physics.y_speed = 200
  82.  
  83.         elif player.is_touching(platform_6):
  84.             player.physics.y_speed = 200
  85.  
  86.         elif player.is_touching(platform_7):
  87.             player.physics.y_speed = 200
  88.  
  89.         else:
  90.             player.physics.y_speed = 0
  91.  
  92.     #to collect shells
  93.     for s in shells:
  94.         if s.is_touching(player):
  95.             s.hide()
  96.             shells.remove(s)
  97.             score.words = str(int(score.words) + 25)
  98.  
  99.     #losing check
  100.     if player.is_touching(death):
  101.         for s in shells:
  102.             s.hide
  103.         sea.hide()
  104.         score.hide()
  105.         score_txt.hide()
  106.         percentage.hide()
  107.         for i in platforms:
  108.             i.hide()
  109.         player.hide()
  110.         for i in shells:
  111.             i.hide()
  112.         text.hide()
  113.         lose = play.new_image(image = "pic.jpg", size = 200, x = 0, y = -50)
  114.         lose_text = play.new_text(words = "YOU LOSE", color = "black", x = 0, y = 250, size = 200)
  115.         await play.timer(3)
  116.         quit()
  117.  
  118.     #win check
  119.     if len(shells) == 0:
  120.         await play.timer(3)
  121.         for s in shells:
  122.             s.hide
  123.         sea.hide()
  124.         score.hide()
  125.         score_txt.hide()
  126.         percentage.hide()
  127.         for i in platforms:
  128.             i.hide()
  129.         player.hide()
  130.         for i in shells:
  131.             i.hide()
  132.         text.hide()
  133.         win = play.new_image(image = "image.jpg", size = 75)
  134.         win_text = play.new_text(words = "WIN", color = "blue", x = -250, y = 200, size = 150)
  135.  
  136.     await play.timer(seconds=1/48)
  137.  
  138. play.start_program()
Advertisement
Add Comment
Please, Sign In to add comment