コード例 #1
0
 def __init__(
     self, game, width=200, height=200, seed=random.randint(1, 50000)
 ):
     self.game = game
     self.seed = seed
     self.timer, self.fps = 0, 15
     self.width, self.height = width, height
     self.bg_console = tdl.Console(width, height)
     self.path_console = tdl.Console(width, height)
     self.console = tdl.Console(width, height)
     self.window = tdl.Window(
         self.console,
         x=width // 2 - (game.width - 2) // 2,
         y=height // 2 - (game.height - 2) // 2,
         width=game.width - 2, height=game.height - 2
     )
     self.parameters = dict(
         pher_evap_rate=0.005,
         pher_amount_walk=0.05,
         pher_amount_refill=0.50,
         pher_sensitivity=5.,
         terrain_awareness=1.,
         max_pher=1.,
         rand_dir_chance=10
     )
     self.colonies = []
     self.generate_world()
     self.camera = Camera(
         self, x=width // 2, y=height // 2
     )
コード例 #2
0
ファイル: game.py プロジェクト: ninmonkey/roguelike-skeleton
    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))
コード例 #3
0
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
コード例 #4
0
ファイル: ipy_app.py プロジェクト: millejoh/Islands
 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()
コード例 #5
0
ファイル: char_finder.py プロジェクト: piger/pyro
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()
コード例 #6
0
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()
コード例 #7
0
    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 = []
