def __init__(self, window_title, width, height, fps_limit=20): tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.console = tdl.init(width, height, title=window_title, fullscreen=False) tdl.set_fps(fps_limit)
def __init__(self, root_path): self.root_path = root_path self.limit_fps = 60 self.is_done = False self.MAP_TILES_X = 80 self.MAP_TILES_Y = 50 self.SCREEN_TILES_X = self.MAP_TILES_X self.SCREEN_TILES_Y = self.MAP_TILES_Y self.entities = [] self.player = None self.map = Map(self.MAP_TILES_X, self.MAP_TILES_Y, self) self.map.debug_show_colors = True self.input_mode = InputMode.GAME self.panel_height = 7 self.bar_width = 20 self.panel_y = self.SCREEN_TILES_Y - self.panel_height self.fov_recompute = True self.update_sim = True self.visible_tiles = [] # todo: move to map self.use_fog_of_war = False self.torch_radius = 10 self.draw_hp = False self.init() path = os.path.join(self.root_path, 'fonts', 'arial12x12.png') tdl.set_font(path, greyscale=True, altLayout=True) self.root_console = tdl.init(self.SCREEN_TILES_X, self.SCREEN_TILES_Y, title='tcod demo', fullscreen=False) self.con = tdl.Console(self.SCREEN_TILES_X, self.SCREEN_TILES_Y) self.con_console = tdl.Console(self.SCREEN_TILES_X, self.panel_height) tdl.setFPS(self.limit_fps) logger.debug("FPS: {}".format(self.limit_fps))
def main(): ''' The following creates and sets the default behavior of the terminal it: 1. creates the default window 2. places the player at the center of the map 3. may set the fps rate ''' # several constants that will be used in the window creation SCREEN_WIDTH = Globals.SCREEN_WIDTH SCREEN_HEIGHT = Globals.SCREEN_HEIGHT # LIMIT_FPS = 20 # used for realtime instead of turnbased # sets a custom font TODO decide on a font, this is filler for now tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) # creates the console window console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Missions: Colonizer", fullscreen=False) # redirects standard out to the console we have created sys.stdout = console # NOTE use to allow for 'realtime' gameplay vs turnbased # tdl.setFPS(LIMIT_FPS) ''' The following creates and manages the controller object which in turn creates and manages the model & the view ''' try: # this try is waiting for the exit request # do I need to assing the controller to a varible? controller = ControllerColonizer(console) except SystemExit: pass # TODO write code to exit gracefully
def initialize_window(): ''' initializes & launches the game ''' # Set custom font tdl.set_font('resources/terminal12x12_gs_ro.png', greyscale=True) # initialize the main console gv.root = tdl.init(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT, title=settings.DUNGEONNAME, fullscreen=False) gv.con = tdl.Console(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) # initialize the panels gv.stat_panel = tdl.Console(settings.SIDE_PANEL_WIDTH, settings.STAT_PANEL_HEIGHT) gv.inv_panel = tdl.Console(settings.SIDE_PANEL_WIDTH, settings.INV_PANEL_HEIGHT) gv.gamelog_panel = tdl.Console(settings.BOTTOM_PANEL_WIDTH, settings.BOTTOM_PANEL_HEIGHT) gv.combat_panel = tdl.Console(settings.COMBAT_PANEL_WIDTH, settings.BOTTOM_PANEL_HEIGHT) # set the default captions for all panels gv.stat_panel.caption = 'Status' gv.inv_panel.caption = 'Inventory' gv.gamelog_panel.caption = 'Gamelog' gv.combat_panel.caption = 'Enemies' # set the default border color and mode for all panels for panel in [ gv.stat_panel, gv.inv_panel, gv.gamelog_panel, gv.combat_panel ]: panel.mode = 'default' panel.border_color = settings.PANELS_BORDER_COLOR
def main(argv=[]): tdl.set_font(FONT, greyscale=True, altLayout=True) main_con = tdl.init(CONSOLE_WIDTH, CONSOLE_HEIGHT, TITLE) app = SimpleMenu(main_con, TITLE, MAIN_MENU_OPTIONS) app.run() del main_con gc.collect()
def __init__(self): tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.console = tdl.init(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, title="zz", fullscreen=False) tdl.setFPS(self.LIMIT_FPS) self.objects = [] self.player = Player() self.objects.append(self.player)
def main(): screen_width = 80 screen_height = 50 tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) root_console = tdl.init(screen_width, screen_height, title='Roguelike Tutorial Revised') while not tdl.event.is_window_closed(): root_console.draw_char(1, 1, '@', bg=None, fg=(255, 255, 255)) tdl.flush() root_console.draw_char(1, 1, ' ', bg=None) for event in tdl.event.get(): if event.type == 'KEYDOWN': user_input = event break else: user_input = None if not user_input: continue if user_input.key == 'ESCAPE': return True
def _setup(self): self.SCREEN_WIDTH = 80 self.SCREEN_HEIGHT = 50 self.LIMIT_FPS = 20 tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, title='AsciiRPG', fullscreen=False) tdl.setFPS(self.LIMIT_FPS) # Create an offscreen console self.console = tdl.Console(self.SCREEN_WIDTH, self.SCREEN_HEIGHT) # Map self.map = Map() self.map.create(self.SCREEN_HEIGHT, self.SCREEN_WIDTH) try: player_y = 1 player_x = 1 while self.map.tiles[player_y][player_x].blocked: player_y = randint(0, self.map.WIDTH - 1) player_x = randint(0, self.map.HEIGHT - 1) except: print("out of range") # Spawn player, first specify Y (which of the top tiles to start at), then X (which of the horizontal tiles to start at) self.player = Player(player_y, player_x, (255,255,255)) #self.cat = Cat(self.SCREEN_WIDTH + 4, self.SCREEN_HEIGHT, (255,255,255)) self.entities = [self.player]
def main(argv=[]): tdl.set_font(FONT, greyscale=True, altLayout=True) main_con = tdl.init(MAP_SIZE, MAP_SIZE, TITLE) app = FogApp(main_con) app.run() del main_con gc.collect()
def main(): global console tdl.set_font('data/terminal8x8_gs_ro.png') console = tdl.init(WIDTH, HEIGHT) console.draw_str(0, 0, "Hello World") tdl.flush() tdl.event.key_wait()
def __init__(self, args): Game.args = args # Configure game settings config = configparser.ConfigParser() cfg_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.cfg') config.read(cfg_path) Game.config = config # Configure tdl tdl.set_font(Game.config['ENGINE']['font']) tdl.set_fps(int(Game.config['ENGINE']['fps'])) self.console = tdl.init(54, 30, 'lunch break roguelike', renderer=Game.config['ENGINE']['renderer']) self._last_time = time.time() Game.seconds_per_tick = float(Game.config['GAME']['turn']) if not Game.instance: Game.instance = self instances.register('game', self) # Twitch Observer nickname = Game.config['TWITCH']['Nickname'] password = Game.config['TWITCH']['Password'] self.channel = Game.config['TWITCH']['Channel'] self.observer = Observer(nickname, password) self.observer.start() self.observer.join_channel(self.channel) self.start_time = time.time() Game.scene_root = gamescene.GameScene()
def __init__(self): tdl.set_font('assets/arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(self.screen.width, self.screen.height, title="Dungeon Run", fullscreen=False) self.con = tdl.Console(self.screen.width, self.screen.height) tdl.set_fps(30)
def main(): screen_width = 80 screen_height = 50 map_width = 80 map_height = 45 colors = {'dark_wall': (0, 0, 100), 'dark_ground': (50, 50, 150)} player = Entity(int(screen_width / 2), int(screen_height / 2), '@', (255, 255, 255)) npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), '@', (255, 255, 0)) entities = [npc, player] tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) root_console = tdl.init(screen_width, screen_height, title='Roguelike Tutorial Revised') con = tdl.Console(screen_width, screen_height) game_map = tdl.map.Map(map_width, map_height) make_map(game_map) while not tdl.event.is_window_closed(): render_all(con, entities, game_map, root_console, screen_width, screen_height, colors) tdl.flush() clear_all(con, entities) for event in tdl.event.get(): if event.type == 'KEYDOWN': user_input = event break else: user_input = None if not user_input: continue action = handle_keys(user_input) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move if game_map.walkable[player.x + dx, player.y + dy]: player.move(dx, dy) if exit: return True if fullscreen: tdl.set_fullscreen(not tdl.get_fullscreen())
def __init__(self, size=SCREEN_SIZE, font=FONT_PATH, title=GAME_TITLE): self.width, self.height = size self.font = font self.title = title tdl.set_font(font, greyscale=True, altLayout=True) self.root = tdl.init(self.width, self.height, title=self.title, fullscreen=True) self.console = tdl.Console(self.width, self.height)
def __init__(self): self.size = (4, 3) self.board = [self.FLOOR, self.FLOOR, self.FLOOR, self.FINISH, self.FLOOR, self.WALL, self.FLOOR, self.FIREPIT, self.FLOOR, self.FLOOR, self.FLOOR, self.FLOOR] self.position = [0, 2] tdl.set_font("terminal16x16_gs_ro.png") self.console = tdl.init(40, 24, title='CodersAI Game') self.game_finished = False self.result = None
def re_init_font(self): # allows reloading of font path = random_font_path(PATH_APP_ROOT) logger.debug("font: ", path) tdl.set_font(path, greyscale=True, altLayout=True) self.root_console = tdl.init(self.SCREEN_TILES_X, self.SCREEN_TILES_Y, title='tcod demo', fullscreen=False) self.con = tdl.Console(self.SCREEN_TILES_X, self.SCREEN_TILES_Y) tdl.setFPS(LIMIT_FPS)
def __init__(self, width, height, title='', font='terminal8x14'): self.width = width self.height = height self.title = title self.windows = [] self.font = font tdl.set_font('fonts/{}.png'.format(font), greyscale=True, altLayout=False) self.root = tdl.init(width, height, title=title, fullscreen=False)
def main(): global root_view # setup to start the TDL and small consoles font = os.path.join(assets_dir, "arial10x10.png") tdl.set_font(font, greyscale=True, altLayout=True) tdl.setFPS(LIMIT_FPS) root_view = tdl.init(width=SCREEN_WIDTH, height=SCREEN_HEIGHT, title="Roguelike", fullscreen=False) main_menu()
def init(self): working_dir = os.path.dirname(__file__) # Get path to font file font_file = 'data/terminal32x32_gs_ro.png' font_path = os.path.normpath(os.path.join(working_dir, font_file)) if not os.path.exists(font_path): raise RuntimeError('Missing font file: {}'.format(font_file)) # Init TDL tdl.set_font(font_path) self.console = tdl.init(10, 21, 'BS.CHESS()', renderer='GLSL')
def Main(): horzDirection = 1 globalCounter = 0 delay = 20 Score = 0 Hardness = 0 SCREEN_WIDTH = 80 SCREEN_HEIGHT = 50 LIMIT_FPS = 20 tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Space Invaders", fullscreen=False) tdl.setFPS(LIMIT_FPS) while not tdl.event.is_window_closed(): screen.Update() globalCounter+=1 if globalCounter >= delay - Hardness: globalCounter=0 horzDirection *= NeedToChangeDir() for en in enemies: en.TryToMove(Vector(horzDirection, 0)) PrintScreen(console) tdl.flush() print("Score: " + str(Score)) if not screen.Objects.__contains__(player): break for en in enemies: if not screen.Objects.__contains__(en): enemies.remove(en) Score+=100 tmp = Score/1000 if Hardness<19: Hardness = int(tmp) if Hardness>18: Hardness = 18 if len(enemies) == 0: InitEnemies() print("Game Over! Your Score is {0}".format(Score))
def char_finder(): w_display = 16 h_display = 16 w_info = 15 h_info = 16 margin = 1 w = w_display + w_info + margin h = 16 highlight = (0, 0) tdl.set_font("mononoki_16-19.png", columns=16, rows=16, greyscale=True, altLayout=False) tdl.set_fps(30) root = tdl.init(w, h, title="char picker") display = tdl.Console(w_display, h_display) info = tdl.Console(w_info, h_info) display.set_colors(FG, BG) info.set_colors(FG, BG) running = True while running: display.clear() info.clear() c = 0 for y in range(0, 16): for x in range(0, 16): color = FG if highlight == (x, y): color = HIGHLIGHT display.draw_char(x, y, c, fg=color) c += 1 for event in tdl.event.get(): if event.type == "KEYDOWN": running = False break elif event.type == "MOUSEDOWN": print(event.cell) highlight = event.cell info.draw_str(0, 0, "cell: %dx%d" % highlight) info.draw_str(0, 1, "char: %d" % get_char(*highlight)) root.blit(display, 0, 0, 16, 16, 0, 0) root.blit(info, w_display + margin, 0, w_info, h_info, 0, 0) tdl.flush()
def main(): global SCREEN_HEIGHT, SCREEN_WIDTH, root, con, hud, msgbox tdl.set_font('terminal8x8_gs_tc.png', greyscale=True, altLayout=True) tdl.event.set_key_repeat(delay=1000, interval=1000) root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Very Small Roguelike", fullscreen=False) con = tdl.Console(CON_WIDTH, CON_HEIGHT) hud = tdl.Console(HUD_WIDTH, HUD_HEIGHT) msgbox = messagebox.MessageBox(tdl.Console(MSG_WIDTH, MSG_HEIGHT)) run_game()
def __init__(self): self.SCREEN_WIDTH = 110 self.SCREEN_HEIGHT = 60 self.LIMIT_FPS = 20 tdl.set_font('arial12x12.png', greyscale=True, altLayout=True) self.FOV_ALGO = 'Basic' self.PANEL_HEIGHT = 12 self.BAR_WIDTH = 20 self.PANEL_Y = self.SCREEN_HEIGHT - self.PANEL_HEIGHT self.MSG_X = 2 self.MSG_WIDTH = 30 self.MSG_HEIGHT = self.PANEL_HEIGHT - 5 self.MOVEMENT_KEYS = { 'UP': [0, -1], 'DOWN': [0, 1], 'LEFT': [-1, 0], 'RIGHT': [1, 0], 'KP1': [-1, 1], 'KP2': [0, 1], 'KP3': [1, 1], 'KP4': [-1, 0], 'KP6': [1, 0], 'KP7': [-1, -1], 'KP8': [0, -1], 'KP9': [1, -1] } self.ACTION_KEYS = { 'J': 'jump', 'j': 'jump', 'D': 'debug', 'd': 'debug', 'M': 'menu', 'm': 'menu', 'w': 'where', 'W': 'where' } # Y is down, X is Right self.CENTERX = self.SCREEN_WIDTH // 2 self.CENTERY = self.SCREEN_HEIGHT // 2 self.console = tdl.Console(self.SCREEN_WIDTH, self.SCREEN_HEIGHT) self.main_window = tdl.init(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, title="Neolithic Rogue", fullscreen=False) self.fov_recompute = True self.game_state = 'playing' self.currentArea = None self.player = Character('@', (255, 0, 255), self.CENTERX, self.CENTERY, 'Player')
def __init__(self, screenWidth, screenHeight, fps): self.screenWidth = screenWidth self.screenHeight = screenHeight #set up window through tdl tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(screenWidth, screenHeight, title="Roguelike", fullscreen=False) self.console = tdl.Console(screenWidth, screenHeight) tdl.setFPS(fps) self.objects = []
def __init__( self, height=60, width=90, fps=30, panel_height=PANEL_HEIGHT, hp_bar_width=BAR_WIDTH, alt_layout=False, font='guildmaster/fonts/terminal16x16_gs_ro.png', # font='guildmaster/fonts/hack15x15.png, vim_bindings=VIM_BINDINGS): self.width = width self.height = height self.map_height = height - panel_height self.panel_height = panel_height self.panel_y = self.height - self.panel_height self.hp_bar_width = hp_bar_width self.message_width = width - hp_bar_width - 2 self.fps = fps self.font = font self.alt_layout = alt_layout self.vim_bindings = vim_bindings # Initialise the player # TODO : character creation screen self.player = new_PC('Player', 'Human') self.visible_tiles = set() self.visible_tiles2 = set() self.magically_visible = set() # initialise message queue self.messages = [] tdl.set_font(self.font, greyscale=True, altLayout=self.alt_layout, columns=16, rows=16) tdl.event.set_key_repeat(delay=500, interval=50) self.root = tdl.init(self.width, self.height, title="Guild Master", fullscreen=False) self.con = tdl.Console(self.width, self.map_height) self.panel = Panel(self.width, self.panel_height, self.hp_bar_width) tdl.set_fps(self.fps)
def __init__(self): tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) self.root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Roguelike", fullscreen=False) tdl.setFPS(LIMIT_FPS) self.con = tdl.Console(MAP_WIDTH, MAP_HEIGHT) self.panel = tdl.Console(SCREEN_WIDTH, PANEL_HEIGHT) self.panel2 = tdl.Console(PANEL_2_WIDTH, PANEL_2_HEIGHT) self.visible_tiles = [] self.fov_recompute = True self.bg_img = image_load('menu_background.png') self.game_msgs = []
def main(): screen_width = 52 screen_height = 54 pause = True tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) gen = 0 life = numpy.random.randint(2, size=(50, 50), dtype=numpy.byte) root_console = tdl.init(screen_width, screen_height, title='.*LIPHE*.') con = tdl.Console(screen_width, screen_height) while not tdl.event.is_window_closed(): play_life(con, root_console, screen_width, screen_height, life) root_console.draw_str(0, 52, "Gen: " + str(gen), (220, 180, 140)) tdl.flush() for event in tdl.event.get(): if event.type == 'KEYDOWN': user_input = event break else: user_input = None action = handle_keys(user_input) advance = action.get('advance') new = action.get('new') if advance: pause = not pause if new: pause = True gen = 0 life = numpy.random.randint(2, size=(50, 50), dtype=numpy.byte) play_life(con, root_console, screen_width, screen_height, life) if pause == False: life = play_life(con, root_console, screen_width, screen_height, life) gen += 1
def main(): screen_width = 80 screen_height = 50 player_x = int(screen_width / 2) player_y = int(screen_height / 2) tdl.set_font('arial10x10.png', greyscale=True, altLayout=True) root_console = tdl.init(screen_width, screen_height, title='Cloudstar') con = tdl.Console(screen_width, screen_height) while not tdl.event.is_window_closed(): con.draw_char(player_x, player_y, '@', bg=None, fg=(255, 255, 255)) root_console.blit(con, 0, 0, screen_width, screen_height, 0, 0) tdl.flush() con.draw_char(player_x, player_y, ' ', bg=None) for event in tdl.event.get(): if event.type == 'KEYDOWN': user_input = event break else: user_input = None if not user_input: continue action = handle_keys(user_input) move = action.get('move') exit = action.get('exit') fullscreen = action.get('fullscreen') if move: dx, dy = move player_x += dx player_y += dy if exit: return True if fullscreen: tdl.set_fullscreen(not tdl.get_fullscreen())
def __init__(cls, player, dungeon): # TODO: give consoles a better name tdl.set_font(get_abs_path('lucida10x10_gs_tc.png'), greyscale=True, altLayout=True) # TODO: Instead of using the level width, use views with fixed width # FIXME: Since we don't have views yet, hardcode level width and height # Initialize consoles cls.console = tdl.Console(80, 40) cls.panel = tdl.Console(cls.SCREEN_HEIGHT, cls.PANEL_HEIGHT) cls.backpack = tdl.Console(cls.BACKPACK_WIDTH, cls.SCREEN_HEIGHT) cls.root_console = tdl.init(cls.SCREEN_WIDTH, cls.SCREEN_HEIGHT, title=cls.GAME_TITLE, fullscreen=False) # Initialize references to other needed objects cls.player = player cls.dungeon = dungeon
def init_game(self): # Other fonts: https://github.com/HexDecimal/python-tdl/tree/master/fonts/libtcod tdl.set_font(self.font, columns=16, rows=16, greyscale=True, altLayout=False) self.root = tdl.init(self.screen_width, self.screen_height, title="PyRo", fullscreen=False) tdl.set_fps(20) # load game data gamedata.load() self.current_scene = StartScreen() self.current_scene.setup(self)