Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import play
- import time
- from random import randint
- frames = 48
- score = 0
- finish = False
- # Setting up the screen
- hello_txt = play.new_text(words='Catch them all!', x=0, y=play.screen.height/2-30)
- hello_txt.color = (120, 120, 120)
- score_txt = play.new_text(words='0', x=play.screen.width/2-80, y=play.screen.height/2-30, color='gold')
- help_txt = play.new_text(words="Use 'q', 'a', 'e', 'd' keys", x=0, y=-play.screen.height/2+30)
- # Adding in your characters
- bunny = play.new_image(image='easter-bunny-1.png', x=0, y=20)
- bowl = play.new_image(image='bowl.png', x=100, y=80, size=40)
- # Making sure your eggs have 4 starting points
- egg_x = [400, -380]
- egg_y = [200, 50]
- eggs = []
- # Starts the time counter
- old_time=0
- # How to make a new egg
- def new_egg():
- egg = play.new_circle(
- color=(255, 212, 59),
- x=egg_x[randint(0, 1)],
- y=egg_y[randint(0, 1)],
- radius=12,
- border_color=(75, 139, 190),
- border_width=5
- )
- egg.start_physics(mass=1, friction=0.7)
- eggs.append(egg)
- # How to make the shelves
- def add_shelf(x, y, a):
- shelf = play.new_box(x=x, y=y, width=300, height=10, angle=a)
- shelf.color = (48, 105, 152)
- shelf.start_physics(can_move=False, mass=10, friction=1.0)
- # Setting up the time and shelves
- @play.when_program_starts
- def start():
- global old_time
- old_time = time.time()
- add_shelf(300, 150, 20)
- add_shelf(300, 0, 20)
- add_shelf(-300, 150, -20)
- add_shelf(-300, 0, -20)
- new_egg()
- # How to catch the eggs
- @play.repeat_forever
- async def game():
- global score, finish, old_time
- if play.key_is_pressed('e'):
- bowl.x = 100
- bowl.y = 80
- if play.key_is_pressed('d'):
- bowl.x = 100
- bowl.y = -70
- if play.key_is_pressed('q'):
- bowl.x = -100
- bowl.y = 80
- if play.key_is_pressed('a'):
- bowl.x = -100
- bowl.y = -70
- if time.time()-old_time > 3:
- new_egg()
- old_time = time.time()
- # WINNING/ LOSING CHECK
- for egg in eggs:
- if egg.y < -250:
- hello_txt.words = "That's all folks!"
- hello_txt.color = 'red'
- quit()
- if egg.is_touching(bowl):
- egg.hide()
- eggs.remove(egg)
- score = score + 1
- score_txt.words = score
- if score == 10:
- hello_txt.words = "You win!"
- hello_txt.color = 'yellow'
- await play.timer(seconds=1/frames)
- # Signal to start
- play.start_program()
- # Don't forget to run and check your code :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement