def death(): FADE_TO_WHITE[0] += 0.5 _time_since_death = FADE_TO_WHITE[0] _time_alive = numbers.clip( (LIFE[SETTINGS["controlling"]]["time_of_death"] - LIFE[SETTINGS["controlling"]]["created"]) / float(WORLD_INFO["length_of_day"]), 0.1, 9999, ) _string = "You die." _sub_string = LIFE[SETTINGS["controlling"]]["cause_of_death"] _col = int(round(255 * numbers.clip((_time_since_death / 100.0) - random.uniform(0, 0.15), 0, 1))) if _time_alive == 1: _sub_sub_string = "Lived 1 day" else: _sub_sub_string = "Lived %s days" % (_time_alive) gfx.fade_to_black(1) gfx.blit_string( (MAP_WINDOW_SIZE[0] / 2) - len(_string) / 2, MAP_WINDOW_SIZE[1] / 2, _string, "map", fore_color=tcod.Color(_col, 0, 0), back_color=tcod.Color(0, 0, 0), ) gfx.blit_string( (MAP_WINDOW_SIZE[0] / 2) - len(_sub_string) / 2, (MAP_WINDOW_SIZE[1] / 2) + 2, _sub_string, "map", fore_color=tcod.Color(int(round(_col * 0.75)), int(round(_col * 0.75)), int(round(_col * 0.75))), back_color=tcod.Color(0, 0, 0), ) gfx.blit_string( (MAP_WINDOW_SIZE[0] / 2) - len(_sub_sub_string) / 2, (MAP_WINDOW_SIZE[1] / 2) + 4, _sub_sub_string, "map", fore_color=tcod.Color(int(round(_col * 0.75)), int(round(_col * 0.75)), int(round(_col * 0.75))), back_color=tcod.Color(0, 0, 0), ) if _time_since_death >= 350: worldgen.save_world() worldgen.reset_world() gfx.clear_scene() SETTINGS["running"] = 1 return False return True
def death(): _player = LIFE[SETTINGS['controlling']] maps.reset_lights() FADE_TO_WHITE[0] += .5 _time_since_death = FADE_TO_WHITE[0] _time_alive = round(numbers.clip((_player['time_of_death']-_player['created'])/float(WORLD_INFO['length_of_day']), 0.1, 9999), 2) _string = 'You die.' _sub_string = _player['cause_of_death'] _col = int(round(255*numbers.clip((_time_since_death/100.0)-random.uniform(0, 0.15), 0, 1))) if _time_alive == 1: _sub_sub_string = 'Lived 1 day' else: if _time_alive < 1: _sub_sub_string = 'Lived less than a day' else: _sub_sub_string = 'Lived %0.1f days' % (_time_alive) gfx.fade_to_black(1) gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_string)/2, MAP_WINDOW_SIZE[1]/2, _string, 'map', fore_color=tcod.Color(_col, 0, 0), back_color=tcod.Color(0, 0, 0)) gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_sub_string)/2, (MAP_WINDOW_SIZE[1]/2)+2, _sub_string, 'map', fore_color=tcod.Color(int(round(_col*.75)), int(round(_col*.75)), int(round(_col*.75))), back_color=tcod.Color(0, 0, 0)) gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_sub_sub_string)/2, (MAP_WINDOW_SIZE[1]/2)+4, _sub_sub_string, 'map', fore_color=tcod.Color(int(round(_col*.75)), int(round(_col*.75)), int(round(_col*.75))), back_color=tcod.Color(0, 0, 0)) if _time_since_death>=350: worldgen.save_world() worldgen.reset_world() gfx.clear_scene() SETTINGS['running'] = 1 return False return True
def main(): _player_moved = False _refresh_map = False get_input() handle_input() if not LIFE[SETTINGS['controlling']]['dead']: if LIFE[SETTINGS['controlling']]['asleep']: gfx.fade_to_black(255) gfx.start_of_frame() gfx.end_of_frame() while LIFE[SETTINGS['controlling']]['asleep']: _played_moved = True _refresh_map = True gfx.title(LIFE[SETTINGS['controlling']]['asleep_reason']) logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True) if LIFE[SETTINGS['controlling']]['dead']: break else: _player_moved = True if _refresh_map: gfx.refresh_view('map') if not _player_moved: if logic.tick_all_objects(ignore_tickrate=True): _player_moved = True draw_targeting() move_camera(SETTINGS['camera_track']) #TODO: Deselect so we can get rid of this call if SELECTED_TILES[0]: gfx.refresh_view('map') if not SETTINGS['last_camera_pos'] == SETTINGS['camera_track'][:]: if EVENTS or MENUS: _visible_chunks = sight.scan_surroundings( LIFE[SETTINGS['following']], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS['following']], 'visible_chunks', value=_visible_chunks) _cam_x = numbers.clip( LIFE[SETTINGS['following']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2) _cam_y = numbers.clip( LIFE[SETTINGS['following']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2) else: _visible_chunks = sight.scan_surroundings( LIFE[SETTINGS['controlling']], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS['controlling']], 'visible_chunks', value=_visible_chunks) SETTINGS['last_camera_pos'] = SETTINGS['camera_track'][:] _cam_x = numbers.clip( LIFE[SETTINGS['controlling']]['pos'][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2) _cam_y = numbers.clip( LIFE[SETTINGS['controlling']]['pos'][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2) maps.render_lights() if '--worldmap' in sys.argv: render_map.render_map(WORLD_INFO['map'], force_camera_pos=(_cam_x, _cam_y, 2)) else: render_map.render_map(WORLD_INFO['map'], los=LIFE[SETTINGS['controlling']]['fov'], force_camera_pos=(_cam_x, _cam_y, 2)) items.draw_items() life.draw_life() if LIFE[SETTINGS['controlling']]['dead'] and not EVENTS: if not death(): return False if SETTINGS['draw life info'] and SETTINGS['following']: life.draw_life_info() gfx.draw_message_box() menus.align_menus() menus.draw_menus() gfx.draw_status_line() gfx.draw_console() gfx.start_of_frame() gfx.end_of_frame() if '--fps' in sys.argv: print tcod.sys_get_fps() if (SETTINGS['recording'] and _player_moved and not EVENTS and not MENUS) or '--worldmap' in sys.argv: gfx.screenshot() if '--worldmap' in sys.argv: SETTINGS['running'] = False
def death(): _player = LIFE[SETTINGS['controlling']] maps.reset_lights() FADE_TO_WHITE[0] += .5 _time_since_death = FADE_TO_WHITE[0] _time_alive = round( numbers.clip((_player['time_of_death'] - _player['created']) / float(WORLD_INFO['length_of_day']), 0.1, 9999), 2) _string = 'You die.' _sub_string = _player['cause_of_death'] _col = int( round(255 * numbers.clip( (_time_since_death / 100.0) - random.uniform(0, 0.15), 0, 1))) if _time_alive == 1: _sub_sub_string = 'Lived 1 day' else: if _time_alive < 1: _sub_sub_string = 'Lived less than a day' else: _sub_sub_string = 'Lived %0.1f days' % (_time_alive) gfx.fade_to_black(1) gfx.blit_string((MAP_WINDOW_SIZE[0] / 2) - len(_string) / 2, MAP_WINDOW_SIZE[1] / 2, _string, 'map', fore_color=tcod.Color(_col, 0, 0), back_color=tcod.Color(0, 0, 0)) gfx.blit_string((MAP_WINDOW_SIZE[0] / 2) - len(_sub_string) / 2, (MAP_WINDOW_SIZE[1] / 2) + 2, _sub_string, 'map', fore_color=tcod.Color(int(round(_col * .75)), int(round(_col * .75)), int(round(_col * .75))), back_color=tcod.Color(0, 0, 0)) gfx.blit_string((MAP_WINDOW_SIZE[0] / 2) - len(_sub_sub_string) / 2, (MAP_WINDOW_SIZE[1] / 2) + 4, _sub_sub_string, 'map', fore_color=tcod.Color(int(round(_col * .75)), int(round(_col * .75)), int(round(_col * .75))), back_color=tcod.Color(0, 0, 0)) if _time_since_death >= 350: worldgen.save_world() worldgen.reset_world() gfx.clear_scene() SETTINGS['running'] = 1 return False return True
def main(): _player_moved = False _refresh_map = False get_input() handle_input() if not LIFE[SETTINGS["controlling"]]["dead"]: if LIFE[SETTINGS["controlling"]]["asleep"]: gfx.fade_to_black(255) gfx.start_of_frame() gfx.end_of_frame() while LIFE[SETTINGS["controlling"]]["asleep"]: _played_moved = True _refresh_map = True gfx.title(LIFE[SETTINGS["controlling"]]["asleep_reason"]) logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True) if LIFE[SETTINGS["controlling"]]["dead"]: break else: _player_moved = True if _refresh_map: gfx.refresh_view("map") if not _player_moved: logic.tick_all_objects(ignore_tickrate=True) draw_targeting() move_camera(SETTINGS["camera_track"]) # TODO: Deselect so we can get rid of this call if SELECTED_TILES[0]: gfx.refresh_view("map") if not SETTINGS["last_camera_pos"] == SETTINGS["camera_track"][:]: if EVENTS or MENUS: _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["following"]], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS["following"]], "visible_chunks", value=_visible_chunks) _cam_x = numbers.clip( LIFE[SETTINGS["following"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2 ) _cam_y = numbers.clip( LIFE[SETTINGS["following"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2 ) else: _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["controlling"]], judge=False, get_chunks=True) alife.brain.flag(LIFE[SETTINGS["controlling"]], "visible_chunks", value=_visible_chunks) SETTINGS["last_camera_pos"] = SETTINGS["camera_track"][:] _cam_x = numbers.clip( LIFE[SETTINGS["controlling"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2 ) _cam_y = numbers.clip( LIFE[SETTINGS["controlling"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2 ) maps.render_lights() if "--worldmap" in sys.argv: render_map.render_map(WORLD_INFO["map"], force_camera_pos=(_cam_x, _cam_y, 2)) else: render_map.render_map( WORLD_INFO["map"], los=LIFE[SETTINGS["controlling"]]["fov"], force_camera_pos=(_cam_x, _cam_y, 2) ) items.draw_items() life.draw_life() if LIFE[SETTINGS["controlling"]]["dead"] and not EVENTS: if not death(): return False if SETTINGS["draw life info"] and SETTINGS["following"]: life.draw_life_info() gfx.draw_message_box() menus.align_menus() menus.draw_menus() gfx.draw_status_line() gfx.draw_console() gfx.start_of_frame() gfx.end_of_frame() if "--fps" in sys.argv: print tcod.sys_get_fps() if (SETTINGS["recording"] and logic.can_tick()) or "--worldmap" in sys.argv: gfx.screenshot() if "--worldmap" in sys.argv: SETTINGS["running"] = False