コード例 #8
0
ファイル: menus.py プロジェクト: pinkjacket/dungeonpunk
def menu(con, root, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")

    header_wrapped = textwrap.wrap(header, width)
    header_height = len(header_wrapped)
    height = len(options) + header_height

    # off-screen console to represent menu window
    window = tdl.Console(width, height)

    # print header
    window.draw_rect(0, 0, width, height, None, fg=(255, 255, 255), bg=None)
    for i, line in enumerate(header_wrapped):
        window.draw_str(0, 0 + i, header_wrapped[i])

    y = header_height
    letter_index = ord("a")
    for option_text in options:
        text = "(" + chr(letter_index) + ") " + option_text
        window.draw_str(0, y, text, bg=None)
        y += 1
        letter_index += 1

    # blit the contents of "window" to root console
    x = screen_width // 2 - width // 2
    y = screen_height // 2 - width // 2
    root.blit(window, x, y, width, height, 0, 0)
コード例 #9
0
def controls_screen(display):
    controls_screen_width = 37
    controls_screen_height = 17

    window = tdl.Console(controls_screen_width, controls_screen_height)

    window.draw_rect(0, 0, controls_screen_width, controls_screen_height, None, fg=Colors.WHITE, bg=None)

    window.draw_str(1, 1, 'GENERAL CONTROLS FOR DUNGEON SPIRAL')

    window.draw_str(1, 3, 'Move: ARROWS, VIKEYS, NUMPAD')
    window.draw_str(1, 4, 'Wait: PERIOD, NUMPAD 5')
    window.draw_str(1, 5, 'View entity info: MOUSE HOVER')
    
    window.draw_str(1, 7, 'MENU CONRTOLS')

    window.draw_str(1, 9, 'Display inventory: I')
    window.draw_str(1, 10, 'Display character screen: C')
    window.draw_str(1, 11, 'Show vendor wares: S')
    window.draw_str(1, 12, 'Confirm targeting: L-CLICK')
    window.draw_str(1, 13, 'Cancel targeting: ESC or R-CLICK')

    window.draw_str(1, 15, 'Descend stairs: >')
    window.draw_str(1, 16, 'Save and quit: ESCAPE')
   
    x = display.SCREEN_WIDTH // 2 - controls_screen_width // 2
    y = display.SCREEN_HEIGHT // 2 - controls_screen_height // 2
    display.root_console.blit(window, x, y, controls_screen_width, controls_screen_height, 0, 0)
コード例 #10
0
def character_screen(display, player):
    char_screen_width = 30
    char_screen_height = 17

    window = tdl.Console(char_screen_width, char_screen_height)

    window.draw_rect(0, 0, char_screen_width, char_screen_height, None, fg=Colors.WHITE, bg=None)

    window.draw_str(1, 1, 'Name: {0}'.format(player.name))

    window.draw_str(1, 3, 'Level: {0}'.format(player.level.current_level))
    window.draw_str(1, 4, 'Experience: {0}'.format(player.level.current_xp))
    window.draw_str(1, 5, 'Experience to Level: {0}'.format(player.level.exp_to_next_level))
    
    window.draw_str(1, 7, 'BASE STAT(ADJUSTED STAT)')

    window.draw_str(1, 9, 'Max HP: {0}({1})'.format(player.fighter.base_max_hp, player.fighter.max_hp))
    window.draw_str(1, 10, 'Power: {0}({1})'.format(player.fighter.base_power, player.fighter.power))
    window.draw_str(1, 11, 'Defense: {0}({1})'.format(player.fighter.base_defense, player.fighter.defense))
    window.draw_str(1, 12, 'Accuracy: {0}({1})'.format(player.fighter.base_accuracy, player.fighter.accuracy))
    window.draw_str(1, 13, 'Armor: {0}({1})'.format(player.fighter.base_armor, player.fighter.armor))

    window.draw_str(1, 15, 'Light Radius: {0}({1})'.format(display.gmap.FOV_RADIUS, display.gmap.FOV_RADIUS + player.equipment.fov_bonus))
    window.draw_str(1, 16, 'Carrying Capacity: {0}({1})'.format(player.inventory.base_capacity, player.inventory.capacity))
   
    x = display.SCREEN_WIDTH // 2 - char_screen_width // 2
    y = display.SCREEN_HEIGHT // 2 - char_screen_height // 2
    display.root_console.blit(window, x, y, char_screen_width, char_screen_height, 0, 0)
コード例 #11
0
ファイル: menus.py プロジェクト: pinkjacket/dungeonpunk
def character_screen(root_console, player, character_screen_width,
                     character_screen_height, screen_width, screen_height):
    window = tdl.Console(character_screen_width, character_screen_height)

    window.draw_rect(0,
                     0,
                     character_screen_width,
                     character_screen_height,
                     None,
                     fg=(255, 255, 255),
                     bg=None)

    window.draw_str(0, 1, "Vital Statistics")
    window.draw_str(0, 2, "Level: {0}".format(player.level.current_level))
    window.draw_str(0, 3, "Experience: {0}".format(player.level.current_xp))
    window.draw_str(
        0, 4,
        "Next level in: {0}".format(player.level.experience_to_next_level))
    window.draw_str(0, 6, "Max HP: {0}".format(player.fighter.max_hp))
    window.draw_str(0, 7, "Attack: {0}".format(player.fighter.power))
    window.draw_str(0, 8, "Defense: {0}".format(player.fighter.defense))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    root_console.blit(window, x, y, character_screen_width,
                      character_screen_height, 0, 0)
コード例 #12
0
ファイル: menus.py プロジェクト: thomerickson/isolation-game
def menu(con, root, header, options, width, screen_width, screen_height):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

    # calc total height for the header and one line per option

    header_wrapped = textwrap.wrap(header, width)
    header_height = len(header_wrapped)
    height = len(options) + header_height + 1
    width += 2

    # create offscreen console that represents the menu's window
    window = tdl.Console(width, height)

    # print the header, with wrapped text
    window.draw_frame(0, 0, width, height, None, fg=None, bg=(120, 120, 120))
    window.draw_rect(1, 1, width-2, height-2, None, fg=None, bg=(40, 40, 40))
    for i, line in enumerate(header_wrapped):
        window.draw_str(1, 0+i, header_wrapped[i], fg=(0,0,0), bg=(120, 120, 120))

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        window.draw_str(1, y, text, fg=(180, 180, 180), bg=(40, 40, 40))
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = screen_width // 2 - width // 2
    y = screen_height // 2 - height // 2
    root.blit(window, x, y, width, height, 0, 0)
コード例 #13
0
ファイル: menu.py プロジェクト: veruz/roguelike_tutorial
def menu(con, root, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate total height for header/textwrap, one line per option
    header_wrapped = textwrap.wrap(header, width)
    header_height = len(header_wrapped)
    height = len(options) + header_height

    # create an off-screen console used as menu window
    window = tdl.Console(width, height)

    # print header, wrapped
    window.draw_rect(0, 0, width, height, None, fg=(255, 255, 255), bg=None)
    for i, line in enumerate(header_wrapped):
        window.draw_str(0, 0 + i, header_wrapped[i])

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        window.draw_str(0, y, text, bg=None)
        y += 1
        letter_index += 1

    # blit the contents of "window" to root
    x = screen_width // 2 - width // 2
    y = screen_height // 2 - height // 2
    root.blit(window, x, y, width, height, 0, 0)
コード例 #14
0
 def __init__(self, width, height, max_width, max_height, fg, bg):
     self.width = width
     self.height = height
     self.max_width = max_width
     self.max_height = max_height
     self.console = tdl.Console(self.max_width, self.max_height)
     self.console.set_colors(fg=fg, bg=bg)
コード例 #15
0
 def __init__(self, menu_width, menu_height):
     self.options = []
     self.console = tdl.Console(menu_width, menu_height)
     self.current_option = 0
     self.ACTION_KEYS = {'UP': 'up', 'DOWN': 'down', 'ENTER': 'select'}
     self.NORMAL_COLOR = (255, 255, 255)
     self.HIGHLIGHT_COLOR = (255, 255, 0)
コード例 #16
0
ファイル: menus.py プロジェクト: AndrewMFrey/RogueDev
def menu(con, root, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # Calculate total header height with one line per option (after text wrap)
    header_wrapped = textwrap.wrap(header, width)
    header_height = len(header_wrapped)
    height = len(options) + header_height

    # Create an off-screen console that represents the menu's window
    window = tdl.Console(width, height)

    # Print the header with wrapped text
    window.draw_rect(0, 0, width, height, None, fg=(255, 255, 255), bg=None)
    for i, line in enumerate(header_wrapped):
        window.draw_str(0, 0 + i, header_wrapped[i])

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        window.draw_str(0, y, text, bg=None)
        y += 1
        letter_index += 1

    # Blit the contents of the menu to the root console
    x = screen_width // 2 - width // 2
    y = screen_height // 2 - height // 2
    root.blit(window, x, y, width, height, 0, 0)
コード例 #17
0
 def __show_window(self, header, options, width):
     header_wrapped = textwrap.wrap(header, width)
     header_height = len(header_wrapped)
     height = len(options) + header_height
     window = tdl.Console(width, height)
     window.draw_rect(0,
                      0,
                      width,
                      height,
                      None,
                      fg=(255, 255, 255),
                      bg=None)
     for i, line in enumerate(header_wrapped):
         window.draw_str(0, 0 + i, header_wrapped[i])
     y = header_height
     letter_index = ord('a')
     for option_text in options:
         text = '(' + chr(letter_index) + ') ' + option_text
         window.draw_str(0, y, text, bg=None)
         y += 1
         letter_index += 1
     x = UISettings.screen_width // 2 - width // 2
     y = UISettings.screen_height // 2 - height // 2
     self.__root_console.blit(window, x, y, width, height, 0, 0)
     tdl.flush()
コード例 #18
0
ファイル: menus.py プロジェクト: Jaun7y/meishi
def character_screen(root_console, player, character_screen_width,
                     character_screen_height, screen_width, screen_height):
    window = tdl.Console(character_screen_width, character_screen_height)

    window.draw_rect(0,
                     0,
                     character_screen_width,
                     character_screen_height,
                     None,
                     fg=(255, 255, 255),
                     bg=None)

    window.draw_str(0, 1, 'Character Information')
    window.draw_str(0, 2, 'Level: {0}'.format(player.level.current_level))
    window.draw_str(0, 3, 'Experience: {0}'.format(player.level.current_xp))
    window.draw_str(
        0, 4, 'Experience to Level: {0}'.format(
            player.level.experience_to_next_level))
    window.draw_str(0, 6, 'Maximum HP: {0}'.format(player.fighter.max_hp))
    window.draw_str(0, 7, 'Attack: {0}'.format(player.fighter.power))
    window.draw_str(0, 8, 'Defense: {0}'.format(player.fighter.defense))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    root_console.blit(window, x, y, character_screen_width,
                      character_screen_height, 0, 0)
コード例 #19
0
ファイル: Game.py プロジェクト: ToonBlok/AsciiRpg
    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]
コード例 #20
0
def play_life(con, root, screen_width, screen_height, a):
    window = tdl.Console(screen_width, screen_height)

    alive = 0

    xmax, ymax = a.shape
    b = a.copy()  # copy grid & Rule 2

    window.draw_frame(0, 0, 52, 52, 177, fg=(50, 50, 255))

    for x in range(xmax):
        for y in range(ymax):
            n = numpy.sum(a[max(x - 1, 0):min(x + 2, xmax),
                            max(y - 1, 0):min(y + 2, ymax)]) - a[x, y]
            if a[x, y]:
                if n < 2 or n > 3:
                    b[x, y] = 0  # Rule 1 and 3
            elif n == 3:
                b[x, y] = 1  # Rule 4
            if b[x, y] == 1:
                alive += 1

                window.draw_char(x + 1,
                                 y + 1,
                                 176,
                                 fg=(200, 150, 100),
                                 bg=(0, 0, 100))
                window.draw_str(0, 53, "Living: " + str(alive),
                                (220, 180, 140))

    x = 0
    y = 0
    root.blit(window, x, y, 52, 54, 0, 0)

    return b
コード例 #21
0
    def animate(self, game_map, mouse_coordinates):
        if self.step >= self.duration:
            return {'done': True}
        else:
            cur_radius = math.ceil((self.step / self.duration) * self.radius)
            diameter = self.radius * 2

            window = tdl.Console(diameter, diameter)

            for x in range(0, diameter):
                for y in range(0, diameter):
                    if math.sqrt((x - self.radius)**2 +
                                 (y - self.radius)**2) <= cur_radius:
                        if game_map.fov[0 - self.radius + x + self.x,
                                        0 - self.radius + self.y +
                                        y] and game_map.transparent[
                                            0 - self.radius + x + self.x,
                                            0 - self.radius + self.y + y]:
                            window.draw_char(x, y, self.char, fg=self.color)
            self.root.blit(window,
                           self.x - self.radius,
                           self.y - self.radius,
                           diameter,
                           diameter,
                           0,
                           0,
                           fg_alpha=0.8,
                           bg_alpha=0.0)
            self.step += 1
        return {}
コード例 #22
0
    def animate(self, game_map, coords):
        if self.end == True:
            return {'done': True}
        self.x, self.y = coords

        print('animating targeting circle at coords' + str(self.x) +
              str(self.y))

        window = tdl.Console(self.diameter, self.diameter)

        for x in range(0, self.diameter):
            for y in range(0, self.diameter):
                if math.sqrt((x - self.radius)**2 +
                             (y - self.radius)**2) <= self.radius:
                    if game_map.fov[0 - self.radius + x + self.x,
                                    0 - self.radius + self.y +
                                    y] and game_map.transparent[
                                        0 - self.radius + x + self.x,
                                        0 - self.radius + self.y + y]:
                        window.draw_char(x, y, 'o', fg=self.color)
        self.root.blit(window,
                       self.x - self.radius,
                       self.y - self.radius,
                       self.diameter,
                       self.diameter,
                       0,
                       0,
                       fg_alpha=0.8,
                       bg_alpha=0)
        self.step += 1
        return {}
コード例 #23
0
def draw_colored_line(con, x, y, text, fg=None, bg=None):
    con = tdl.Console(2, 2)
    colored_words = []
    colors = []
    text_blocks = []
    
    n = 0
    for chara in text:
        if chara is "[":
            word = ""
            for charac in text[n+1:]:
                if charac is "]":
                    colored_words.append(word)
                    break
                else:
                    word += charac
            for charac in text[]
        elif chara is "{":
            word = ""
            for charac in text[n+1:]:
                if charac is "}":
                    colors.append(word)
                    break
                else:
                    word += charac
        n += 1
    # con.draw_str(x, y, text, fg, bg)
    return colored_words, colors
コード例 #24
0
ファイル: menus.py プロジェクト: Derric-S/Roguelike
def menu(con, root, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calc total height for header
    header_wrapped = textwrap.wrap(header, width)
    header_height = len(header_wrapped)
    height = len(options) + header_height

    # create console for menu's window
    window = tdl.Console(width, height)

    # print header
    window.draw_rect(0, 0, width, height, None, fg=colors.white, bg=None)
    for i, line in enumerate(header_wrapped):
        window.draw_str(0, 0 + i, header_wrapped[i])

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        window.draw_str(0, y, text, bg=None)
        y += 1
        letter_index += 1

    # blit window to root console
    x = screen_width // 2 - width // 2
    y = screen_height // 2 - height // 2
    root.blit(window, x, y, width, height, 0, 0)
コード例 #25
0
def control_screen(root_console, character_screen_width,
                   character_screen_height, screen_width, screen_height):
    window = tdl.Console(character_screen_width, character_screen_height)

    window.draw_str(0, 1, 'GAME CONTROLS - ESC/x to quit')
    window.draw_str(0, 2, 'W - Move Up')
    window.draw_str(0, 3, 'S - Move Down')
    window.draw_str(0, 4, 'A - Move Left')
    window.draw_str(0, 5, 'D - Move Right')

    window.draw_str(0, 7, 'I - Open Inventory (ESC to quit)')
    window.draw_str(0, 8, 'G - Pick-Up Item')
    window.draw_str(0, 9, 'R - Drop Item')

    window.draw_str(0, 11, 'STAIRS - Next Level')
    window.draw_str(0, 12, 'Shift + . - Go Down the Stairs')

    window.draw_str(0, 14, 'Store Controls')
    window.draw_str(0, 15, 'Q - Open Store/Quit Store')

    window.draw_str(0, 17, 'Character Information')
    window.draw_str(0, 18, 'C - Open/Close Character Info. Screen')

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    root_console.blit(window, x, y, character_screen_width,
                      character_screen_height, 0, 0)
コード例 #26
0
 def __init__(self, width, height, bar_width, bg=DIM_FG1):
     self.width = width
     self.height = height
     self.bar_width = bar_width
     self.msg_x = bar_width + 2
     self.bg = bg
     self.panel = tdl.Console(self.width, self.height)
コード例 #27
0
ファイル: rogue_test10.py プロジェクト: gruiick/pyRogue
def menu(header, options, width):
    """ """
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate total height for the header (after textwrap) and one
    # line per option
    header_wrapped = []
    for header_line in header.splitlines():
        header_wrapped.extend(textwrap.wrap(header_line, width))
    header_height = len(header_wrapped)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tdl.Console(width, height)

    window.draw_rect(0,
                     0,
                     width,
                     height,
                     None,
                     fg=roguecolors.white,
                     bg=roguecolors.dark_grey)
    # print the header, with wrapped text
    for i, line in enumerate(header_wrapped):
        window.draw_str(0, 0 + i, header_wrapped[i], bg=None)

    y = header_height
    # now, print each item, one by line
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        window.draw_str(0, y, text, bg=None)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = SCREEN_WIDTH // 2 - width // 2
    y = SCREEN_HEIGHT // 2 - height // 2
    root.blit(window, x, y, width, height, 0, 0)

    # present the root console to the player and wait for a key-press
    tdl.flush()
    key = tdl.event.key_wait()
    key_char = key.char
    if key_char == '':
        key_char = ' '  # placeholder

    if key.key == 'ENTER' and key.alt:  # Alt+Enter: toggle fullscreen
        tdl.set_fullscreen(not tdl.get_fullscreen())

    # convert the ASCII code to an index; if it corresponds to an
    # option, return it
    index = ord(key_char) - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
コード例 #28
0
    def __init__(self, x, y, width, height, title=''):
        super().__init__(' ', position=(x, y))

        self.width = width
        self.height = height
        self.data = tdl.Console(width, height)
        self.title = title
        self.always_show = True
コード例 #29
0
    def __init__(self, x=0, y=0, width=54, height=30):
        super().__init__(' ')
        self.position = x, y
        self.width = width
        self.height = height
        self.always_show = True

        self.console = tdl.Console(width, height)
コード例 #30
0
ファイル: window.py プロジェクト: sadovsky/dungeonrun
 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)