Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import play
- import pygame
- play.set_backdrop('light blue')
- text1 = play.new_text("Minecraft piano for fun!", x = -200, y = 250)
- text2 = play.new_text("Created in python!", x = -200, y = 200)
- text3 = play.new_text("Create your melody by pressing the keys!", x = 0, y = 150)
- piano = play.new_image("piano.png", x = 50, y = 225,size = 30)
- key_clear_melody = play.new_box(color='blue',border_color = 'gold', x = -200, y = -200, width = 200, height = 100)
- kcm = play.new_text(words='clear melody', x=-200, y=-200, font_size=45)
- key_play_melody = play.new_box(color='red', border_color = 'gold', x = 200, y = -200, width = 200, height = 100)
- kpm = play.new_text(words='play melody', x=200, y=-200, font_size=45)
- sound = pygame.mixer.Sound("clear_melody.wav")
- b_p = play.new_circle(x=-180, y=-125, radius=10)
- txt_p = play.new_text(words='piano', x=-145, y=-125, font_size=20)
- b_g = play.new_circle(color='blue', x=-80, y=-125, radius=10)
- txt_g = play.new_text(words='guitar', x=-45, y=-125, font_size=20)
- b_v = play.new_circle(color='blue', x=20, y=-125, radius=10)
- txt_v = play.new_text(words='violin', x=55, y=-125, font_size=20)
- b_f = play.new_circle(color='blue', x=120, y=-125, radius=10)
- txt_f = play.new_text(words='flute', x=155, y=-125, font_size=20)
- @play.repeat_forever
- def switch ():
- for i in instrument_buttons:
- if i.is_clicked:
- global instrument
- instrument = instrument_buttons.index (i)
- for j in instrument_buttons:
- j.color = "blue"
- i.color = "black"
- instrument = 0
- instrument_buttons = [b_p, b_g, b_v, b_f]
- keys = []
- sounds = [[],[],[],[]]
- for i in range(8):
- key_x = -350 + i * 100
- key = play.new_box(color='white', border_color = 'black', border_width=3, x =key_x, y = 0, width=80, height=200)
- keys.append(key)
- p_sound = pygame.mixer.Sound ("pia" + str(i+1) +'.ogg')
- g_sound = pygame.mixer.Sound ("git" + str(i+1) +'.ogg')
- v_sound = pygame.mixer. Sound ("vio" + str(i+1) +'.ogg')
- f_sound = pygame.mixer.Sound ("fl" + str(i+1) +'.ogg')
- sounds [0].append (p_sound)
- sounds [1].append (g_sound)
- sounds [2].append (v_sound)
- sounds [3].append (f_sound)
- buttons = ["a", "s", "d", "f", "g", "h", "j", "k"]
- image = []
- melody = []
- i1 = play.new_image("creeper.png", x = -350, y = 0,size = 20)
- c = play.new_text("C", x = -350, y = -75)
- image.append(i1)
- i2= play.new_image("skeleton.png", x = -250, y = 0,size = 15)
- image.append(i2)
- d = play.new_text("D", x = -250, y = -75)
- i3= play.new_image("enderman.png", x = -150, y = 0,size = 25)
- image.append(i3)
- E = play.new_text("E", x = -150, y = -75)
- i4= play.new_image("steve1.png", x = -50, y = 0,size = 45)
- image.append(i4)
- F = play.new_text("F", x = -50, y = -75)
- i5= play.new_image("chicken1.png", x = 50, y = 0,size = 20)
- image.append(i5)
- G = play.new_text("G", x = 50, y = -75)
- i6= play.new_image("spider.png", x = 150, y = 0,size = 8)
- image.append(i6)
- A = play.new_text("A", x = 150, y = -75)
- i7= play.new_image("wither.png", x = 250, y = 0,size = 33)
- B = play.new_text("B", x = 250, y = -75)
- image.append(i7)
- i8= play.new_image("dragon.png", x = 350, y = 0,size = 13)
- C = play.new_text("C", x = 350, y = -75)
- image.append(i8)
- # You had this twice, one without a 'clear' command
- # This is why the recorded sound won't go away!
- @key_clear_melody.when_clicked
- def play_sound():
- melody.clear()
- sound.play()
- @play.when_program_starts
- def start():
- pygame.mixer_music.load("hello.mp3")
- pygame.mixer_music.play()
- @key_play_melody.when_clicked
- async def play_m():
- for i in range(len(melody)):
- await play.timer(seconds=0.5)
- sounds[instrument][melody[i]].play()
- @play.repeat_forever
- async def play_instrument():
- for i in range(len(keys)):
- if keys[i].is_clicked or play.key_is_pressed(buttons[i]):
- keys[i].color = 'light grey'
- sounds[instrument][i].play()
- await play.timer(seconds=0.3)
- keys[i].color = 'white' #alternately, "white"
- melody.append(i)
- play.start_program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement