def run(): while True: screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("music choices") background = pygame.image.load("choose_music_background.jpg") screen.blit(background,(0,0)) mode1 = dropDowns("castle in the sky","My heart will go on", white,black,20, 100, 300, 100, screen) mode2 = dropDowns("A comme Amour", "Totoro", grey,black, 350, 100, 300, 100,screen) mode3 = dropDowns("Canon in D","Mariage D'Amou", black,white, 650, 100, 300, 100,screen) for mode in [mode1, mode2, mode3]: mode.drawChoices() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() for mode in [mode1, mode2, mode3]: index = -1 for rect in [mode.text1rect, mode.text2rect]: index += 1 if rect.collidepoint(pos): if index == 0: return musicPieces[mode.song1] else: return musicPieces[mode.song2] elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: import home home.run() pygame.display.update()
def run(): while True: screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("music choices") background = pygame.image.load("choose_music_background.jpg") screen.blit(background, (0, 0)) mode1 = dropDowns("castle in the sky", "My heart will go on", white, black, 20, 100, 300, 100, screen) mode2 = dropDowns("A comme Amour", "Totoro", grey, black, 350, 100, 300, 100, screen) mode3 = dropDowns("Canon in D", "Mariage D'Amou", black, white, 650, 100, 300, 100, screen) for mode in [mode1, mode2, mode3]: mode.drawChoices() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() for mode in [mode1, mode2, mode3]: index = -1 for rect in [mode.text1rect, mode.text2rect]: index += 1 if rect.collidepoint(pos): if index == 0: return musicPieces[mode.song1] else: return musicPieces[mode.song2] elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: import home home.run() pygame.display.update()
def run(): background = pygame.image.load("instruction_background.jpg") screen = pygame.display.set_mode((1000,600)) screen.blit(background, (0,0)) pygame.display.set_caption("Instructions") while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return home if event.key == pygame.K_ESCAPE: import home home.run() pygame.display.update()
def run(): screen = pygame.display.set_mode((1000, 1000)) pygame.display.set_caption("Staff") screen.fill(blue) placeNotes() makeStaff(screen) makeWhiteKeys() makeBlackKeys() drawReset(screen) drawNames(screen) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return to the home page if event.key == pygame.K_ESCAPE: import home home.run() elif event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() interval = 7 if data.resetrect.collidepoint(pos): reset() for note in all_notes: if note.rect.collidepoint(pos): index = note.Index() # change image of selected notes note.image = pygame.image.load("orange_note.png") for whitekey in all_whitekeys: if whitekey.Index() == index + interval: # change key images whitekey.image = pygame.image.load("orange_key.png") # use output event to make sound of the note midi_out.set_instrument(0) midi_out.note_on(notes[index], 127) time.sleep(0.5) midi_out.note_off(notes[index], 127) # draw all the notes all_notes.draw(screen) all_whitekeys.draw(screen) all_blackkeys.draw(screen) pygame.display.update()
def run(): pygame.init() pygame.midi.init() print "starting" pygame.display.set_caption("midi test") screen = pygame.display.set_mode((400, 300), RESIZABLE, 32) ########################################################## # Yifan Leng wrote the follwing part while True: if i.poll(): midi_events = i.read(10) if midi_events[0][0][2] != 0: timePoints.append(int(pygame.midi.time())-startTime) notes.append(int(midi_events[0][0][1])) # convert them into pygame events. if midi_events[0][0][2] == 0: # append the length of the note timePoints.append(int(pygame.midi.time())-startTime) noteLength = timePoints[-1]-timePoints[-2] # append the note value note = notes[-1] info = [timePoints[-2], noteLength, note] data.information.append(info) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return home if event.key == pygame.K_ESCAPE: import home home.run() else: # write a text file to store information content = str(data.information) write_file.writeFile("my_play.txt", content) if write_file.writeFile("my_play.txt", content): print "done recording" ################################################################# print "exit button clicked." i.close()
def run(): pygame.init() pygame.midi.init() print "starting" pygame.display.set_caption("midi test") screen = pygame.display.set_mode((400, 300), RESIZABLE, 32) ########################################################## # Yifan Leng wrote the follwing part while True: if i.poll(): midi_events = i.read(10) if midi_events[0][0][2] != 0: timePoints.append(int(pygame.midi.time()) - startTime) notes.append(int(midi_events[0][0][1])) # convert them into pygame events. if midi_events[0][0][2] == 0: # append the length of the note timePoints.append(int(pygame.midi.time()) - startTime) noteLength = timePoints[-1] - timePoints[-2] # append the note value note = notes[-1] info = [timePoints[-2], noteLength, note] data.information.append(info) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return home if event.key == pygame.K_ESCAPE: import home home.run() else: # write a text file to store information content = str(data.information) write_file.writeFile("my_play.txt", content) if write_file.writeFile("my_play.txt", content): print "done recording" ################################################################# print "exit button clicked." i.close()
def run(): try: information = read_file.readFile("my_play.txt") except: information = [] # set up the screen information = stringToList(information) screen = pygame.display.set_mode((1000, screenHeight)) pygame.display.set_caption("Game") makeWhiteKeys() makeBlackKeys() # set up fallingPieces all_keys = all_whitekeys + all_blackkeys generateNotes(information, screen) while True: drawFast(screen) drawSlow(screen) FPS = data.FPS clock.tick(FPS) makePieceFall(screen, all_keys) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return home if event.key == pygame.K_ESCAPE: import home home.run() elif event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if data.fastRect.collidepoint(pos): # fast FPS is 120 print "fast" data.FPS = 120 elif data.slowRect.collidepoint(pos): # set slow FPS to 20 print "slow" data.FPS = 20 pygame.display.update()
def run(): try: information = read_file.readFile("my_play.txt") except: information = [] # set up the screen information = stringToList(information) screen = pygame.display.set_mode((1000, screenHeight)) pygame.display.set_caption("Game") makeWhiteKeys() makeBlackKeys() # set up fallingPieces all_keys = all_whitekeys + all_blackkeys generateNotes(information, screen) while True: drawFast(screen) drawSlow(screen) FPS = data.FPS clock.tick(FPS) makePieceFall(screen,all_keys) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return home if event.key == pygame.K_ESCAPE: import home home.run() elif event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if data.fastRect.collidepoint(pos): # fast FPS is 120 print "fast" data.FPS = 120 elif data.slowRect.collidepoint(pos): # set slow FPS to 20 print "slow" data.FPS = 20 pygame.display.update()
import home home.run()
def home(self): self._window.destroy() import home home.run()
def run(song): # set up the screen screen = pygame.display.set_mode((screenWidth, screenHeight)) pygame.display.set_caption("Game") makeWhiteKeys() makeBlackKeys() # set up fallingPieces generateNotes(song,screen) all_keys = all_whitekeys + all_blackkeys while True: makePieceFall(screen, all_keys, data.fallingPieces) drawFast(screen) drawSlow(screen) drawKeys(screen) clock.tick(data.FPS) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: # press esc to return home if event.key == pygame.K_ESCAPE: import home home.run() elif event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() if data.fastRect.collidepoint(pos): # fast FPS is 120 data.FPS = 120 elif data.slowRect.collidepoint(pos): # set slow FPS to 10 data.FPS = 10 if i.poll(): midi_events = i.read(10) note = midi_events[0][0][1] noteStatus = midi_events[0][0][2] #midi_events[0][0][2] is zero when the key is realeased for key in all_keys: if key.note == note and noteStatus != 0 and key.note == data.fallingNote: # score increases as user hits the right key data.score += 1 # switch key images if key.note in whiteNotes: key.image = pygame.image.load("orange_key.png") else: key.image = pygame.image.load("orange_small_key.png") # red the keys if user hits the wrong key if key.note in blackNotes: key.image = pygame.image.load("red_key.png") else: key.image = pygame.image.load("red_big_key.png") # switch back the original key for key in all_keys: if key.note in whiteNotes: key.image = pygame.image.load("white_key.png") else: key.image = pygame.image.load("black_key.png") # render scores on the screen text = font.render(str(data.score), True, red, black) textrect = text.get_rect() textrect.centerx, textrect.centery = 20, 100 screen.blit(text, textrect) pygame.display.update()