Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import play
- import time
- import pygame
- from random import randint, choice
- pygame.mixer_music.load('hello.mp3')
- pygame.mixer_music.play()
- play.set_backdrop('light green')
- hello_txt=play.new_text(words='Catch 30 Eggs!', x=0, y=250)
- basket = play.new_image(image='basket.png', x=0, y=-200, size=20)
- result = play.new_text(words='', x=0, y=0, font_size=100)
- color = ["blue", "cyan", "white", "green", "purple", "orange"]
- score = play.new_text(words='0', x=300, y=250, color='yellow')
- score.num = 0
- lives = play.new_text(words='5', x=-300, y=250, color='red')
- lives.num = 5
- game_end = False
- @play.when_program_starts
- def start():
- basket.start_physics(stable=True, obeys_gravity=False)
- @play.repeat_forever
- async def movement():
- if play.key_is_pressed("a", "left"):
- basket.physics.x_speed = -100
- elif play.key_is_pressed("d", "right" ):
- basket.physics.x_speed = 100
- else:
- basket.physics.x_speed = 0
- async def spawn_egg():
- if not game_end:
- e = play.new_circle(color=choice(color), radius=10)
- e.go_to(randint(-300,300), 280)
- e.start_physics(bounciness=0)
- await play.timer(0.95)
- if e.is_touching(basket):
- score.num += 1
- score.words = str(score.num)
- else:
- lives.num -= 1
- lives.words = str(lives.num)
- e.color = "red"
- e.physics.bounciness = 0.3
- await play.timer(2)
- e.stop_physics()
- e.hide()
- @play.repeat_forever
- async def egg1():
- await spawn_egg()
- await play.timer(0.5)
- @play.repeat_forever
- async def egg2():
- await play.timer(0.5)
- await spawn_egg()
- @play.repeat_forever
- async def game_end_check():
- global game_end
- if score.num == 30:
- game_end = True
- result.words = "YOU WIN!!!"
- result.color = "green"
- elif lives.num == 0:
- game_end = True
- result.words = "YOU LOSE!!!"
- result.color = "red"
- if game_end:
- while True:
- result.show()
- await play.timer(0.5)
- result.hide()
- await play.timer(0.5)
- play.start_program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement