def new_game(): global player, alive, state, current_turn starting_items = ui.item_choice_menu() if starting_items is None: #player closed window during starting item dialog return terrain.map = mapgen.generate_map() (x, y) = terrain.map.player_start_pos terrain.map[x][y] = terrain.Floor() player = mob.Player((x, y)) for i in starting_items: player.get(i((0, 0))) terrain.map.init_fov_and_pathfinding() for i in range(50): randomly_spawn_enemies() update_objects() terrain.map.mobs.append(player) ui.clear_messages() render.init() compute_fov() render.draw_all_tiles() alive = True state = 'playing' current_turn = 1 ui.message('For this mission something something you need to get to the other side of this battlefield! Go 100 tiles to the right!')
def new_game(): global player, alive, state, current_turn starting_items = ui.item_choice_menu() if starting_items is None: # player closed window during starting item dialog return terrain.map = mapgen.generate_map() pos = terrain.map.player_start_pos player = mob.Player(pos) for i in starting_items: player.get(i((0, 0))) # terrain.map.init_fov_and_pathfinding() for i in range(50): update_objects() terrain.map.objects.append(player) ui.clear_messages() render.init() compute_fov() render.draw_all_tiles() alive = True state = 'playing' current_turn = 1 ui.message( 'Good job! You managed to sneak into the fortress of the dwarves and nabbed a priceless artifact while the dwarves were busy repelling a seige. Unfortunately, your escape route is now encased in battle! Can you navigate 200 tiles of mayhem?')
def load_game(): file = shelve.open('savegame', 'r') terrain.map = file['map'] terrain.map.init_fov_and_pathfinding() objindex = file['player_location'] game.player = terrain.map.mobs[objindex] game.alive = file['alive'] game.state = file['state'] game.current_turn = file['turn'] ui.messages = file['messages'] game.compute_fov() render.init() render.draw_all_tiles() print('game loaded') file.close()
def handle_keys(): # controls tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, ui.key, ui.mouse) key = get_key(ui.key) action = None # action that player takes, e.g. 'moved' or 'attacked' # movement keys if state == 'playing': if key in ui.direction_keys: (x, y) = ui.direction_keys[key] if DIAGONAL_MOVEMENT: action = player.move_or_attack(x, y) elif not (x != 0 and y != 0): action = player.move_or_attack(x, y) else: # player is trying to move diagonally # diagonal movement is disabled, though! return None elif key in ('.', tcod.KEY_KP5): action = 'pass' elif key in ('g', ','): # pick up an item # look for an item in player's tile for object in terrain.map.objects: if isinstance(object, item.Item): if (object.x, object.y) == (player.x, player.y): player.pick_up(object) break # inventory menu elif key == 'z': # use player's first item i = player.inventory[0] action = player.use(i) elif key == 'x': # use player's 2nd item i = player.inventory[1] action = player.use(i) elif key == 'c': # use player's 3rd item i = player.inventory[2] action = player.use(i) if key == tcod.KEY_ENTER and ui.key.lalt: # Alt+Enter: toggle fullscreen tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) elif key == tcod.KEY_ESCAPE: ui.handle_escape_menu() if action == 'moved': if player.x > terrain.map.width / 2: terrain.map.scroll() purge_dead_objects() # player moved, so we should recompute the fov map # terrain.map.init_fov_and_pathfinding() # terrain.map.update_fov_map() compute_fov() terrain.map.update_pathfinding() # also move render camera render.move_camera(player.x, player.y) # also update each tile on screen (different tiles will be lit) render.clear_all_tiles() render.draw_all_tiles() return action