Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # IMPORT THE MODULES
- import play
- from random import randint
- # SET THE STAGE, MAKE ALL THE SPRITES!
- play.set_backdrop('white')
- frames = 15
- lose = play.new_text(words='YOU LOSE', font_size=100, color='red')
- win = play.new_text(words='YOU WIN', font_size=100, color='yellow')
- platform = play.new_box(color='brown', y = -250, width = 150, height = 15)
- ball = play.new_circle(color='green', y = -160, radius = 15)
- # THIS IS A LIST FOR IF YOU'RE USING A FOR LOOP!
- blocks = []
- @play.when_program_starts
- def start():
- platform.start_physics(stable=True, obeys_gravity=False, bounciness=1, mass=1)
- ball.start_physics(stable=False, x_speed=30, y_speed=30, obeys_gravity=False, bounciness=1, mass=10)
- block_x = play.screen.left+75
- block_y = play.screen.top-50
- for i in range(2):
- while (block_x <= play.screen.right-30):
- block=play.new_box(color='grey', x=block_x, y=block_y, width=110, height=30, border_color='dark grey', border_width=1)
- blocks.append(block)
- block_x=block_x + block.width
- block_x=play.screen.left+75
- block_y=block.y-block.height
- platform.show()
- lose.hide()
- win.hide()
- @play.repeat_forever
- async def game():
- if play.key_is_pressed('a'):
- platform.x -= 20
- if play.key_is_pressed('d'):
- platform.x += 20
- for b in blocks:
- if b.is_touching(ball):
- ball.physics.x_speed = -1 * ball.physics.x_speed
- ball.physics.y_speed = -1 * ball.physics.y_speed
- b.hide()
- blocks.remove(b)
- if ball.y <= platform.y:
- lose.show()
- if len(blocks) == 0:
- win.show()
- await play.timer(seconds=1/frames)
- play.start_program()
Add Comment
Please, Sign In to add comment