def game(player, entities, game_map, message_log, game_state, console, panel, constants): # am_i_host = False # am_i_invader = False fov_recompute = True fov_map = initialize_fov(game_map) key = tcod.Key() mouse = tcod.Mouse() """ network = Network() network.connect() # Connect to the game server, adds player to the list of available hosts """ game_state = GameStates.PLAYERS_TURN previous_game_state = game_state # Previous state keeps track of game state previous to opening a menu (or similar) so we can return to that state targeting_spell = None # Beginning of game loop while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE_PRESS, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius']) render_all(console, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], mouse, game_state) tcod.console_flush() clear_all(console, entities) action = handle_generic_input(key, game_state) mouse_action = handle_mouse(mouse) # These actions come from the input.py file move = action.get('move') wait = action.get('wait') pickup = action.get('pickup') show_inventory = action.get('show_inventory') inventory_index = action.get('inventory_index') use_bonfire = action.get('use_bonfire') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') show_book_screen = action.get('show_book_screen') show_spell_list = action.get('show_spell_list') spell_list_index = action.get('spell_list_index') drop_inventory = action.get('drop_inventory') exit = action.get('exit') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') # Initialize an array to store actions the player takes player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move dest_x = player.x + dx dest_y = player.y + dy if not game_map.is_blocked(dest_x, dest_y): target = get_blocking_entities(entities, dest_x, dest_y) if target: attack_results = player.combat_entity.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) if player.isHasted(): if not game_map.is_blocked(dest_x + dx, dest_y + dy): player.move(dx, dy) fov_recompute = True game_state = GameStates.STATUS_EFFECT_RESOLUTIONS elif wait: game_state = GameStates.STATUS_EFFECT_RESOLUTIONS elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There are no items to pick up here.', tcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend(player.inventory.use(item)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click spell_result = player.book.cast_spell(targeting_spell, entities=entities, game_map=game_map, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(spell_result) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if show_spell_list: previous_game_state = game_state game_state = GameStates.SPELL_LIST if spell_list_index is not None and previous_game_state != GameStates.PLAYER_DEAD and spell_list_index < len( player.book.get_book_spell_list()): spell = player.book.spell_list[spell_list_index] if game_state == GameStates.SPELL_LIST: player_turn_results.extend( player.book.cast_spell(spell, entities=entities, fov_map=fov_map, game_map=game_map)) if use_bonfire and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.bonfire and entity.x == player.x and entity.y == player.y: player.score += 50 entities = game_map.descend(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True tcod.console_clear(console) break else: message_log.add_message( Message('There is no bonfire here to rest at.', tcod.yellow)) if level_up: player.score = player.score + (player.level.current_level * 200) if level_up == 'hp': player.combat_entity.base_max_hp += 20 elif level_up == 'mp': player.combat_entity.base_max_mana += 20 elif level_up == 'pow': player.combat_entity.base_power += 5 elif level_up == 'def': player.combat_entity.base_defense += 5 player.combat_entity.hp = player.combat_entity.max_hp # We set health and mana to max mana to 'refill' on level-up player.combat_entity.mana = player.combat_entity.max_mana game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if show_book_screen: previous_game_state = game_state game_state = GameStates.BOOK_SCREEN if exit: # Exiting from the inventory returns us to the previous game state if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN, GameStates.BOOK_SCREEN, GameStates.SPELL_LIST): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) # Otherwise game exits else: return True for player_turn_result in player_turn_results: message = player_turn_result.get( 'message' ) # message message comes whenever a player is notified of an event (various files) dead_entity = player_turn_result.get( 'dead') # dead message comes from combat_entity class item_added = player_turn_result.get( 'item_added') # item_added message comes from inventory class item_consumed = player_turn_result.get( 'consumed') # consumed message comes from the inventory class item_dropped = player_turn_result.get( 'item_dropped' ) # item_dropped message comes from the inventory class equip = player_turn_result.get( 'equip') # equip message comes from the inventory class # invade = player_turn_result.get('invade') # invade message comes from the item_functions class targeting = player_turn_result.get( 'targeting') # targeting message comes from book class targeting_cancelled = player_turn_result.get( 'targeting_cancelled' ) # targetting_cancelled message comes from engine spell_success = player_turn_result.get( 'spell_success' ) # spell_success comes from the spell functions class xp = player_turn_result.get('xp') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.STATUS_EFFECT_RESOLUTIONS if item_consumed: game_state = GameStates.STATUS_EFFECT_RESOLUTIONS if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_spell = targeting message_log.add_message(targeting_spell.targeting_message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targetting cancelled')) if spell_success: game_state = previous_game_state if item_dropped: entities.append(item_dropped) game_state = GameStates.STATUS_EFFECT_RESOLUTIONS if equip: equip_results = player.book.toggle_page(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') dequipped = equip_result.get('dequipped') if equipped: message_log.add_message( Message('You equipped the {0}'.format( equipped.name))) if dequipped: message_log.add_message( Message('You dequipped the {0}'.format( dequipped.name))) game_state = GameStates.STATUS_EFFECT_RESOLUTIONS """ if invade: msg = {'header': 'invade', 'data': None} response = network.send(msg) if(response['header'] == 'no_host_found'): message = Message('No available hosts found to invade.', tcod.dark_pink) message_log.add_message(message) game_state = GameStates.STATUS_EFFECT_RESOLUTIONS elif(response['header'] == 'invading_player'): message = Message('You are invading a new world...', tcod.dark_pink) am_i_invader = True message_log.add_message(message) if response['header'] == 'game_vars': old_entities = entities # we need to store the old game state entities = response['data'][0] # making invaders entities the hosts entities entities.append(response['data'][1]) # adding the host to the entity list for the invader entities.append(player) # adding the invader to his own entity list game_map = response['data'][2] # changing the invaders map to the hosts map print("WE GOT HERE") game_state = GameStates.INVADER elif(response['header'] == 'already_in_session'): message = Message('You are already in an invasion instance!', tcod.dark_pink) message_log.add_message(message) """ if xp: player.score += xp leveled_up = player.level.add_xp(xp) message_log.add_message( Message('You gain {0} experience points.'.format(xp))) if leveled_up: player.score = player.score + (player.level.current_level * 200) message_log.add_message( Message( 'You have leveled up! You reached level {0}'. format(player.level.current_level) + '!', tcod.pink)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if game_state == GameStates.STATUS_EFFECT_RESOLUTIONS: for entity in entities: if entity.combat_entity: status_effect_results = entity.combat_entity.apply_status_effects( ) for status_effect_result in status_effect_results: message_log.add_message( status_effect_result.get('message')) if game_map.tiles[entity.x][entity.y].trap: if game_map.tiles[entity.x][ entity.y].trap.caster != entity: trap_results = game_map.tiles[entity.x][ entity.y].trap.function( game_map.tiles[entity.x][ entity.y].trap.function_kwargs, entity) for trap_result in trap_results: message = trap_result.get('message') dead_entity = trap_result.get('dead') xp = trap_result.get('xp') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player( dead_entity) else: message = kill_monster(dead_entity) if xp: leveled_up = player.level.add_xp(xp) player.score += xp message_log.add_message( Message( 'You gain {0} experience points.'. format(xp))) if leveled_up: message_log.add_message( Message( 'You have leveled up! You reached level {0}' .format( player.level.current_level) + '!', tcod.pink)) previous_game_state = game_state game_state = GameStates.LEVEL_UP game_map.tiles[entity.x][entity.y].trap = None # We check if the player has been invaded and if so get the game ready to send to the invader. """ if am_i_host == False and am_i_invader == False: am_i_host = check_invasion(network) if am_i_host == True: player.set_name('Host') message = Message('You are being invaded!!', tcod.light_crimson) message_log.add_message(message) game_state = GameStates.INVASION_HOST else: game_state = GameStates.ENEMY_TURN """ game_state = GameStates.ENEMY_TURN # This portion needs implementation, game state changes upon your game being invaded or you invading another game. # Need to load the correct map (hosts), entities, etc, on both screens. """ if game_state == GameStates.INVASION_HOST: print("inside client invasion host") game_vars = (entities, player, game_map) msg = {'header': 'host_sending_vars', 'data': 'test'} print("pre object send") response = network.send(msg) print("post object send") print(response) game_state = GameStates.ENEMY_TURN if game_state == GameStates.INVADER: game_state = GameStates.ENEMY_TURN """ if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants): fov_recompute = True key = libtcod.Key() mouse = libtcod.Mouse() fov_map = initialize_fov(game_map) previous_game_state = game_state targeting_item = None while not libtcod.console_is_window_closed(): if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants["fov_radius"], constants["fov_light_walls"], constants["fov_algorithm"]) libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants["screen_width"], constants["screen_height"], constants["bar_width"], constants["panel_height"], constants["panel_y"], mouse, constants["colors"], game_state) libtcod.console_flush() clear_all(con, entities) fov_recompute = False action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get("move") wait = action.get("wait") pickup = action.get("pickup") show_inventory = action.get("show_inventory") drop_inventory = action.get("drop_inventory") inventory_index = action.get("inventory_index") show_char_screen = action.get("show_character_screen") take_stairs = action.get("take_stairs") level_up = action.get("level_up") exit = action.get("exit") fullscreen = action.get("fullscreen") left_click = mouse_action.get("left_click") right_click = mouse_action.get("right_click") player_turn_results = [] if wait: game_state = GameStates.ENEMY_TURN if level_up: if level_up == "hp": player.fighter.base_max_hp += 20 player.fighter.hp += 20 elif level_up == "str": player.fighter.base_power += 1 elif level_up == "dex": player.fighter.base_defense += 1 game_state = previous_game_state if show_char_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message( Message("There are no stairs here.", libtcod.yellow)) if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): destination_x = player.x + dx destination_y = player.y + dy target = player.get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: fov_recompute = True player.move(dx, dy) game_state = GameStates.ENEMY_TURN if pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message("Tehre is nothing here to pick up.", libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({"targeting_cancelled": True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({"targeting_cancelled": True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get("message") dead_entity = player_turn_result.get("dead") item_added = player_turn_result.get("item_added") item_consumed = player_turn_result.get("consumed") item_dropped = player_turn_result.get("item_dropped") equip = player_turn_result.get("equip") targeting = player_turn_result.get("targeting") targeting_cancelled = player_turn_result.get("targeting_cancelled") xp = player_turn_result.get("xp") if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get("equipped") dequipped = equip_result.get("dequipped") if equipped: message_log.add_message( Message("You equipped the {}".format( equipped.name))) if dequipped: message_log.add_message( Message("You dequipped the {}".format( dequipped.name))) game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message("Targeting cancelled")) if xp: leveled_up = player.level.add_xp(xp) message_log.add_message( Message("You gain {} experience points.".format(xp), libtcod.white)) if leveled_up: message_log.add_message( Message( "You battle skills grow stronger! You reached level {}." .format(player.level.current_level), libtcod.yellow)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get("message") dead_entity = enemy_turn_result.get("dead") if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants): fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN previous_game_state = game_state targeting_item = None while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius'], constants['fov_light_walls'], constants['fov_algorithm']) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], mouse, constants['colors'], game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') wait = action.get('wait') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') exit = action.get('exit') fullscreen = action.get('fullscreen') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN elif wait: game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message( Message('There are no stairs here.', libtcod.yellow)) if level_up: if level_up == 'hp': player.fighter.base_max_hp += 20 player.fighter.hp += 20 elif level_up == 'str': player.fighter.base_power += 1 elif level_up == 'def': player.fighter.base_defense += 1 game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') equip = player_turn_result.get('equip') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') xp = player_turn_result.get('xp') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') dequipped = equip_result.get('dequipped') if equipped: message_log.add_message( Message('You equipped the {0}'.format( equipped.name))) if dequipped: message_log.add_message( Message('You dequipped the {0}'.format( dequipped.name))) game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targeting cancelled')) if xp: leveled_up = player.level.add_xp(xp) message_log.add_message( Message('You gain {0} experience points.'.format(xp))) if leveled_up: message_log.add_message( Message( 'Your battle skills grow stronger! You reached level {0}' .format(player.level.current_level) + '!', libtcod.yellow)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 room_max_size = 10 room_min_size = 4 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 colors = { 'dark_wall': tcod.Color(0, 0, 100), 'dark_ground': tcod.Color(50, 50, 150), 'light_wall': tcod.Color(130, 110, 50), 'light_ground': tcod.Color(200, 180, 50) } fighter_component = Fighter(hp=30, defense=2, power=5) player = Entity(0, 0, '@', tcod.white, 'Player', blocks=True, fighter=fighter_component) entities = [player] tcod.console_set_custom_font( '.\\assets\\fonts\\arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) tcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', fullscreen=False) con = tcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room) fov_recompute = True fov_map = initialize_fov(game_map) key = tcod.Key() mouse = tcod.Mouse() game_state = GameStates.PLAYERS_TURN while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, entities, game_map, fov_map, fov_recompute, screen_width, screen_height, colors) fov_recompute = False tcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') msg = action.get('msg') if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entites_at_location( entities, destination_x, destination_y) if target: player.fighter.attack(target) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN print('Enemy Turn!') if exit: print('Thanks for playing!') return True if fullscreen: tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: entity.ai.take_turn(player, fov_map, game_map, entities) game_state = GameStates.PLAYERS_TURN print('Player Turn!') if msg: tcod.console_print(con, 1, 1, ' ') tcod.console_print(con, 1, 1, msg) print('window was closed')
def main(): #basic screen setup screen_width = 80 screen_height = 45 map_w = 60 map_h = 40 map_console_w = 60 map_console_h = 40 #tcod events setup key = tcod.Key() mouse = tcod.Mouse() #create player and put player in entities array player = ec.Entity(4, 2, drawval.CHARS["person"], 15, 0, 10, 10, cx.Faction.Ally, cx.DrawOrder.PLAYER, True, "You") entities = [player] player_state = 1 #player is alive player_gold = 0 player_floor = 1 # get and shuffle trap chars. 4 for floor tiles, and 4 for map glyphs G_TEMP_CHARS = drawval.TRAP_CHARS shuffle(G_TEMP_CHARS) G_TRAP_CHARS = G_TEMP_CHARS[0:4] G_GLYPH_CHARS = G_TEMP_CHARS[4:8] for x in range(0, len(G_GLYPH_CHARS)): G_GLYPH_CHARS[x] += 64 #create new level map level_map, paper_map = new_level(map_w, map_h, entities, G_TRAP_CHARS, G_GLYPH_CHARS) tcod.console_set_custom_font( cx.FONT_FILE[cx.SETTINGS[1]["sel"]], tcod.FONT_TYPE_GRAYSCALE | tcod.FONT_LAYOUT_ASCII_INROW, 32, 16) main_console = tcod.console_init_root(screen_width, screen_height, "D@N ROGUE", False, 3, "F", True) map_console = tcod.console.Console(map_console_w, map_console_h, "F", None) #menu_console = tcod.console.Console(30, 19, "F", None) message_console = tcod.console.Console( map_console.width, main_console.height - map_console.height) status_console = tcod.console.Console( main_console.width - map_console.width, main_console.height, "F", None) status_console.print(status_console.width // 2, 1, "The Unreliable\nCartographer", drawval.COLORS[15], drawval.COLORS[0], tcod.BKGND_DEFAULT, tcod.CENTER) re.legend_print(status_console, G_GLYPH_CHARS, 1, 4) messages = [] for x in range(0, message_console.height): messages.append("") welcome_message = "Welcome to *The Unreliable Cartographer.* This is a game about exploring ancient ruins to find an ancient artifact with a map of increasingly dubious accuracy and dodging traps along the way. Controls are on the left panel. We hope you like it!" re.messageprint(message_console, welcome_message, messages) #menu.menu_print(menu_console) #re.console_borders(menu_console,0,0,menu_console.width-1,menu_console.height-1) fg_sh = 15 bg_sh = 0 fov = player.fov(level_map, entities) #re.console_borders(map_console,0,0,map_console.width-1,map_console.height-1) jump_trigger = False no_enemies = False quit_trigger = False new_floor = False fov = player.fov(level_map, entities) re.draw_paper_map(paper_map, map_console) while True: draw_loop(player, level_map, paper_map, map_console, main_console, message_console, status_console, entities, player_state) status_con(status_console, 2, status_console.height - 2, player_floor, player_gold) for event in tcod.event.wait(): if event.type == "KEYDOWN": action = key_input(event.sym) #pause = False move = action.get('move') exit = action.get('exit') pause = action.get('pause') jump = action.get('jump') controlchange = action.get('controlchange') if player_state == 1: if move: dx, dy = move if not jump_trigger: player.move(dx, dy, level_map, entities, map_console, message_console, messages) elif jump_trigger: for z in range(0, 2): if player.jump(dx, dy, level_map, entities, map_console, message_console, messages) == False: break else: draw_loop(player, level_map, paper_map, map_console, main_console, message_console, status_console, entities, player_state) sleep(0.0080) jump_trigger = False player.lastx = dx player.lasty = dy quit_trigger = False if jump: if not jump_trigger: re.messageprint( message_console, "Press [DIR] to jump 2 squares away in a direction, any other key to cancel.", messages) jump_trigger = True no_enemies = True elif jump_trigger: re.messageprint(message_console, "Jump cancelled.", messages) jump_trigger = False no_enemies = True quit_trigger = False player_gold = player.istrapped(level_map, entities, map_console, message_console, messages, player_gold) print(player_gold) if not no_enemies: for entity in entities: if entity.dispname == "Boulder": entity.move(entity.persistent_x, entity.persistent_y, level_map, entities, map_console, message_console, messages) for entity in entities: if entity.istrap and entity.trapstate > 0: entity.do_trap(level_map, paper_map, main_console, map_console, fov, message_console, messages, entities) if entity.dispname == "gold": entities.remove(entity) if entity.dispname == "stairs": new_floor = True if entity.dispname == "artifact": player_state = 0 elif no_enemies: no_enemies = False if level_map.t_[player.x][player.y].type == "pit": fov = player.fov(level_map, entities) for z in drawval.CHARS["person_fall"]: player.char = z draw_loop(player, level_map, paper_map, map_console, main_console, message_console, status_console, entities, player_state) player_state = 0 entities.remove(player) re.messageprint(message_console, "Oh, dear! You've fallen down a pit!", messages) if player.stats.hp < 1: player_state = 0 status_con(status_console, 2, status_console.height - 2, player_floor, player_gold) if exit: if quit_trigger == False: re.messageprint( message_console, "Quit? [ESC] for 'Yes' or anything else for 'no'.", messages) no_enemies = True quit_trigger = True elif quit_trigger: return True if controlchange: no_enemies = True cx.SETTINGS[0]["sel"] = (cx.SETTINGS[0]["sel"] + 1) % 3 re.legend_print(status_console, G_GLYPH_CHARS, 1, 4) quit_trigger = False re.messageprint( message_console, "Changed controls to " + cx.INPUT_SEL_NAME[cx.SETTINGS[0]["sel"]] + ".", messages) #if pause: # no_enemies = True # menu.menu(main_console,menu_console) elif event.type == "WINDOWCLOSE": return True if new_floor: temp_player = entities.pop entities.clear() level_map.t_.clear() paper_map.t_.clear() player = ec.Entity(4, 2, drawval.CHARS["person"], 15, 0, 10, 10, cx.Faction.Ally, cx.DrawOrder.PLAYER, True, "You") entities = [player] player_floor += 1 player.x = 4 player.y = 2 map_console.clear() level_map, paper_map = new_level(map_w, map_h, entities, G_TRAP_CHARS, G_GLYPH_CHARS, player_floor) new_floor = False re.draw_paper_map(paper_map, map_console) fov = player.fov(level_map, entities) status_con(status_console, 2, status_console.height - 2, player_floor, player_gold)
def play_game(self) -> bool: print("Running") self.game_state = GameStates.PLAYERS_TURN self.previous_game_state = GameStates.PLAYERS_TURN self.render.set_map(self.game_map, self.map_buffer) self.render.set_panel(self.panel_buffer, self.constants['panel_height'], self.constants['bar_width'], self.constants['panel_y']) self.render.set_message_log(self.message_log) self.targeting_item = None self.fov_radius = self.constants['fov_radius'] self.fov_map = initialize_fov(self.game_map) self.player_turn_results = [] fov_recompute = True key = tcod.Key() mouse = tcod.Mouse() while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) fov_recompute = self.recompute_fov(fov_recompute) self.render.render_all(self.entities, self.player, self.fov_map, mouse, self.game_state) action = handle_keys(key, self.game_state) mouse_action = handle_mouse(mouse) left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') fov_recompute |= self.change_light_radius(action) self.do_inventory(action) self.do_targeting(left_click, right_click) a_take_stairs = action.get('take_stairs') a_level_up = action.get('level_up') a_show_character_screen = action.get('show_character_screen') if a_show_character_screen: self.previous_game_state = self.game_state self.game_state = GameStates.CHARACTER_SCREEN a_exit = action.get('exit') if a_exit: should_quit = self.do_action_exit_current_screen() if should_quit: return True if a_take_stairs and self.game_state == GameStates.PLAYERS_TURN: fov_recompute = self.do_action_take_stairs(fov_recompute) if a_level_up: self.do_action_level_up(a_level_up) self.game_state = self.previous_game_state self.do_game_window_actions(action) fov_recompute = self.do_player_turn(action, fov_recompute) self.evaluate_messages() if self.game_state == GameStates.ENEMY_TURN: self.do_entities_actions()
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 room_max_size = 10 room_min_size = 6 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 colours = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } fighter_component = Fighter(hp=30, defense=2, power=5) player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component) entities = [player] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'PyRL', False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room) fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, entities, player, game_map, fov_map, fov_recompute, screen_width, screen_height, colours) libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') if message: print(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) print(message) if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: print(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) print(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def main(): screen_width = 80 screen_height = 50 bar_width = 20 panel_height = 7 panel_y = screen_height - panel_height message_x = bar_width + 2 message_width = screen_width - bar_width - 2 message_height = panel_height - 1 map_width = 80 map_height = 43 room_max_size = 30 room_min_size = 6 max_rooms = 30 fov_algorithm = 2 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 max_items_per_room = 2 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } til = Tile(False) fighter_component = Fighter(30, defense=2, power=5) player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR) entities = [player] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False) con = libtcod.console_new(screen_width, screen_height) panel = libtcod.console_new(screen_width, panel_height) map = GameMap(map_width, map_height) map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room) fov_recompute = True fov_map = initialize_fov(map) message_log = MessageLog(message_x, message_width, message_height) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value) render_all(con, panel, entities_in_render_order, player, map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN else: message_log.add_message(Message('stuck')) if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) if exit: return True for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.ENEMY_TURN: for entity in entities_in_render_order: if entity != player and entity.ai != None: enemy_turn_results = entity.ai.take_turn( fov_map, player, map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break game_state = GameStates.PLAYERS_TURN
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 colors = { "dark_wall": libtcod.Color(0, 0, 100), "dark_ground": libtcod.Color(50, 50, 150) } # Create the player and an npc using the Entity class player = Entity(int(screen_width / 2), int(screen_height / 2), "@", libtcod.purple) npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@", libtcod.green) entities = [npc, player] # Telling libtcod which file to use, second argument is file type libtcod.console_set_custom_font( "arial10x10.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # This is what creates the screen, sets the game name and specifies fullscreen boolean libtcod.console_init_root(screen_width, screen_height, "TBD", False) # Creating the console con = libtcod.console_new(screen_width, screen_height) #Initialize map game_map = GameMap(map_width, map_height) # Variables for holding keyboard/mouse input key = libtcod.Key() mouse = libtcod.Mouse() # Loops that continues until the game window is closed # Checks for key/mouse press # Specifies character colour, where to put them, what they'll be represented by # and the background. The 0 is the console we're drawing to. # console_flush() draws everything while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) render_all(con, entities, game_map, screen_width, screen_height, colors) libtcod.console_flush() clear_all(con, entities) # This calls the handle_keys function to determine what should be done # depending on which key was pressed. action = handle_keys(key) move = action.get("move") exit = action.get("exit") fullscreen = action.get("fullscreen") # takes the x/y move amounts and applies them to player's position if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150) } player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.peach) npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', libtcod.yellow) entities = [npc, player] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'Ringo\'s Vanilla Rogue', False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) key = libtcod.Key() mouse = libtcod.Mouse() #game loop while not libtcod.console_is_window_closed(): #check for input libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) #put entities in places render_all(con, entities, game_map, screen_width, screen_height, colors) #draw to the screen libtcod.console_flush() #clear it? clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def main(): # Defaults for screen screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 colors = { 'dark_wall': tcod.Color(0, 0, 100), 'dark_ground': tcod.Color(50, 50, 150) } player = Entity(int(screen_width / 2), int(screen_height / 2), '@', tcod.white) npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', tcod.white) entities = [npc, player] # Describes which font to use tcod.console_set_custom_font( 'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) # Renders initial screen tcod.console_init_root(screen_width, screen_height, 'TCOD Tutorial Revised', False) con = tcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) key = tcod.Key() mouse = tcod.Mouse() # Main game loop while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse) render_all(con, entities, game_map, screen_width, screen_height, colors) tcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') enable_exit = action.get('exit') enable_fullscreen = action.get('fullscreen') if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) if enable_exit: return True if enable_fullscreen: tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
def main(): # screen size in pixels screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 room_max_size = 10 room_min_size = 6 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } player = Entity(0, 0, "@", libtcod.white) entities = [player] # selecting a custom font through libtcod # using a picture of all the characters for the font libtcod.console_set_custom_font( "arial10x10.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # renders the actual window # boolean attribute is True if fullscreen libtcod.console_init_root( screen_width, screen_height, "roguelike tutorial", False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room) fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() # game loop while not libtcod.console_is_window_closed(): # event listener for mouse and keypad input libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, entities, game_map, fov_map, fov_recompute, screen_width, screen_height, colors) fov_recompute = False # this puts everything on the screen libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get("move") exit = action.get("exit") fullscreen = action.get("fullscreen") if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) fov_recompute = True # if the key is ESC... if exit: # exit window return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def main(): # defines screen size screen_width = 80 screen_height = 50 # place player in center player_x = int(screen_width / 2) player_y = int(screen_height / 2) # use font from file we're reading libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # create screen form width and height variable and title libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial', False) con = libtcod.console_new(screen_width, screen_height) # allow key board and mouse input # take key and mouse input from key = libtcod.Key() mouse = libtcod.Mouse() # game loop while not libtcod.console_is_window_closed(): # add color to @ symbol assigned to 0 # check for inputs libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) libtcod.console_set_default_foreground(con, libtcod.white) libtcod.console_put_char(con, player_x, player_y, '@', libtcod.BKGND_NONE) libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) # libtcod.console_set_default_foreground(0, libtcod.white) # console 0,x coord, y coord, and @ symbol, background none # libtcod.console_put_char(0,1,1,'@',libtcod.BKGND_NONE) #now modified with new coordinates # libtcod.console_put_char(0, player_x, player_y, '@', libtcod.BKGND_NONE) # present everything libtcod.console_flush() libtcod.console_put_char(con, player_x, player_y, ' ', libtcod.BKGND_NONE) # allow get out of program by pressing esc # key = libtcod.console_check_for_keypress() # grab from handle_key action = handle_keys(key) # if key for move move = action.get('move') # if key for exit get_out_exit = action.get('exit') # if key for fullscreen fullscreen = action.get('fullscreen') # if move is grabbed if move: # grab x and y coordinate dx, dy = move # and adjust player_x += dx player_y += dy # if key.vk == libtcod.KEY_ESCAPE: # new exit function if get_out_exit: return True # fullscreen if if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def main(): # console props screen_width = 80 screen_height = 50 # UI settings bar_width = 20 ui_panel_height = 7 ui_panel_y = screen_height - ui_panel_height ## Message system message_x = bar_width + 2 message_width = screen_width - bar_width - 2 message_height = ui_panel_height - 1 message_log = MessageLog(message_x, message_width, message_height) # map props map_width = 80 map_height = 43 room_max_size = 10 room_min_size = 6 max_rooms = 30 max_monsters_per_room = 3 max_items_per_room = 4 # FOV settings fov_algorithm = 0 fov_light_walls = True fov_radius = 10 fov_recompute = True # we don't need to recompute FOV everytime (wait, fight, use item) # Colors dictionary colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } # Entities setup player_fighter_comp = Fighter(30, 2, 5) player_inventory_comp = Inventory(12) player = Entity(0, 0, '@', libtcod.white, 'Player', True, RenderOrder.ACTOR, player_fighter_comp, inventory=player_inventory_comp) entities = [player] game_state = GameStates.PLAYERS_TURN previous_game_state = game_state # Consoles setup libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'First Shem RL. Thanks Tutorial', False) con = libtcod.console.Console(screen_width, screen_height) ui_panel = libtcod.console.Console(screen_width, ui_panel_height) # Gamemap setup game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, player, entities, max_monsters_per_room, max_items_per_room) fov_map = initialize_fov(game_map) # Input setup key = libtcod.Key() mouse = libtcod.Mouse() targeting_item = None # WARN Check tcod.event for QUIT events while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, entities, player, game_map, fov_map, fov_recompute, screen_width, screen_height, ui_panel, bar_width, ui_panel_height, ui_panel_y, message_log, mouse, game_state, colors) fov_recompute = False libtcod.console_flush() clear_all(con, entities) # Input handling action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') exit = action.get('exit') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') fullscreen = action.get('fullscreen') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') player_turn_results = [] # Movement handling if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move dest_x = player.x + dx dest_y = player.y + dy if not game_map.is_blocked(dest_x, dest_y): target = get_blocking_entities_at_location(entities, dest_x, dest_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN # Pickup handling elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message(Message('There is nothing here to pickup', libtcod.yellow)) # Menus display handling if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY # Items usage handling if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len(player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend(player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen) # Print turn results for p_t_result in player_turn_results: message = p_t_result.get('message') dead_entity = p_t_result.get('dead') item_added =p_t_result.get('item_added') item_consumed = p_t_result.get('item_consumed') item_dropped = p_t_result.get('item_dropped') targeting = p_t_result.get('targeting') targeting_cancelled = p_t_result.get('targeting_cancelled') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targeting cancelled')) if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN # ENEMIES TURN if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn(player, fov_map, game_map, entities) for e_t_result in enemy_turn_results: message = e_t_result.get('message') dead_entity = e_t_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def main(): # Tela # Largura largura_tela = 80 # Altura altura_tela = 50 # Mapa mapa_largura = 80 mapa_altura = 43 # Sala tamanho_max_sala = 10 tamanho_min_sala = 6 max_salas = 30 # Algoritimo para visao (Famoso Fog) visao_algoritimo = 0 visao_ilumina_parede = True area_visao = 3 # interface barra_largura = 20 painel_altura = 7 painel_y = altura_tela - painel_altura msg_x = barra_largura + 2 msg_alt = largura_tela - barra_largura - 2 msg_lar = painel_altura + 6 # Monstros monstros_por_sala = 3 # Cores cores = { 'parede_escura': libtcod.Color(0, 0, 100), 'chao_escuro': libtcod.Color(180, 180, 180), 'parede_iluminada': libtcod.Color(130, 110, 50), 'chao_iluminado': libtcod.Color(200, 180, 50) } # Jogador combatente = Combatente(hp=30, defesa=2, forca=5) player = Entidade(0, 0, '@', libtcod.white, 'Diego', bloqueia=True, combatente=combatente, ordem_desenho=OrdemDesenho.ATOR) # npc = Entidade(int(largura_tela / 2 - 5), int(altura_tela / 2), 'N', libtcod.yellow, 'SHOP', bloqueia=False) # Objetos do Mapa (NPC , Jogador, Monstros, Itens e etc ... ) entidades = [player] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(largura_tela, altura_tela, 'Dugeon Diego', False) console = libtcod.console_new(largura_tela, altura_tela) painel = libtcod.console_new(largura_tela, painel_altura) mapa_jogo = MapaJogo(mapa_largura, mapa_altura) # mapa_jogo.fazer_mapa_estatico() # Desenha a DG. mapa_jogo.fazer_mapa(max_salas, tamanho_min_sala, tamanho_max_sala, mapa_largura, mapa_altura, player, entidades, monstros_por_sala) recalcula_visao = True visao = inicializa_visao(mapa_jogo) msg_log = MensagemLog(msg_x, msg_lar, msg_alt) # cria variaveis para teclas e Mouse. key = libtcod.Key() mouse = libtcod.Mouse() estado_jogo = EstadoJogo.TURNO_JOGADOR # Com tudo pronto aqui começa o laço principal while not libtcod.console_is_window_closed(): # captura eventos libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if recalcula_visao: recalcular_visao(visao, player.x, player.y, area_visao, visao_ilumina_parede, visao_algoritimo) # desenhar desenhar_tudo(console, entidades, mapa_jogo, largura_tela, altura_tela, cores, visao, recalcula_visao, player, painel, barra_largura, largura_tela, painel_altura, painel_y, msg_log, mouse) recalcula_visao = False libtcod.console_flush() # limpar limpar_tudo(console, entidades) # Recebe um dicionario acao = captura_teclado(key) mover = acao.get('mover') sair = acao.get('sair') tela_cheia = acao.get('fullscreen') jogador_resultado = [] if mover and estado_jogo == EstadoJogo.TURNO_JOGADOR: dx, dy = mover destino_x = player.x + dx destino_y = player.y + dy if not mapa_jogo.is_bloqueado(destino_x, destino_y): alvo = obter_entidade_com_bloqueio_por_localizacao( entidades, destino_x, destino_y) if alvo: j_ataque_resultado = player.combatente.atacar(alvo) jogador_resultado.extend(j_ataque_resultado) else: player.mover(dx, dy) recalcula_visao = True estado_jogo = EstadoJogo.TURNO_INIMIGO if sair: return True if tela_cheia: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for resultado in jogador_resultado: msg = resultado.get('mensagem') morto = resultado.get('morto') if msg: msg_log.add_msg(msg) if morto: if morto == player: msg, estado_jogo = matar_jogador(morto) else: msg = kill_monster(morto) msg_log.add_msg(msg) if estado_jogo == EstadoJogo.TURNO_INIMIGO: for entidade in entidades: if entidade.ai: entidade.ai.acao_ai(player, visao, mapa_jogo, entidades) enimigo_resultado = entidade.ai.acao_ai( player, visao, mapa_jogo, entidades) for resultado in enimigo_resultado: msg = resultado.get('mensagem') morto = resultado.get('morto') if msg: msg_log.add_msg(msg) if morto: if morto == player: message, estado_jogo = matar_jogador(morto) else: message = kill_monster(morto) msg_log.add_msg(message) if estado_jogo == EstadoJogo.JOGADOR_MORTO: break if estado_jogo == EstadoJogo.JOGADOR_MORTO: break else: estado_jogo = EstadoJogo.TURNO_JOGADOR
def main(): screen_width = 80 screen_height = 50 bar_width = 20 panel_height = 7 panel_y = screen_height - panel_height message_x = bar_width + 2 message_width = screen_width - bar_width - 2 message_height = panel_height - 1 # Size of map map_width = 80 map_height = 43 # Variables for rooms room_max_size = 10 room_min_size = 6 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 max_items_per_room = 2 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 100), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } fighter_component = Fighter(hp=30, defense=2, power=5) inventory_component = Inventory(26) player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component) entities = [player] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False) con = libtcod.console_new(screen_width, screen_height) panel = libtcod.console_new(screen_width, panel_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room) fov_recompute = True fov_map = initialize_fov(game_map) message_log = MessageLog(message_x, message_width, message_height) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN previous_game_state = game_state while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) move = action.get('move') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') exit = action.get('exit') fullscreen = action.get('fullscreen') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: player.fighter.attack(target) attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): game_state == previous_game_state else: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill + player( dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def main(): # Screen size screen_width = 80 screen_height = 50 # HP Bar bar_width = 20 panel_height = 7 panel_y = screen_height - panel_height # Message log size message_x = bar_width + 2 message_width = screen_width - bar_width - 2 message_height = panel_height - 1 # Map and rooms map_width = 80 map_heigth = 43 room_max_size = 10 room_min_size = 6 max_rooms = 30 # FOV fov_algorithm = 0 fov_light_walls = True fov_radius = 10 # Monsters max_monsters_per_room = 3 # Color dictinoary colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } # Setup player and entities fighter_component = Fighter(hp=30, defense=2, power=5) player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component) entities = [player] # Setup libtcod console libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'RL-ONE', False) con = libtcod.console_new(screen_width, screen_height) # UI panel panel = libtcod.console_new(screen_width, panel_height) # Draw map game_map = GameMap(map_width, map_heigth) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_heigth, player, entities, max_monsters_per_room) # Recompute FOV boolean, this only happens when the player moves fov_recompute = True # Initialize FOV fov_map = initialize_fov(game_map) # Message log message_log = MessageLog(message_x, message_width, message_height) # Input controls key = libtcod.Key() mouse = libtcod.Mouse() # Game state game_state = GameStates.PLAYERS_TURN # Game loop while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') # Results list player_turn_results = [] # Players turn if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) # Enemies turn if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants, camera): fov_recompute = True fov_map = initalize_fov(game_map) camera.update(player) key = libtcod.Key() mouse = libtcod.Mouse() previous_game_state = game_state targeting_item = None while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius'], constants['fov_light_walls'], constants['fov_algorithm']) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], mouse, constants['colors'], game_state, camera) fov_recompute = False libtcod.console_flush() clear_all(con, entities, camera) action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') wait = action.get('wait') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') exit = action.get('exit') fullscreen = action.get('fullscreen') fullscreen_console = action.get('fullscreen_console') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') wheel_up = mouse_action.get('wheel_up') wheel_down = mouse_action.get('wheel_down') player_turn_results = [] if wheel_up: message_log.scroll_up() if wheel_down: message_log.scroll_down() if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) camera.update(player) fov_recompute = True game_state = GameStates.ENEMY_TURN elif wait: game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.usable and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message( 'You fumble around on the ground but find nothing.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initalize_fov(game_map) camera.update(player) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message( Message('There are no stairs here.', libtcod.yellow)) if level_up: if level_up == 'hp': player.fighter.base_max_hp += 20 # TODO: Consider putting these in constants player.fighter.hp += 20 elif level_up == 'str': player.fighter.base_power += 1 elif level_up == 'def': player.fighter.base_defense += 1 elif level_up == 'speed': player.fighter.base_speed -= 10 # game_state = previous_game_state # This is the only way I found that the level up book doesn't lock game_state = GameStates.PLAYERS_TURN # the game, hopefully it's fine but it may give an extra turn on lvl up if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if fullscreen_console: previous_game_state = game_state game_state = GameStates.FULLSCREEN_CONSOLE if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_map.dungeon_level == -1: # Testing arena case needs no save file return True elif game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN, GameStates.FULLSCREEN_CONSOLE): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') equip = player_turn_result.get('equip') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') xp = player_turn_result.get('xp') if message: message_log.add_message(message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targeting cancelled')) if xp: leveled_up = player.level.add_xp(xp) message_log.add_message(Message('You gain {0} xp.'.format(xp))) if leveled_up: message_log.add_message( Message( 'You have honed your skills to reach level {0}.'. format(player.level.current_level), libtcod.cyan)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message( targeting_item.usable.targeting_message) if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') unequipped = equip_result.get('unequipped') if equipped: message_log.add_message( Message('You equipped the {0}.'.format( equipped.name))) if unequipped: message_log.add_message( Message('You unequipped the {0}.'.format( unequipped.name))) game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: current_moves = entity.fighter.current_moves current_moves -= player.fighter.base_speed while (current_moves <= 0): enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player( dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break # Break game loop if game_state == GameStates.PLAYER_DEAD: break # Break game loop current_moves += entity.fighter.speed entity.fighter.current_moves = current_moves else: game_state = GameStates.PLAYERS_TURN
def main(): #----------------------------------------------------------------------------------------------- ################################################################################################ #----------------------------------------------------------------------------------------------- # CONFIG SCREENWIDTH = 80 SCREENHEIGHT = 50 MAPWIDTH = 80 MAPHEIGHT = 43 BARWIDTH = 20 PANELHEIGHT = 7 PANELY = SCREENHEIGHT - PANELHEIGHT MESSAGEX = BARWIDTH + 2 MESSAGEWIDTH = SCREENWIDTH - BARWIDTH - 2 MESSAGEHEIGHT = PANELHEIGHT - 2 ROOMMAX = 10 ROOMMIN = 6 NUMROOMSMAX = 30 FOVALGORITHM = 0 FOVLIGHTWALLS = True FOVRADIUS = 15 MAXMONSTERSPERROOM = 3 MAXITEMSPERROOM = 2 COLORS = { 'darkWall': tcod.Color(0,0,100), 'darkGround': tcod.Color(50,50,150), 'lightWall': tcod.Color(130,110,50), 'lightGround': tcod.Color(200,180,50) } #----------------------------------------------------------------------------------------------- ################################################################################################ #----------------------------------------------------------------------------------------------- # INITIALIZATION fighterComponent = Fighter(hp=30, defense=2, power=5) inventoryComponent = Inventory(26) player = Entity(0, 0, '@', tcod.white, 'Player', blocks=True, renderOrder=RenderOrder.ACTOR, fighter=fighterComponent, inventory=inventoryComponent) # Player Entity Object entities = [player] # Entity List #----------------------------------------------------------------------------------------------- # Initialize Font tcod.console_set_custom_font('arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) # Initialize Console Window tcod.console_init_root(SCREENWIDTH, SCREENHEIGHT, title = 'ASCII Roguelike', fullscreen = False) baseConsole = tcod.console_new(SCREENWIDTH, SCREENHEIGHT) # Base Console panel = tcod.console_new(SCREENWIDTH, PANELHEIGHT) #----------------------------------------------------------------------------------------------- MAP = GameMap(MAPWIDTH, MAPHEIGHT) # CREATE MAP MAP.makeMap(NUMROOMSMAX, ROOMMIN, ROOMMAX, MAPWIDTH, MAPHEIGHT, player, entities, MAXMONSTERSPERROOM, MAXITEMSPERROOM) fovRecompute = True # FOV Recomputing Boolean fovMap = initializeFOV(MAP) # Initialize FOV Map #----------------------------------------------------------------------------------------------- messageLog = MessageLog(MESSAGEX, MESSAGEWIDTH, MESSAGEHEIGHT) key = tcod.Key() # Store Keyboard Input mouse = tcod.Mouse() # Store Mouse Input gameState = GameStates.PLAYERTURN # Start On Player's Turn previousGameState = gameState #----------------------------------------------------------------------------------------------- ################################################################################################ #----------------------------------------------------------------------------------------------- # GAME LOOP while not tcod.console_is_window_closed(): tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) # Capture User Input #----------------------------------------------------------------------------------------------- if fovRecompute: # Recompute FOV Based on Player Position recomputeFOV(fovMap, player.x, player.y, FOVRADIUS, FOVLIGHTWALLS, FOVALGORITHM) # Render All Entities renderAll(baseConsole, panel, entities, player, MAP, fovMap, fovRecompute, messageLog, SCREENWIDTH, SCREENHEIGHT, BARWIDTH, PANELHEIGHT, PANELY, mouse, COLORS, gameState) fovRecompute = False # Turn Off FOV Recompute Until Player Move #----------------------------------------------------------------------------------------------- tcod.console_flush() # Update Console to Current State clearAll(baseConsole, entities) # Clear Entities #----------------------------------------------------------------------------------------------- action = handleKeys(key, gameState) # Get Key Press # Key Press Action move = action.get('move') # Movement pickup = action.get('pickup') # Pickup Object showInventory = action.get('showInventory') inventoryIndex = action.get('inventoryIndex') exit = action.get('exit') # Exit Boolean fullscreen = action.get('fullscreen') # Fullscreen Boolean playerTurnResults = [] # Initialize Player's Turn Results # Check for movement and players turn if move and gameState == GameStates.PLAYERTURN: dx,dy = move # Movement Deltas # Movement Destination destinationX = player.x + dx destinationY = player.y + dy # If map is not blocked: if not MAP.isBlocked(destinationX, destinationY): # Check for blocking entities target = getBlockingEntities(entities, destinationX, destinationY) if target: # player.fighter.attack(target) attackResults = player.fighter.attack(target) # Gather Attack Results playerTurnResults.extend(attackResults) # Add to Player Turn Results else: player.move(dx,dy) # Move Player By Delta fovRecompute = True gameState = GameStates.ENEMYTURN # Set To Enemy's Turn elif pickup and gameState == GameStates.PLAYERTURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickupResults = player.inventory.addItem(entity) playerTurnResults.extend(pickupResults) break else: messageLog.addMessage(Message('There is nothing to pick up.', tcod.yellow)) if showInventory: previousGameState = gameState gameState = GameStates.INVENTORY if inventoryIndex is not None and previousGameState != GameStates.PLAYERDEAD and inventoryIndex < len(player.inventory.items): item = player.inventory.items[inventoryIndex] playerTurnResults.extend(player.inventory.use(item)) if exit: # Exit Window if gameState == GameStates.INVENTORY: gameState = previousGameState else: return True if fullscreen: # Fullscreen tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) for playerTurnResult in playerTurnResults: message = playerTurnResult.get('message') deadEntity = playerTurnResult.get('dead') itemAdded = playerTurnResult.get('itemAdded') itemConsumed = playerTurnResult.get('consumed') if message: messageLog.addMessage(message) if deadEntity: if deadEntity == player: message, gameState = killPlayer(deadEntity) else: message = killMonster(deadEntity) messageLog.addMessage(message) if itemAdded: entities.remove(itemAdded) gameState = GameStates.ENEMYTURN if itemConsumed: gameState = GameStates.ENEMYTURN if gameState == GameStates.ENEMYTURN: for entity in entities: if entity.ai: # entity.ai.takeTurn(player, fovMap, MAP, entities) enemyTurnResults = entity.ai.takeTurn(player, fovMap, MAP, entities) for enemyTurnResult in enemyTurnResults: message = enemyTurnResult.get('message') deadEntity = enemyTurnResult.get('dead') if message: messageLog.addMessage(message) if deadEntity: if deadEntity == player: message, gameState = killPlayer(deadEntity) else: message = killMonster(deadEntity) messageLog.addMessage(message) if gameState == GameStates.PLAYERDEAD: break if gameState == GameStates.PLAYERDEAD: break else: gameState = GameStates.PLAYERTURN # Set To Player's Turn
def main(): screen_width = 80 screen_height = 50 map_width = screen_width map_height = screen_height - 5 room_max_size = 10 room_min_size = 6 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 500), } player = Entity(screen_width // 2, screen_height // 2, '@', libtcod.white, 'Player', blocks=True) entities = [player] libtcod.console_set_custom_font( 'dejavu10x10_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room) fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, entities, game_map, fov_map, fov_recompute, screen_width, screen_height, colors) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target: print( 'You kick the {} in the shins, much to its cansternation!' .format(target.name)) else: player.move(dx, dy) fov_recompute = True if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
fighter=fighter_component) objects = [player] inventory = [] fov_recompute = True game_state = 'playing' player_action = None panel = tcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) game_msgs = [] mouse = tcod.Mouse() key = tcod.Key() def get_names_under_mouse(): global mouse (x, y) = mouse.cx, mouse.cy names = [ obj.name for obj in objects if obj.x == x and obj.y == y and tcod.map_is_in_fov(fov_map, obj.x, obj.y) ] names = ','.join(names) return names.capitalize()
def main(): constants = get_constants() libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False) con = libtcod.console_new(constants['screen_width'], constants['screen_height']) panel = libtcod.console_new(constants['screen_width'], constants['panel_height']) player = None entities = [] game_map = None message_log = None game_state = None show_main_menu = True show_load_error_message = False main_menu_background_image = libtcod.image_load('menu_background.png') key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if show_main_menu: main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height']) if show_load_error_message: message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() action = handle_main_menu(key) new_game = action.get('new_game') load_saved_game = action.get('load_game') exit_game = action.get('exit') if show_load_error_message and (new_game or load_saved_game or exit_game): show_load_error_message = False elif new_game: player, entities, game_map, message_log, game_state = get_game_variables( constants) game_state = GameStates.PLAYERS_TURN show_main_menu = False elif load_saved_game: try: player, entities, game_map, message_log, game_state = load_game( ) show_main_menu = False except FileNotFoundError: show_load_error_message = True elif exit_game: break else: libtcod.console_clear(con) play_game(player, entities, game_map, message_log, game_state, con, panel, constants) show_main_menu = True
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 room_max_size = 10 room_min_size = 6 max_rooms = 30 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150) } player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white) npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', libtcod.yellow) entities = [player, npc] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'Roguelike Demo', False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player) key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) render_all(con, entities, game_map, screen_width, screen_height, colors) libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 room_max_size = 10 room_min_size = 6 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white) npc = Entity(int(screen_height / 2 - 5), int(screen_height / 2 - 5), '@', libtcod.yellow) entities = [npc, player] libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'THE GAME', False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player) fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, entities, game_map, fov_map, fov_recompute, screen_width, screen_height, colors) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move if not game_map.is_blocked(player.x + dx, player.y + dy): player.move(dx, dy) fov_recompute = True if exit: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants): fov_recompute = True fov_map = initialize_fov(game_map) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN previous_game_state = game_state targeting_item = None while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, constants['fov_radius'], constants['fov_light_walls'], constants['fov_algorithm']) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, constants['screen_width'], constants['screen_height'], constants['bar_width'], constants['panel_height'], constants['panel_y'], mouse, constants['colors'], game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') exit = action.get('exit') fullscreen = action.get('fullscreen') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target and target.z == player.z: player.push(target, entities, fov_map, game_map) else: player.move(dx, dy, fov_map) fov_recompute = True game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up.', libtcod.yellow)) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.ENEMY_TURN: player.depth += 10 if player.depth % 30 == 0: game_map.place_entities(0, entities, 2, 0) for entity in entities: if entity.name == 'Boulder': if entity.z < 0: entities.remove(entity) else: entity.z -= 1 elif entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) if entity.z > 0: guyintheway = get_blocking_entities_at_location( entities, entity.x, entity.y) if guyintheway: entity.x = entity.x + randint(-1, 1) entity.y = entity.y + randint(-1, 1) if entity.x == 0 and entity.y == 0: entity.x = entity.x + randint(-1, 1) entity.y = entity.y + randint(-1, 1) entity.z -= 1 target = get_blocking_entities_at_location( entities, entity.x, entity.y) if target: if not target == entity: if target.z == 0: entities.remove(target) else: target.z -= 1 for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: libtcod.console_clear(0) break else: game_state = GameStates.PLAYERS_TURN