def test_sys_time(console): libtcodpy.sys_set_fps(0) libtcodpy.sys_get_fps() libtcodpy.sys_get_last_frame_length() libtcodpy.sys_sleep_milli(0) libtcodpy.sys_elapsed_milli() libtcodpy.sys_elapsed_seconds()
def init_root(self, show_credits=False): RootConsole.active_root = self RootConsole.scratch = Console(self.width, self.height) RootConsole.temp_console = Console(self.width, self.height) tcod.console_init_root(self.width, self.height, self.title, self.fullscreen, self.renderer) if show_credits: tcod.console_credits() tcod.sys_set_fps(self.max_fps)
playery += 1 elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): playerx -= 1 elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): playerx += 1 ############################################# # Initialization & Main Loop ############################################# libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) playerx = SCREEN_WIDTH//2 playery = SCREEN_HEIGHT//2 while not libtcod.console_is_window_closed(): libtcod.console_set_default_foreground(0, libtcod.white) libtcod.console_put_char(0, playerx, playery, '@', libtcod.BKGND_NONE) libtcod.console_flush() libtcod.console_put_char(0, playerx, playery, ' ', libtcod.BKGND_NONE) #handle keys and exit game if needed exit = handle_keys()
def create_console(title: str, console_width: int, console_height: int, font_file: str, fps_limit: int): libtcod.console_set_custom_font(fontFile=font_file, flags=libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(w=console_width, h=console_height, title=title, fullscreen=False) libtcod.sys_set_fps(fps_limit) return libtcod.console_new(w=console_width, h=console_height)
def main(): # some initializations, main console title = 'NOIGUE L.C.' tcod.sys_set_fps(LIMIT_FPS) tcod.console_set_custom_font( "arial10x10.png", tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD,) tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, title, renderer=tcod.RENDERER_SDL2, order="F") con = tcod.console.Console(MAP_WIDTH, MAP_HEIGHT) con.default_fg = tcod.white game_state = GameStates.INTRO_SCREEN # inputs key = tcod.Key() mouse = tcod.Mouse() while not tcod.console_is_window_closed(): tcod.sys_check_for_event( tcod.EVENT_KEY_PRESS, key, mouse) if game_state == GameStates.INTRO_SCREEN: game_state = start_screen(con, game_state, key, title) elif game_state == GameStates.EXIT: break elif game_state == GameStates.CLASS_CHOICE: game_state = class_choice(con, game_state, key, title) elif game_state == GameStates.PLAYERS_TURN: # start pyo server pyo_server = Server(duplex=0).boot() pyo_server.start() # create player player = Entity(0, 0, '@', tcod.white, 'Player', blocks=True, type=Noiseur(sound=Noise()), inventory=Inventory(26), render=RenderOrder.ENTITY) player.type.sound_out() entities = [player] previous_game_state = game_state # create sub-panels panels = [] panel = Panel(0, CAMERA_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-CAMERA_HEIGHT, "log") panels.append(panel) panel = Panel(CAMERA_WIDTH, 0, SCREEN_WIDTH - CAMERA_WIDTH, CAMERA_HEIGHT, "sidebar") panels.append(panel) message_log = MessageLog( 2, SCREEN_WIDTH-4, SCREEN_HEIGHT-CAMERA_HEIGHT-2) # create game map and place entities, fov camera = Camera() game_map = GameMap() game_map.make_map(player, entities) fov = FOV(game_map) # compute fov fov.recompute_fov(player) # main loop targeting_item = None while not tcod.console_is_window_closed(): # get events tcod.sys_check_for_event( tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse) # render everything render_all(con, panels, entities, player, game_map, fov, message_log, game_state, camera) tcod.console_flush() clear_all(con, panels, entities, camera) # get action from keyboard 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') if show_inventory: previous_game_state = game_state game_state=GameStates.SHOW_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') # deal with actions player_turn_results = [] if game_state == GameStates.PLAYERS_TURN: 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 not target: player.move(dx, dy) fov.recompute = True game_state = GameStates.ENEMY_TURN elif pickup : 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.', tcod.yellow)) if game_state == GameStates.SHOW_INVENTORY: if inventory_index is not None and inventory_index < len(player.inventory.items): item = player.inventory.items[inventory_index] player_turn_results.extend(player.inventory.use(item, entities=entities, fov_map=fov.map)) 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=int(target_x+camera.x), target_y=int(target_y+camera.y)) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) for player_turn_result in player_turn_results: message = player_turn_result.get('message') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') if message: 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 game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, entity, fov, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') if message: message_log.add_message(message) else: game_state = GameStates.PLAYERS_TURN if exit: if game_state == GameStates.SHOW_INVENTORY: game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: pyo_server.stop() return True if fullscreen: tcod.console_set_fullscreen( not tcod.console_is_fullscreen())
player.move(1, 0) fov_recompute = True if __name__ == '__main__': ############################################# # Initialization & Main Loop ############################################# libtcod.console_set_custom_font( 'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) libtcod.sys_set_fps(LIMIT_FPS) con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT) # create object representing the player player = Object(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, '@', libtcod.white) # create an NPC npc = Object(SCREEN_WIDTH / 2 - 5, SCREEN_HEIGHT / 2, '@', libtcod.yellow) # the list of objects with those two objects = [npc, player] # generate map (at this point it's not drawn to the screen) make_map() # create the FOV map, according to the generated map
def main(): tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, b"Frogue", False) tcod.sys_set_fps(30) game = Game() game.run()
def init(): global root tcod.console_set_custom_font('arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) root = tcod.console_init_root(screenwidth, screenheight, 'Test', False) tcod.sys_set_fps(limitfps)
for object in objects: object.clear() # ############################################ # Initialization & Main Game Loop # ############################################ # Setup Font font_filename = 'd:/Python/RougeLike/project/arial10x10.png' tcod.console_set_custom_font(font_filename, tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD) # Initialize screen title = 'RLPY' tcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, title, FULLSCREEN) cuck = tcod.console_new(SCREEN_WIDTH,SCREEN_HEIGHT) #temporary work screen # Set FPS tcod.sys_set_fps(LIMIT_FPS) #Set map colors color_dark_wall = tcod.Color(0, 0, 100) color_light_wall = tcod.Color(130, 110, 50) color_dark_ground = tcod.Color(50,50,150) color_light_ground = tcod.Color(200, 180, 50) #Create player player = Object(0, 0, '@','player', tcod.white, blocks=True) objects = [player] #Generate map make_map() #FOV
initialize_fov() def load_customfont(): """The index of the first custom tile in the file""" a = 256 # The "y" is the row index, here we load the sixth row in the font file. # Increase the "6" to load any new rows from the file. for y in range(5, 6): libtcod.console_map_ascii_codes_to_font(a, 32, 0, y) a += 32 ############################################# # Initialization & Main Loop ############################################# # The font has 32 chars in a row, and there's a total of 10 rows. # Increase the "10" when you add new rows to the sample font file. libtcod.console_set_custom_font('TiledFont.png',\ libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10) libtcod.console_init_root(var.SCREEN_WIDTH, var.SCREEN_HEIGHT, 'python/roguebasin_tombs', False) libtcod.sys_set_fps(var.LIMIT_FPS) var.CON = libtcod.console_new(var.MAP_WIDTH, var.MAP_HEIGHT) var.panel = libtcod.console_new(var.SCREEN_WIDTH, var.PANEL_HEIGHT) main_menu()
import time import global_vars from combat_control import combat_controller from combat_functions import change_actor from ui_control import create_terminal, handle_input, render, fill_status_panel, BLTWindow from enums import GameStates, CombatPhase, EntityState, MenuTypes from entity import create_entity_list, fill_player_list, add_fighters, add_weapons from components.armor import apply_armor from game_map import array_gen, fill_map from fov_aoc import modify_fov, change_face from game_messages import MessageLog, Message from utilities import save_game, load_game from nc_control import nc_controller if __name__ == "__main__": libtcodpy.sys_set_fps(options.fps) #Console init dim_list = [(options.map_width, options.map_height), (options.status_panel_w, options.status_panel_h), (options.enemy_panel_w, options.enemy_panel_h), (options.message_panel_w, options.message_panel_h)] menu_desc = { 'New Game': 'Start a new game', 'Load Game': 'Load the game from disk', 'Quit Game': 'Exit the game' } menu_dict = { 'type': MenuTypes.combat, 'header': 'Main Menu',