def chk_slp2(st): del_t= f_t - clock.tick(FPS) if del_t > 0: print(f"Lag : {-del_t}s") return tk_time() - st, del_t else: return tk_time() - st, 0
def EndGame(): end_buttons = [] button((225, 275), (50, 50), rgb.BLACK, name="Choose Level", group=end_buttons) button((525, 275), (50, 50), rgb.BLACK, name="Quit", group=end_buttons) gt = 0 lag = 0 st = tk_time() pygame.mixer.music.stop() while True: events = pygame.event.get() chk_exit(events) screen.fill(rgb.WHITE) if chk_buttons(events, end_buttons) == "Quit": pygame.quit() exit() elif chk_buttons(events, end_buttons) == "Choose Level": SelectStage() draw_buttons(end_buttons) pygame.display.flip() st, lag, gt = chk_slp(st, gt)
def SelectStage(st= tk_time(), lag= 0, gt= 0): buttons_stages= [] button( (50, HEIGHT-50), (50, 50), rgb.BLACK, name= "Back", group= buttons_stages) button( (50, HEIGHT-150), (50, 50), rgb.BLACK, name= "Quit", group= buttons_stages) for i,file in enumerate(files): button( (375, i*100 + 150), (50, 50), rgb.BLACK, name= file, group= buttons_stages) while True: events= pygame.fastevent.get() chk_exit(events) screen.fill(rgb.WHITE) draw_buttons(group= buttons_stages) action= chk_buttons(events, group= buttons_stages) if action == None: pass elif action == "Back": MainMenu() elif action == "Quit": pygame.quit() exit() elif action in files: print(f"Playing {action}!") StartGame(action) pygame.display.flip() st, lag, gt= chk_slp(st, gt)
def chk_slp(st, gt): c_t = tk_time() del_t = f_t - c_t + st if del_t < 0: print(f"Lag : {-del_t}s") return c_t, -del_t, gt + f_t - del_t else: sleep(del_t) return c_t, 0, gt + f_t
def StartGame(file_name): notes = note_parser.parse(file_name) pygame.mixer.music.load(".\\tracks\\" + file_name) gt = 0 lag = 0 st = tk_time() pygame.mixer.music.play() while True: events = pygame.event.get() chk_exit(events) screen.fill((255, 255, 255)) draw_notes(notes, gt) pygame.display.flip() st, lag, gt = chk_slp(st, gt)
def MainMenu(st=tk_time(), lag=0, gt=0): button((375, 450), (50, 50), rgb.BLACK, name="Choose Level") button((375, 150), (50, 50), rgb.BLACK, name="Quit") while True: events = pygame.event.get() chk_exit(events) screen.fill(rgb.WHITE) if chk_buttons(events, buttons) == "Quit": pygame.quit() exit() elif chk_buttons(events, buttons) == "Choose Level": SelectStage() draw_buttons(buttons) pygame.display.flip() st, lag, gt = chk_slp(st, gt)
n_on.append(msg[1:]) else: n_off.append(msg[1:]) for i1 in n_on: for i2 in n_off: if i1[0] == i2[0] and i2[-1] > i1[-1]: i1.append(i2[-1]) break min_n = 999 max_n = 0 for i in n_on: pos = int(round((i[0] - 41) / 3.5)) * 100 + 25, HEIGHT size = 50, int(round((i[-1] - i[-2]) * 20)) time = i[-2] note(pos, size, time) st = tk_time() gt = 0 lag = 0 while True: events = pygame.event.get() print(len(events)) chk_exit(events) screen.fill((255, 255, 255)) draw_notes(notes) pygame.display.flip() st, lag, gt = chk_slp(st, gt)