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, 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 __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(): ''' 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 _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(): 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 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 __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 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 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 __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, main_console=None, level_display_width=c.SCREEN_WIDTH, level_display_height=c.SCREEN_HEIGHT): if main_console is None: self.main_console = tdl.init(level_display_width, level_display_height, 'From Renderer Default Constructor') else: self.main_console = main_console self.level_display_width = level_display_width self.level_display_height = level_display_height self._level_console = tdl.Console(level_display_width, level_display_height)
def setUpClass(cls): cls.console = tdl.init(WIDTH, HEIGHT, 'TDL UnitTest', False, renderer='GLSL') # make a small window in the corner cls.window = tdl.Window(cls.console, 0, 0, WINWIDTH, WINHEIGHT)
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 __init__(self, m, n): self.m = m self.n = n self.grid = np.random.randint(0, 2, size=(m, n)) self.root = tdl.init(m, n, title="Conway's Game of Life", fullscreen=False)
def init_root(self, width=80, height=26, show_credits=False): self.root = tdl.init(width, height) self.scratch = tdl.Console(width, height) self.temp_console = tdl.Console(width, height) self.width, self.height = width, height tdl.set_fps(30) if show_credits: tcod.console_credits()
def init_root(self, width=80, height=26, show_credits=False): self.root = tdl.init(width, height) self.canvas = tdl.Console(width, height) self.temp_console = tdl.Console(width, height) self.width, self.height = width, height tdl.set_fps(30) if show_credits: tcod.console_credits()
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): self.main_console_w = 100 self.main_console_h = 60 font_path = os.path.normpath( os.path.join(os.path.realpath(__file__), "..", "..", "terminal8x8_gs_ro.png")) tdl.setFont(font_path) self.main_console = tdl.init(self.main_console_w, self.main_console_h, 'Roguelike Game')
def main(): console = tdl.init(46, 20, renderer='OPENGL') for Test in [ FullDrawCharTest, CharOnlyTest, TypewriterCharOnlyTest, ColorOnlyTest, GetCharTest, SingleRectTest, DrawStrTest, BlitScrollTest ]: Test(console).run() console.clear()
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 __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 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): self.root = tdl.init(80, 40) self._map = tdl.Console(40, 40) self._map.drawFrame(0, 0, 40, 40, '#') self._text = tdl.Console(38, 38) self._text.setMode('scroll') self.entities.append(entity.Player(1, 1, '@', self)) self.entities.append(entity.Walker(1, 2, 'J', self))
def __init__(self): self.main_console_w = 80 self.main_console_h = 60 tdl.setFont('terminal8x8_gs_ro.png') # Configure the font. # Create the root console. self.main_console = tdl.init(self.main_console_w, self.main_console_h, 'Roguelike Game') CONSOLES['action_log'] = self.create_new_console(40, 15) CONSOLES['status'] = self.create_new_console(40, 15)
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(): 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 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(): 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 blit(fname): #image open try: img = Image.open(fname) except: input('ERROR: File not found.') return #image resize size = (W, H) = img.size w_blit = W // FONTSIZE h_blit = H // FONTSIZE size_blit = (w_blit, h_blit) img.thumbnail(size_blit, Image.ANTIALIAS) pix = img.load() #tdl renderer start console = tdl.init( w_blit, h_blit, 'ASCII BLITTER Press ANY key to save to file.' ) console.clear() for x in range(w_blit): for y in range(h_blit): m = (pix[x, y][0] + pix[x, y][1] + pix[x, y][2]) // 3 if m < 9: c = '.' elif m < 22: c = ',' elif m < 27: c = '`' elif m < 32: c = '-' elif m < 37: c = '+' elif m < 45: c = '/' elif m < 130: c = chr(random.randint(97, 120)) elif m < 195: c = chr(random.randint(65, 90)) else: c = str(random.randint(0, 9)) console.draw_char( x, y, c, pix[x, y], (pix[x, y][0] // 10, pix[x, y][1] // 10, pix[x, y][2] // 10)) tdl.flush() tdl.event.key_wait() tdl.flush() tdl.screenshot() del console return
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, width=132, height=60): global _instance if _instance: raise TermboxException("It is possible to create only one instance of Termbox") try: self.console = tdl.init(width, height) except tdl.TDLException as e: raise TermboxException(e) self.e = Event() # cache for event data _instance = self
def __init__(self, width=132, height=60): global _instance if _instance: raise TermboxException( "It is possible to create only one instance of Termbox") try: self.console = tdl.init(width, height) except tdl.TDLException as e: raise TermboxException(e) self.e = Event() # cache for event data _instance = self
def run_benchmark(): global log log = open('results.log', 'a') print('', file=log) console = tdl.init(WIDTH, HEIGHT, renderer=RENDERER) print_result('Benchmark run on %s' % time.ctime()) print_result('Running under %s %s' % (platform.python_implementation(), platform.python_version())) print_result('In %s mode' % (['release', 'debug'][__debug__])) print_result('%i characters/frame' % (WIDTH * HEIGHT)) print_result('Opened console in %s mode' % RENDERER) Benchmark_DrawChar_DefaultColor().run(console) Benchmark_DrawChar_NoColor().run(console) #Benchmark_DrawStr16_DefaultColor().run(console) #Benchmark_DrawStr16_NoColor().run(console) log.close() print('results written to results.log')
#!/usr/bin/env python """ Example showing some of the most basic functions needed to say "Hello World" """ # you can skip past this part and go onto the next. # what this does is allow tdl to be imported without installing it first. import sys sys.path.insert(0, '../') # import the tdl library and all of it's functions, this gives us access to anything # starting with "tdl." import tdl # start the main console, this will open the window that you see and give you a Console. # we make a small window that's 20 tiles wide and 16 tile's tall for this example. console = tdl.init(20, 16) # draw the string "Hello World" at the top left corner using the default colors: # a white forground on a black background. console.drawStr(0, 0, 'Hello World') # display the changes to the console with flush. # if you forget this part the screen will stay black emptiness forever. tdl.flush() # wait for a key press, any key pressed now will cause the program flow to the next part # which closes out of the program. tdl.event.keyWait() # if you run this example in IDLE then we'll need to delete the console manually # otherwise IDLE prevents the window from closing causing it to hang
def __init__(self, width = 80, height = 24, title = 'TDL Console'): import tdl # Importhing this initializes a bunch of crap self.tdl = tdl # We don't want to import it a bunch of times though self.console = tdl.init(width, height, title) self.prompt = None
def setUpClass(cls): tdl.setFont('../fonts/libtcod/terminal8x8_gs_ro.png') cls.console = tdl.init(WIDTH, HEIGHT, 'TDL UnitTest', False, renderer='SDL') # make a small window in the corner cls.window = tdl.Window(cls.console, 0, 0, WINWIDTH, WINHEIGHT)
def main(): console = tdl.init(46, 20, renderer='OPENGL') for Test in [FullDrawCharTest, CharOnlyTest, TypewriterCharOnlyTest, ColorOnlyTest, GetCharTest, SingleRectTest, DrawStrTest, BlitScrollTest]: Test(console).run() console.clear()
def __init__(self): self.console = tdl.init(WIDTH, HEIGHT, "Game of life", fullscreen=False, renderer='SDL') self.board = [] self.is_running = False self.step = 0
def init(): global console console = tdl.init(WIDTH, HEIGHT)
""" This function draws all Renderable objects :param renderable_list: The list of objects to render. """ main_console.clear() for re in renderable_list: re.draw(main_console) root.clear() root.blit(main_console) if __name__ == '__main__': root = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT) tdl.set_fps(LIMIT_FPS) gamestate = state.MainState() actors = [] player = actor.Actor("Player", (1, 1), '@') actors.append(player) main_console = tdl.Console(SCREEN_WIDTH, SCREEN_HEIGHT) draw(actors) tdl.flush() while not tdl.event.is_window_closed(): key_ev = tdl.event.key_wait()
def main(): console = tdl.init(WIDTH, HEIGHT) board = LifeBoard(WIDTH, HEIGHT - 1) # The R-pentomino # board.set_batch(WIDTH // 2 - 2,HEIGHT // 2 - 2, # [' **', # '** ', # ' * ']) # Diehard # board.set_batch(WIDTH // 2 - 5,HEIGHT // 2 - 2, # [' * ', # '** ', # ' * ***']) # Gosper glider gun board.set_batch( 1, 1, [ " ", " * ", " * * ", " ** ** **", " * * ** **", "** * * ** ", "** * * ** * * ", " * * * ", " * * ", " ** ", ], ) play = False redraw = True mouse_drawing = None mouse_x = -1 mouse_y = -1 while True: for event in tdl.event.get(): if event.type == "QUIT": return elif event.type == "KEYDOWN": if event.key == "SPACE": play = not play redraw = True elif event.char.upper() == "S": board.step() redraw = True elif event.char.upper() == "C": board.clear() redraw = True elif event.char.upper() == "W": board.wrap = not board.wrap redraw = True elif event.type == "MOUSEDOWN": x, y, = event.cell board.toggle(x, y) mouse_drawing = event.cell redraw = True elif event.type == "MOUSEUP": mouse_drawing = None elif event.type == "MOUSEMOTION": if mouse_drawing and mouse_drawing != event.cell: x, y = mouse_drawing = event.cell board.toggle(x, y) mouse_x, mouse_y = event.cell redraw = True if play and mouse_drawing is None: board.step() redraw = True if redraw: redraw = False console.clear() for x, y in board.live_cells: console.draw_char(x, y, "*") # console.draw_rect(0, -1, None, None, None, bg=(64, 64, 80)) console.draw_rect(0, -1, None, None, None, bg=(64, 64, 80)) console.draw_str( 0, -1, "Mouse:Toggle Cells, Space:%5s, [S]tep, [C]lear, [W]rap Turn %s" % (["Play", "Pause"][play], ["On", "Off"][board.wrap]), None, None, ) if (mouse_x, mouse_y) in console: console.draw_char(mouse_x, mouse_y, None, (0, 0, 0), (255, 255, 255)) else: time.sleep(0.01) tdl.flush() tdl.set_title("Conway's Game of Life - %i FPS" % tdl.get_fps())
# 1 2 3 'KP1': [-1, 1], 'KP2': [0, 1], 'KP3': [1, 1], 'KP4': [-1, 0], 'KP6': [1, 0], 'KP7': [-1, -1], 'KP8': [0, -1], 'KP9': [1, -1], } tdl.setFont('terminal8x8_gs_ro.png') # Configure the font. # Create the root console. console = tdl.init(WIDTH, HEIGHT, 'python-tdl tutorial') # player coordinates playerX, playerY = 1, 2 while True: # Continue in an infinite game loop. console.clear() # Blank the console. # Using "(x, y) in console" we can quickly check if a position is inside of # a console. And skip a draw operation that would otherwise fail. if (playerX, playerY) in console: console.drawChar(playerX, playerY, '@') tdl.flush() # Update the window.
BAR_WIDTH = 20 PANEL_HEIGHT = 7 PANEL_Y = SCREEN_HEIGHT - PANEL_HEIGHT MSG_X = BAR_WIDTH + 2 MSG_WIDTH = SCREEN_WIDTH - BAR_WIDTH - 2 MSG_HEIGHT = PANEL_HEIGHT - 1 INVENTORY_WIDTH = 50 LIMIT_FPS = 20 playerX = SCREEN_WIDTH/2 playerY = SCREEN_HEIGHT/2 MOUSE_COORD = {'x':0, 'y':0} console = tdl.init(SCREEN_WIDTH, SCREEN_HEIGHT, title = "Roguelike") panel = tdl.Console(SCREEN_WIDTH, PANEL_HEIGHT) con = tdl.Console(MAP_WIDTH, MAP_HEIGHT) tdl.setFPS(LIMIT_FPS) ROOM_MAX_SIZE = 10 ROOM_MIN_SIZE = 6 MAX_ROOMS = 30 MAX_ROOM_ITEMS = 2 fov_recompute = False FOV_ALGO = 0 #default FOV algorithm FOV_LIGHT_WALLS = True TORCH_RADIUS = 10 HEAL_AMOUNT = 4
for x in range(width): for y in range(height): val = self.noise.getPoint((x + self.x) / width * self.zoom, (y + self.y) / height * self.zoom, self.z) bgcolor = (int(val * 255),) * 2 + (min(255, int(val * 2 * 255)),) samplewin.drawChar(x, y, ' ', (255, 255, 255), bgcolor) WIDTH, HEIGHT = 80, 40 SAMPLE_WINDOW_RECT = (20, 10, 46, 20) FONT = '../fonts/X11/8x13.png' if __name__ == '__main__': tdl.setFont(FONT) console = tdl.init(WIDTH, HEIGHT, renderer='opengl') samplewin = tdl.Window(console, *SAMPLE_WINDOW_RECT) samples = [cls() for cls in [TrueColorSample, NoiseSample]] sampleIndex = 0 while 1: console.clear() samples[sampleIndex].runOnce() for i, sample in enumerate(samples): bgcolor = (0, 0, 0) if sampleIndex == i: bgcolor = (0, 0, 192) console.drawStr(0, -5 + i, '%s' % sample.name, (255, 255, 255), bgcolor) console.drawStr(0, -1, '%i FPS' % tdl.getFPS()) tdl.flush()
import tdl from Map import * WIDTH = 200 HEIGHT = 100 WINWIDTH = 200 WINHEIGHT = 200 COLOR_BLACK = (0,0,0) COLOR_WHITE = (255,255,255) COLOR_RED = (255,0,0) COLOR_GREEN = (0,255,0) COLOR_BLUE = (0,0,255) COLOR_YELLOW = (255,255,0) console = tdl.init(WIDTH,HEIGHT,title='Test') next_console = tdl.Console(WIDTH,HEIGHT) # player positions # px = WIDTH / 2 # py = HEIGHT / 2 dungeon = Map(HEIGHT,WIDTH) # dungeon.test(90,50,Tile(char=' ',blocks_movement=True,bg=COLOR_RED)) gen = WorldGenerator(dungeon) # gen.carve_rect_room(Rect(85,40,40,40)) # gen.carve_rect_room(Rect(65,40,15,15)) # gen.carve_h_tunnel(66,85,44) parts = gen.create_partitions(0,0,HEIGHT-1,WIDTH-1) gen.spawn_partition_rooms(parts, fill=False)
#!/usr/bin/env python """ An interactive example of what events are available. """ import sys sys.path.insert(0, '../') import tdl WIDTH, HEIGHT = 80, 60 console = tdl.init(WIDTH, HEIGHT) # the scrolling text window textWindow = tdl.Window(console, 0, 0, WIDTH, -2) # slow down the program so that the user can more clearly see the motion events tdl.setFPS(24) while 1: event = tdl.event.wait() print(event) if event.type == 'QUIT': raise SystemExit() elif event.type == 'MOUSEMOTION': # clear and print to the bottom of the console console.drawRect(0, HEIGHT - 1, None, None, ' ') console.drawStr(0, HEIGHT - 1, 'MOUSEMOTION event - pos=%i,%i cell=%i,%i motion=%i,%i cellmotion=%i,%i' % (event.pos + event.cell + event.motion + event.cellmotion)) continue # prevent scrolling
""" import sys import code import textwrap import io import time import traceback sys.path.insert(0, '../') import tdl sys.ps1 = '>>> ' sys.ps2 = '... ' WIDTH, HEIGHT = 80, 50 console = tdl.init(WIDTH, HEIGHT, 'Python Interpeter in TDL') console.setMode('scroll') class TDLPrint(io.TextIOBase): def __init__(self, fgcolor=(255, 255, 255), bgcolor=(0, 0, 0)): self.colors = fgcolor, bgcolor def write(self, string): olderr.write(string) console.setColors(*self.colors) console.write(string) #sys.stdout = TDLPrint() sys.stdout = console sys.stdout.move(0, HEIGHT-1) olderr = newerr = sys.stderr