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 load_world(world): global LOADED_CHUNKS gfx.title('Loading...') LOADED_CHUNKS = {} WORLD_INFO['id'] = world maps.load_map('map', base_dir=profiles.get_world_directory(world)) logging.debug('Loading life from disk...') with open( os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'life.dat'), 'r') as e: LIFE.update(json.loads(e.readline())) logging.debug('Loading items from disk...') with open( os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items.dat'), 'r') as e: ITEMS.update(json.loads(e.readline())) logging.debug('Loading historic items...') #with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items_history.dat'), 'r') as e: # ITEMS_HISTORY.update(json.loads(''.join(e.readlines()))) maps.reset_lights() SETTINGS['controlling'] = None SETTINGS['following'] = None for life in LIFE.values(): if life['dead']: continue if 'player' in life: SETTINGS['controlling'] = life['id'] lfe.focus_on(life) break lfe.load_all_life() items.reload_all_items() if SETTINGS['chunk_handler']: SETTINGS['chunk_handler'].check_chunks(force=True) #logging.debug('Rendering map slices...') #maps.render_map_slices() logging.info('World loaded.')
def load_world(world): global LOADED_CHUNKS gfx.title('Loading...') LOADED_CHUNKS = {} WORLD_INFO['id'] = world maps.load_map('map', base_dir=profiles.get_world_directory(world)) logging.debug('Loading life from disk...') with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'life.dat'), 'r') as e: LIFE.update(json.loads(e.readline())) logging.debug('Loading items from disk...') with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items.dat'), 'r') as e: ITEMS.update(json.loads(e.readline())) logging.debug('Loading historic items...') #with open(os.path.join(profiles.get_world_directory(WORLD_INFO['id']), 'items_history.dat'), 'r') as e: # ITEMS_HISTORY.update(json.loads(''.join(e.readlines()))) maps.reset_lights() SETTINGS['controlling'] = None SETTINGS['following'] = None for life in LIFE.values(): if life['dead']: continue if 'player' in life: SETTINGS['controlling'] = life['id'] lfe.focus_on(life) break lfe.load_all_life() items.reload_all_items() if SETTINGS['chunk_handler']: SETTINGS['chunk_handler'].check_chunks(force=True) #logging.debug('Rendering map slices...') #maps.render_map_slices() logging.info('World loaded.')
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