shh_algo_PY

Arkanoid Game

Mar 27th, 2022 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. # IMPORT THE MODULES
  2.  
  3. import play
  4. from random import randint
  5.  
  6. # SET THE STAGE, MAKE ALL THE SPRITES!
  7.  
  8. play.set_backdrop('white')
  9.  
  10. frames = 15
  11.  
  12. lose = play.new_text(words='YOU LOSE', font_size=100, color='red')
  13.  
  14. win = play.new_text(words='YOU WIN', font_size=100, color='yellow')
  15.  
  16. platform = play.new_box(color='brown', y = -250, width = 150, height = 15)
  17.  
  18. ball = play.new_circle(color='green', y = -160, radius = 15)
  19.  
  20. # THIS IS A LIST FOR IF YOU'RE USING A FOR LOOP!
  21.  
  22. blocks = []
  23.  
  24. @play.when_program_starts
  25. def start():
  26.     platform.start_physics(stable=True, obeys_gravity=False, bounciness=1, mass=1)
  27.  
  28.     ball.start_physics(stable=False, x_speed=30, y_speed=30, obeys_gravity=False, bounciness=1, mass=10)
  29.  
  30.     block_x = play.screen.left+75
  31.     block_y = play.screen.top-50
  32.  
  33.     for i in range(2):
  34.         while (block_x <= play.screen.right-30):
  35.             block=play.new_box(color='grey', x=block_x, y=block_y, width=110, height=30, border_color='dark grey', border_width=1)
  36.             blocks.append(block)
  37.             block_x=block_x + block.width
  38.         block_x=play.screen.left+75
  39.         block_y=block.y-block.height
  40.  
  41.  
  42.     platform.show()
  43.     lose.hide()
  44.     win.hide()
  45.  
  46. @play.repeat_forever
  47. async def game():
  48.     if play.key_is_pressed('a'):
  49.         platform.x -= 20
  50.     if play.key_is_pressed('d'):
  51.         platform.x += 20
  52.  
  53.     for b in blocks:
  54.         if b.is_touching(ball):      
  55.             ball.physics.x_speed = -1 * ball.physics.x_speed
  56.             ball.physics.y_speed = -1 * ball.physics.y_speed
  57.             b.hide()
  58.             blocks.remove(b)
  59.  
  60.     if ball.y <= platform.y:
  61.         lose.show()
  62.     if len(blocks) == 0:
  63.         win.show()
  64.    
  65.     await play.timer(seconds=1/frames)
  66.  
  67. play.start_program()
Add Comment
Please, Sign In to add comment