def handle_keys(): global exit_game global fov_recompute player_dx = 0 player_dy = 0 #movement keys if tcod.console_is_key_pressed(tcod.KEY_UP): player_dy = -1 fov_recompute = True elif tcod.console_is_key_pressed(tcod.KEY_DOWN): player_dy = 1 fov_recompute = True elif tcod.console_is_key_pressed(tcod.KEY_LEFT): player_dx = -1 fov_recompute = True elif tcod.console_is_key_pressed(tcod.KEY_RIGHT): player_dx = 1 fov_recompute = True # move the player player.move(player_dx, player_dy) # check for specific key presses combos, etc key = tcod.console_check_for_keypress() if key.vk == tcod.KEY_ENTER and key.lalt: # Alt-enter toggle fullscreen tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) elif key.vk == tcod.KEY_ESCAPE: exit_game = True
def main(): screen_width = 80 screen_height = 50 player_x = int(screen_width / 2) player_y = int(screen_height / 2) 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) key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_put_char(0, player_x, player_y, '@', libtcod.BKGND_NONE) libtcod.console_flush() key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: return True
def handle_keys(): global fov_recompute key = libtcod.console_check_for_keypress() # real-time # key = libtcod.console_wait_for_keypress(True) #turn-based if key.vk == libtcod.KEY_ENTER and key.lalt: # Alt+Enter: toggle fullscreen libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) elif key.vk == libtcod.KEY_ESCAPE: return True # exit game # movement keys if libtcod.console_is_key_pressed(libtcod.KEY_UP): player.move(0, -1) fov_recompute = True elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): player.move(0, 1) fov_recompute = True elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): player.move(-1, 0) fov_recompute = True elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): player.move(1, 0) fov_recompute = True
def get_key_event(turn_based=None): if turn_based: key = tcod.console_wait_for_keypress(True) else: # Real-time game play; don't wait for a player's key stroke key = tcod.console_check_for_keypress() return key
def main(): screen_width = 5 screen_height = 35 libtcod.console_set_custom_font('alienraid12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(screen_width, screen_height, 'Alien Raid Icon Tracker', False) while not libtcod.console_is_window_closed(): libtcod.console_set_default_foreground(0, libtcod.white) #COLUMN 1 libtcod.console_put_char(0, 1, 1, 196, libtcod.BKGND_NONE) #KANGA libtcod.console_put_char(0, 1, 3, 179, libtcod.BKGND_NONE) #JOEY libtcod.console_put_char(0, 1, 5, 191, libtcod.BKGND_NONE) #DINGO libtcod.console_put_char(0, 1, 7, 218, libtcod.BKGND_NONE) #TENTACLAWS/TENTACRUEL libtcod.console_put_char(0, 1, 9, 217, libtcod.BKGND_NONE) #ENERGY SHIELD libtcod.console_put_char(0, 1, 11, 192, libtcod.BKGND_NONE) #ALUMINITE TENTASLEEVE libtcod.console_put_char(0, 1, 13, 180, libtcod.BKGND_NONE) #CORPSE libtcod.console_put_char(0, 1, 15, 195, libtcod.BKGND_NONE) #MED KIT libtcod.console_put_char(0, 1, 17, 193, libtcod.BKGND_NONE) #GRENADE libtcod.console_put_char(0, 1, 19, 194, libtcod.BKGND_NONE) #SHOCK CHARGE libtcod.console_put_char(0, 1, 21, 197, libtcod.BKGND_NONE) #ALIEN libtcod.console_put_char(0, 1, 23, 205, libtcod.BKGND_NONE) #TRAIL libtcod.console_put_char(0, 1, 25, 186, libtcod.BKGND_NONE) #GOANNA libtcod.console_put_char(0, 1, 27, 187, libtcod.BKGND_NONE) #RAY GUN libtcod.console_put_char(0, 1, 29, 201, libtcod.BKGND_NONE) #KILLER BEE libtcod.console_put_char(0, 1, 31, 188, libtcod.BKGND_NONE) #WHIPPY WILLOW TWIG libtcod.console_put_char(0, 1, 33, 200, libtcod.BKGND_NONE) #HAT #COLUMN 2 libtcod.console_put_char(0, 3, 1, 185, libtcod.BKGND_NONE) #CHEST_PLATE libtcod.console_put_char(0, 3, 3, 204, libtcod.BKGND_NONE) #NECK BRACER libtcod.console_put_char(0, 3, 5, 202, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 7, 203, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 9, 206, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 11, 176, libtcod.BKGND_NONE) # WALL1 libtcod.console_put_char(0, 3, 13, 177, libtcod.BKGND_NONE) # WALL2 libtcod.console_put_char(0, 3, 15, 178, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 17, 25, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 19, 26, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 21, 27, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 23, 30, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 25, 31, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 27, 16, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 29, 17, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 31, 29, libtcod.BKGND_NONE) # libtcod.console_put_char(0, 3, 33, 18, libtcod.BKGND_NONE) # libtcod.console_flush() key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: return True
def handle_splash_screen_keys(self): key: tcod.Key = tcod.console_check_for_keypress() if not key: return if key.vk == tcod.KEY_DOWN: self._selected_option_index = min( len(self._main_menu_options_tuple) - 1, self._selected_option_index + 1) elif key.vk == tcod.KEY_UP: self._selected_option_index = max(0, self._selected_option_index - 1) elif key.vk in (tcod.KEY_SPACE, tcod.KEY_ENTER): self.main_menu_options[self._main_menu_options_tuple[ self._selected_option_index]][1]()
def main(): window_width = 80 window_height = 50 window_title = "Janus Mining Colony" font_path = Path("fonts/libtcod/dejavu16x16_gs_tc.png") presenter = Presenter(window_width, window_height, window_title, font_path) while presenter.is_window_open(): presenter.put_tile(1, 1, '@', libtcodpy.white) presenter.present() key = libtcodpy.console_check_for_keypress() if key.vk == libtcodpy.KEY_ESCAPE: return True
def main(): screen_width = 81 screen_height = 67 map_width = 81 map_height = 67 room_max_size = [8, 10, 12] room_min_size = [8, 10, 12] max_tried = 500 colors = { 'dark_wall': tcod.Color(0, 0, 100), 'dark_ground': tcod.orange, 'light_wall': tcod.Color(130, 110, 50), 'light_ground': tcod.Color(200, 180, 50) } tcod.console_set_custom_font( "BBT\\fonts\\arial12x12.png", tcod.FONT_TYPE_GRAYSCALE | tcod.FONT_LAYOUT_TCOD) tcod.console_init_root(screen_width, screen_height, 'Maze Generator', False) con = tcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_tried, room_min_size, room_max_size, map_width, map_height) while not tcod.console_is_window_closed(): tcod.console_set_default_foreground(0, tcod.white) tcod.console_put_char(con, 0, 0, '@', tcod.BKGND_NONE) tcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0) render_all(con, game_map, colors) tcod.console_flush() key = tcod.console_check_for_keypress() action = handle_key(key) exit = action.get('exit') if exit: return True
def handle_keys(): global exit_game global fov_recompute player_dx = 0 player_dy = 0 # check for specific key presses combos, etc key = tcod.console_check_for_keypress() if key.vk == tcod.KEY_ENTER and key.lalt: # Alt-enter toggle fullscreen tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) elif key.vk == tcod.KEY_ESCAPE: return 'exit' if (game_state == 'playing'): #movement keys if tcod.console_is_key_pressed(tcod.KEY_UP): player_dy = -1 # move or attack player_move_or_attack(player_dx, player_dy) elif tcod.console_is_key_pressed(tcod.KEY_DOWN): player_dy = 1 # move or attack player_move_or_attack(player_dx, player_dy) elif tcod.console_is_key_pressed(tcod.KEY_LEFT): player_dx = -1 # move or attack player_move_or_attack(player_dx, player_dy) elif tcod.console_is_key_pressed(tcod.KEY_RIGHT): player_dx = 1 # move or attack player_move_or_attack(player_dx, player_dy) else: return 'didnt-take-turn'
def handle_keys(): global player_x, player_y global exit_game #movement keys if tcod.console_is_key_pressed(tcod.KEY_UP): player_y = player_y - 1 elif tcod.console_is_key_pressed(tcod.KEY_DOWN): player_y = player_y + 1 elif tcod.console_is_key_pressed(tcod.KEY_LEFT): player_x = player_x - 1 elif tcod.console_is_key_pressed(tcod.KEY_RIGHT): player_x = player_x + 1 key = tcod.console_check_for_keypress() if key.vk == tcod.KEY_ENTER and key.lalt: # Alt-enter toggle fullscreen tcod.console_set_fullscreen(not tcod.console_is_fullscreen()) elif key.vk == tcod.KEY_ESCAPE: exit_game = True
def main(): screen_width = 80 screen_height = 50 font_path = 'arial10x10.png' font_flags = tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD tcod.console_set_custom_font(font_path, font_flags) window_title = "tenrl" fullscreen = False tcod.console_init_root(screen_width, screen_height, window_title, fullscreen) while not tcod.console_is_window_closed(): tcod.console_set_default_foreground(0, tcod.white) tcod.console_put_char(0, 1, 1, '@', tcod.BKGND_NONE) tcod.console_flush() key = tcod.console_check_for_keypress() if key.vk == tcod.KEY_ESCAPE: return True
def main(): libtcod.console_set_custom_font( 'courier12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) # TODO # tcod_test.py:37: DeprecationWarning: A renderer should be given, see the online documentation. # libtcod.console_init_root(screen_width, screen_height, 'NecroPlanter', False) libtcod.console_init_root(screen_width, screen_height, 'NecroPlanter', False) # TODO # tcod_test.py:39: DeprecationWarning: Use the tcod.event module to check for "QUIT" type events. # while not libtcod.console_is_window_closed(): while not libtcod.console_is_window_closed(): # TODO # tcod_test.py:40: DeprecationWarning: Set the `con.default_fg` attribute instead. # libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_put_char(0, 1, 1, '@', libtcod.BKGND_NONE) libtcod.console_put_char(0, 5, 5, '#', libtcod.BKGND_NONE) libtcod.console_put_char(0, 6, 6, '$', libtcod.BKGND_NONE) # setMap(mapObj.print_groups()) # print the map, starting it at 4,4 setMap(mapObj, 4, 4) libtcod.console_flush() # tcod_test.py:47: DeprecationWarning: Use the tcod.event.get function to check for events. # key = libtcod.console_check_for_keypress() key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: return True
def test_console_key_input(console): libtcodpy.console_check_for_keypress() libtcodpy.console_is_key_pressed(libtcodpy.KEY_ENTER)
def get_key_event(turn_based=None): if turn_based: key = tcod.console_wait_for_keypress(True) else: key = tcod.console_check_for_keypress() return key
libtcod.console_set_key_color( layer_1_console, libtcod.Color(xp_loader.transparent_cell_back_r, xp_loader.transparent_cell_back_g, xp_loader.transparent_cell_back_b)) #################### # libtcod piping to actually put the console layers on screen. This will probably change quite a bit for your actual usage of libtcod #################### draw_layers = False while not libtcod.console_is_window_closed(): key = libtcod.console_check_for_keypress() if key.vk == libtcod.KEY_ESCAPE: break #exit game if key.c == ord('a'): draw_layers = not draw_layers libtcod.console_clear(0) libtcod.console_blit(layer_0_console, 0, 0, xp_data['layer_data'][0]['width'], xp_data['layer_data'][0]['height'], 0, 0, 0) if draw_layers: libtcod.console_blit(layer_1_console, 0, 0, xp_data['layer_data'][1]['width'], xp_data['layer_data'][1]['height'], 0, 0, 0)
def main(): # logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.CRITICAL) tcod.console_set_custom_font( 'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) tcod.console_init_root(SCR_WIDTH, SCR_HEIGHT, 'My cool console.', order="C") tcod.console_set_default_foreground(0, tcod.yellow) logging.debug('Ready to make map.') lvl_map = Map(SCR_HEIGHT - 1, SCR_WIDTH) lvl_map.render() logging.debug('Ready to make player.') actors = Actors() player = Player(*lvl_map.get_random_legal_space(), PLAYER_ATK, PLAYER_MAX_HP, 'Player') # Make space under player unwalkable lvl_map.walkable[player.row][player.col] = False actors.player = player # actors.queue.insert(0, player) monster_counter = 0 for _ in range(MONSTER_COUNT): monster = Monster(*lvl_map.get_random_legal_space(), MONSTER_ATK, MONSTER_MAX_HP, f'Monster {monster_counter}') actors.queue.insert(0, monster) monster_counter += 1 actors.queue[0].render() # Make space under monster unwalkable lvl_map.walkable[monster.row][monster.col] = False logging.debug('Ready to render map to console.') logging.debug('Ready to enter main loop.') # Need to get our first actor actor = player logging.debug(f'actor={actor}, queue={actors.queue}') print(actors.queue) # Enter main loop while not tcod.console_is_window_closed(): logging.debug(f'actor={actor}, queue={actors.queue}') for _actor in actors.queue: if not _actor.alive: print(f'dumping {_actor}') monster = Monster(*lvl_map.get_random_legal_space(), MONSTER_ATK, MONSTER_MAX_HP, f'Monster {monster_counter}') monster_counter += 1 actors.queue.insert(0, monster) actors.queue[0].render() actors.queue.remove(_actor) lvl_map.walkable[_actor.row][_actor.col] = True # Pump events for keypress kp = tcod.console_check_for_keypress() if kp.vk == tcod.KEY_ESCAPE: return # print(player.acted) # Get next actor from the queue if we're ready if actor.acted: actors.queue.insert(0, actor) actor = actors.queue.pop() logging.debug(f'actor={actor}, queue={actors.queue}') # print(f'{actor} appraently acted.') # Update the actor actor.update(kp, lvl_map, actors) # logging.debug(f'{actor} acted = {actor.acted}') # Update the player position update_position_display(player) tcod.console_flush() time.sleep(SLOW_DOWN_DELAY)
def handle_inputs(game): key = tcod.console_check_for_keypress() for handler in game.input_handlers: handler.handle_input(key)
def get_key_event(turn_based = None): # Gather Keyboard Input if turn_based: key = tcod.console_wait_for_keypress(True) # Turn-Based: Wait For Input else: key = tcod.console_check_for_keypress() # Real-Time: Don't Wait return key
del Wars[:] # Select Map Mode while not tcod.console_is_window_closed(): # Simulation while isRunning == True: ProcessCivs(World, Civs, Chars, Colors, Month) # DEBUG Print Mounth Month += 1 print("Month: ", Month) # End Simulation tcod.console_check_for_keypress(True) if tcod.console_is_key_pressed(tcod.KEY_SPACE): timer = 0 isRunning = False print("*PAUSED*") time.sleep(1) # Flush Console if needUpdate: BiomeMap(Chars, Colors) needUpdate = False key = tcod.console_wait_for_keypress(True) # Start Simulation if tcod.console_is_key_pressed(tcod.KEY_SPACE):
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_width / 2 - 5), int(screen_height / 2), '@', 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, 'libtcod tutorial', False) con = libtcod.console.Console(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.generate_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(): 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) key = libtcod.console_check_for_keypress() 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()) time.sleep(.01)