def main(): print "pydance", VERSION, "<*****@*****.**> - irc.freenode.net/#pyddr" if mainconfig["usepsyco"]: try: import psyco print _("Psyco optimizing compiler found. Using psyco.full().") psyco.full() except ImportError: print _("W: Psyco optimizing compiler not found.") # default settings for play_and_quit. mode = "SINGLE" difficulty = "BASIC" test_file = None for opt, arg in getopt(sys.argv[1:], "hvf:d:m:", ["help", "version", "filename=", "difficulty=", "mode="])[0]: if opt in ["-h", _("--help")]: print_help() elif opt in ["-v", _("--version")]: print_version() elif opt in ["-f", _("--filename")]: test_file = arg elif opt in ["-m", _("--mode")]: mode = arg elif opt in ["-d", _("--difficulty")]: difficulty = arg if test_file: play_and_quit(test_file, mode, difficulty) song_list = {} course_list = [] for dir in mainconfig["songdir"].split(os.pathsep): print _("Searching for songs in"), dir song_list.update(util.find_songs(dir, ['*.dance', '*.sm', '*.dwi', '*/song.*'])) for dir in mainconfig["coursedir"].split(os.pathsep): print _("Searching for courses in"), dir course_list.extend(util.find(dir, ['*.crs'])) screen = set_display_mode() pygame.display.set_caption("pydance " + VERSION) pygame.mouse.set_visible(False) try: if os.path.exists("/usr/share/pixmaps/pydance.png"): icon = pygame.image.load("/usr/share/pixmaps/pydance.png") else: icon = pygame.image.load(os.path.join(pydance_path, "icon.png")) pygame.display.set_icon(icon) except: pass music.load(os.path.join(sound_path, "menu.ogg")) music.play(4, 0.0) songs = load_files(screen, song_list.values(), _("songs"), SongItem, (False,)) # Construct the song and record dictionaries for courses. These are # necessary because courses identify songs by title and mix, rather # than filename. The recordkey dictionary is needed for player's # picks courses. song_dict = {} record_dict = {} for song in songs: mix = song.info["mix"].lower() title = song.info["title"].lower() if song.info["subtitle"]: title += " " + song.info["subtitle"].lower() if not song_dict.has_key(mix): song_dict[mix] = {} song_dict[mix][title] = song record_dict[song.info["recordkey"]] = song crs = load_files(screen, [course_list], _("courses"), courses.CourseFile, (song_dict, record_dict)) crs.extend(courses.make_players(song_dict, record_dict)) records.verify(record_dict) # Let the GC clean these up if it needs to. song_list = None course_list = None record_dict = None pad.empty() if len(songs) < 1: ErrorMessage(screen, (_("You don't have any songs or step files. Check out " "http://icculus.org/pyddr/get.php#songs " "and download some free ones. " "If you already have some, make sure they're in ")) + mainconfig["songdir"]) raise SystemExit(_("You don't have any songs. Check http://icculus.org/pyddr/get.php#songs .")) menudriver.do(screen, (songs, crs, screen)) # Clean up shit. music.stop() pygame.quit() mainconfig.write(os.path.join(rc_path, "pydance.cfg")) # FIXME -- is this option a good idea? if mainconfig["saveinput"]: pad.write(os.path.join(rc_path, "input.cfg")) records.write()
def main(): print "pydance", VERSION, "<*****@*****.**> - irc.freenode.net/#pyddr" if mainconfig["usepsyco"]: try: import psyco print _("Psyco optimizing compiler found. Using psyco.full().") psyco.full() except ImportError: print _("W: Psyco optimizing compiler not found.") # default settings for play_and_quit. mode = "SINGLE" difficulty = "BASIC" test_file = None for opt, arg in getopt( sys.argv[1:], "hvf:d:m:", ["help", "version", "filename=", "difficulty=", "mode="])[0]: if opt in ["-h", _("--help")]: print_help() elif opt in ["-v", _("--version")]: print_version() elif opt in ["-f", _("--filename")]: test_file = arg elif opt in ["-m", _("--mode")]: mode = arg elif opt in ["-d", _("--difficulty")]: difficulty = arg if test_file: play_and_quit(test_file, mode, difficulty) song_list = [] course_list = [] for dir in mainconfig["songdir"].split(os.pathsep): print _("Searching for songs in"), dir song_list.extend( util.find(dir, ['*.dance', '*.dwi', '*.sm', '*/song.*'])) for dir in mainconfig["coursedir"].split(os.pathsep): print _("Searching for courses in"), dir course_list.extend(util.find(dir, ['*.crs'])) screen = set_display_mode() pygame.display.set_caption("pydance " + VERSION) pygame.mouse.set_visible(False) try: if os.path.exists("/usr/share/pixmaps/pydance.png"): icon = pygame.image.load("/usr/share/pixmaps/pydance.png") else: icon = pygame.image.load(os.path.join(pydance_path, "icon.png")) pygame.display.set_icon(icon) except: pass music.load(os.path.join(sound_path, "menu.ogg")) music.play(4, 0.0) songs = load_files(screen, song_list, _("songs"), SongItem, (False, )) # Construct the song and record dictionaries for courses. These are # necessary because courses identify songs by title and mix, rather # than filename. The recordkey dictionary is needed for player's # picks courses. song_dict = {} record_dict = {} for song in songs: mix = song.info["mix"].lower() title = song.info["title"].lower() if song.info["subtitle"]: title += " " + song.info["subtitle"].lower() if not song_dict.has_key(mix): song_dict[mix] = {} song_dict[mix][title] = song record_dict[song.info["recordkey"]] = song crs = load_files(screen, course_list, _("courses"), courses.CourseFile, (song_dict, record_dict)) crs.extend(courses.make_players(song_dict, record_dict)) records.verify(record_dict) # Let the GC clean these up if it needs to. song_list = None course_list = None record_dict = None pad.empty() if len(songs) < 1: ErrorMessage(screen, (_("You don't have any songs or step files. Check out " "http://icculus.org/pyddr/get.php#songs " "and download some free ones. " "If you already have some, make sure they're in ")) + mainconfig["songdir"]) raise SystemExit( _("You don't have any songs. Check http://icculus.org/pyddr/get.php#songs ." )) menudriver.do(screen, (songs, crs, screen)) # Clean up shit. music.stop() pygame.quit() mainconfig.write(os.path.join(rc_path, "pydance.cfg")) # FIXME -- is this option a good idea? if mainconfig["saveinput"]: pad.write(os.path.join(rc_path, "input.cfg")) records.write()
def dance(screen, song, players, prevscr, ready_go, game): songFailed = False # text group, e.g. judgings and combos tgroup = RenderUpdates() # lyric display group lgroup = RenderUpdates() background = pygame.Surface([640, 480]) if song.movie != None: backmovie = BGMovie(song.movie) else: backmovie = None background.fill(colors.BLACK) screen.fill(colors.BLACK) if ready_go: ready_go_time = min(100, *[plr.ready for plr in players]) tgroup.add(ReadyGoSprite(ready_go_time)) if mainconfig['showbackground'] > 0: if backmovie is None: bgkludge = pygame.image.load(song.background).convert() bgkrect = bgkludge.get_rect() if (bgkrect.size[0] == 320) and (bgkrect.size[1] == 240): bgkludge = pygame.transform.scale2x(bgkludge) else: bgkludge = pygame.transform.scale(bgkludge, [640, 480]) bgkludge.set_alpha(mainconfig['bgbrightness'], RLEACCEL) q = mainconfig['bgbrightness'] / 256.0 # FIXME for i in range(0, 101, 5): p = i / 100.0 prevscr.set_alpha(256 * (1 - p) * q, RLEACCEL) screen.fill(colors.BLACK) screen.blit(prevscr, [0, 0]) screen.blit(bgkludge, [0, 0]) pygame.display.update() pygame.time.delay(1) background.blit(bgkludge, [0, 0]) else: pygame.display.update() else: pygame.display.update() if mainconfig["strobe"]: tgroup.add(Blinky(song.bpm)) if mainconfig["fpsdisplay"]: fpstext = FPSDisp() timewatch = TimeDisp() tgroup.add([fpstext, timewatch]) else: fpstext = None if mainconfig['showlyrics']: lgroup.add(song.lyricdisplay.channels()) fontfn, basesize = FontTheme.Dance_title_artist songtext = fontfx.zztext(song.title, 480, 12, basesize, fontfn) grptext = fontfx.zztext(song.artist, 160, 12, basesize, fontfn) songtext.zin() grptext.zin() tgroup.add([songtext, grptext]) song.init() if song.crapout != 0: error.ErrorMessage(screen, _("The audio file for this song ") + song.filename + _(" could not be found.")) return False # The player didn't fail. if mainconfig['assist']: music.set_volume(0.6) else: music.set_volume(1.0) song.play() for plr in players: plr.start_song() autofail = mainconfig['autofail'] screenshot = False pad.empty() while True: if autofail: songFailed = True for plr in players: if not plr.lifebar.gameover: songFailed = False break if songFailed: song.kill() for plr in players: plr.get_next_events(song) if song.is_over(): break else: curtime = music.get_pos()/1000.0 key = [] ev = pad.poll() for i in range(len(players)): if (pad.states[(i, pad.START)] and pad.states[(i, pad.SELECT)]): ev = (0, pad.QUIT) break else: pass while ev[1] != pad.PASS: if ev[1] == pad.QUIT: for p in players: p.escaped = True break elif ev[1] == pad.SCREENSHOT: screenshot = True elif ev[1] == pad.LEFT: key.append((ev[0], 'l')) elif ev[1] == pad.DOWNLEFT: key.append((ev[0], 'w')) elif ev[1] == pad.UPLEFT: key.append((ev[0], 'k')) elif ev[1] == pad.RIGHT: key.append((ev[0], 'r')) elif ev[1] == pad.UPRIGHT: key.append((ev[0], 'z')) elif ev[1] == pad.DOWNRIGHT: key.append((ev[0], 'g')) elif ev[1] == pad.UP: key.append((ev[0], 'u')) elif ev[1] == pad.DOWN: key.append((ev[0], 'd')) elif ev[1] == pad.CENTER: key.append((ev[0], 'c')) ev = pad.poll() if ev[1] == pad.QUIT: return False for ev in key: if game.double: pid = ev[0] / 2 else: pid = ev[0] if pid < len(players): players[pid].handle_key(ev, curtime) rectlist = [] if backmovie: backmovie.update(curtime) if backmovie.changed or (fpstext.fps() > 30): backmovie.resetchange() screen.blit(backmovie.image, [0, 0]) for plr in players: rectlist.extend(plr.game_loop(curtime, screen)) lgroup.update(curtime) tgroup.update(curtime) rectlist.extend(tgroup.draw(screen)) rectlist.extend(lgroup.draw(screen)) if backmovie is None: pygame.display.update(rectlist) else: pygame.display.update() if screenshot: fn = os.path.join(rc_path, "screenshot.bmp") print _("Saving a screenshot to"), fn pygame.image.save(screen, fn) screenshot = False if backmovie is None: lgroup.clear(screen, background) tgroup.clear(screen, background) for plr in players: plr.clear_sprites(screen, background) if ((curtime > players[0].length - 1) and (songtext.zdir == 0) and (songtext.zoom > 0)): songtext.zout() grptext.zout() if fpstext: print _("Average FPS for this song was %d.") % fpstext.fps() return songFailed
def dance(screen, song, players, prevscr, ready_go, game): songFailed = False # text group, e.g. judgings and combos tgroup = RenderUpdates() # lyric display group lgroup = RenderUpdates() background = pygame.Surface([640, 480]) if song.movie != None: backmovie = BGMovie(song.movie) else: backmovie = None background.fill(colors.BLACK) screen.fill(colors.BLACK) if ready_go: ready_go_time = min(100, *[plr.ready for plr in players]) tgroup.add(ReadyGoSprite(ready_go_time)) if mainconfig['showbackground'] > 0: if backmovie is None: bgkludge = pygame.image.load(song.background).convert() bgkrect = bgkludge.get_rect() if (bgkrect.size[0] == 320) and (bgkrect.size[1] == 240): bgkludge = pygame.transform.scale2x(bgkludge) else: bgkludge = pygame.transform.scale(bgkludge, [640, 480]) bgkludge.set_alpha(mainconfig['bgbrightness'], RLEACCEL) q = mainconfig['bgbrightness'] / 256.0 # FIXME for i in range(0, 101, 5): p = i / 100.0 prevscr.set_alpha(256 * (1 - p) * q, RLEACCEL) screen.fill(colors.BLACK) screen.blit(prevscr, [0, 0]) screen.blit(bgkludge, [0, 0]) pygame.display.update() pygame.time.delay(1) background.blit(bgkludge, [0, 0]) else: pygame.display.update() else: pygame.display.update() if mainconfig["strobe"]: tgroup.add(Blinky(song.bpm)) if mainconfig["fpsdisplay"]: fpstext = FPSDisp() timewatch = TimeDisp() tgroup.add([fpstext, timewatch]) else: fpstext = None if mainconfig['showlyrics']: lgroup.add(song.lyricdisplay.channels()) fontfn, basesize = FontTheme.Dance_title_artist songtext = fontfx.zztext(song.title, 480, 12, basesize, fontfn) grptext = fontfx.zztext(song.artist, 160, 12, basesize, fontfn) songtext.zin() grptext.zin() tgroup.add([songtext, grptext]) song.init() if song.crapout != 0: error.ErrorMessage( screen, _("The audio file for this song ") + song.filename + _(" could not be found.")) return False # The player didn't fail. if mainconfig['assist']: music.set_volume(0.6) else: music.set_volume(1.0) song.play() for plr in players: plr.start_song() autofail = mainconfig['autofail'] screenshot = False pad.empty() while True: if autofail: songFailed = True for plr in players: if not plr.lifebar.gameover: songFailed = False break if songFailed: song.kill() for plr in players: plr.get_next_events(song) if song.is_over(): break else: curtime = music.get_pos() / 1000.0 key = [] ev = pad.poll() for i in range(len(players)): if (pad.states[(i, pad.START)] and pad.states[(i, pad.SELECT)]): ev = (0, pad.QUIT) break else: pass while ev[1] != pad.PASS: if ev[1] == pad.QUIT: for p in players: p.escaped = True break elif ev[1] == pad.SCREENSHOT: screenshot = True elif ev[1] == pad.LEFT: key.append((ev[0], 'l')) elif ev[1] == pad.DOWNLEFT: key.append((ev[0], 'w')) elif ev[1] == pad.UPLEFT: key.append((ev[0], 'k')) elif ev[1] == pad.RIGHT: key.append((ev[0], 'r')) elif ev[1] == pad.UPRIGHT: key.append((ev[0], 'z')) elif ev[1] == pad.DOWNRIGHT: key.append((ev[0], 'g')) elif ev[1] == pad.UP: key.append((ev[0], 'u')) elif ev[1] == pad.DOWN: key.append((ev[0], 'd')) elif ev[1] == pad.CENTER: key.append((ev[0], 'c')) ev = pad.poll() if ev[1] == pad.QUIT: return False for ev in key: if game.double: pid = ev[0] / 2 else: pid = ev[0] if pid < len(players): players[pid].handle_key(ev, curtime) rectlist = [] if backmovie: backmovie.update(curtime) if backmovie.changed or (fpstext.fps() > 30): backmovie.resetchange() screen.blit(backmovie.image, [0, 0]) for plr in players: rectlist.extend(plr.game_loop(curtime, screen)) lgroup.update(curtime) tgroup.update(curtime) rectlist.extend(tgroup.draw(screen)) rectlist.extend(lgroup.draw(screen)) if backmovie is None: pygame.display.update(rectlist) else: pygame.display.update() if screenshot: fn = os.path.join(rc_path, "screenshot.bmp") print _("Saving a screenshot to"), fn pygame.image.save(screen, fn) screenshot = False if backmovie is None: lgroup.clear(screen, background) tgroup.clear(screen, background) for plr in players: plr.clear_sprites(screen, background) if ((curtime > players[0].length - 1) and (songtext.zdir == 0) and (songtext.zoom > 0)): songtext.zout() grptext.zout() if fpstext: print _("Average FPS for this song was %d.") % fpstext.fps() return songFailed