def play_game(): player_action = None GameState.mouse = libtcod.Mouse() GameState.key = libtcod.Key() #main loop while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, GameState.key, GameState.mouse) #render the screen GUI.render_all() libtcod.console_flush() #level up if needed check_level_up() #erase all objects at their old locations, before they move for object in GameState.objects: object.clear() #handle keys and exit game if needed player_action = handle_keys() if player_action == 'exit': save_game() break #let monsters take their turn if GameState.game_state == 'playing' and player_action != 'didnt-take-turn': for object in objects: if object.ai: object.ai.take_turn()
def target_tile(max_range=None): #return the position of a tile left-clicked in player's FOV (optionally in a range), or (None,None) if right-clicked. while True: #render the screen. this erases the inventory and shows the names of objects under the mouse. libtcod.console_flush() libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, GameState.key, GameState.mouse) GUI.render_all() (x, y) = (GameState.mouse.cx, GameState.mouse.cy) if GameState.mouse.rbutton_pressed or GameState.key.vk == libtcod.KEY_ESCAPE: return (None, None) #cancel if the player right-clicked or pressed Escape #accept the target if the player clicked in FOV, and in case a range is specified, if it's in that range if (GameState.mouse.lbutton_pressed and libtcod.map_is_in_fov(GameState.fov_map, x, y) and (max_range is None or GameState.player.distance(x, y) <= max_range)): return (x, y)
def play_game(): player_action = None GameState.mouse = libtcod.Mouse() GameState.key = libtcod.Key() #main loop while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, GameState.key, GameState.mouse) #render the screen GUI.render_all() libtcod.console_flush() #level up if needed #TODO: Add level system #check_level_up() #erase all objects at their old locations, before they move for object in GameState.objects: object.clear() #handle keys and exit game if needed player_action = handle_keys() if player_action == 'exit': save_game() break #let monsters take their turn if GameState.game_state == 'playing' and player_action != 'didnt-take-turn': Obj = Object() for Obj in GameState.objects: if Obj.ai != None: #print "Beginning " + str(Obj) + " Move" if Obj.ai.currentState.action != None: Obj.ai.currentStateAction() #print str(Obj) + " Finished Action" Obj.ai.checkCurrentState()