Beispiel #1
0
def storyScreen(console):
   libtcod.console_set_default_background(console, STORY_BACKGROUND_COLOUR1)
   libtcod.console_clear(console)
   
   done = False
   counter = 0
   blinkOn = True
   blinkSpeed = 10

   while not done and not libtcod.console_is_window_closed():
      key = libtcod.console_check_for_keypress(True)
      if not key.vk == libtcod.KEY_NONE:
         done = True

      #print the story message
      libtcod.console_set_default_foreground(console, STORY_FOREGROUND_COLOUR1)
      libtcod.console_print_rect(console, 1, 3, SCREEN_WIDTH, SCREEN_HEIGHT, STORY_TEXT1)
      if(blinkOn):
         libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3)
         libtcod.console_print_rect(console, 16, 22, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key")

      # blit the panel to the screen
      libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*1), 0, 0, 1)   
      
      libtcod.console_flush()

      counter += 1
      if counter >= blinkSpeed:
         counter = 0
         blinkOn = not blinkOn
         libtcod.console_clear(console)

   libtcod.console_clear(console)
Beispiel #2
0
def draw_stat_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(stat_con)
    libtcod.console_set_default_foreground(stat_con, libtcod.gold)
    libtcod.console_vline(stat_con, STAT_PANEL_WIDTH - 1, 0, STAT_PANEL_HEIGHT)
    libtcod.console_set_default_foreground(stat_con, old_foreground_color)

    # A string with a red over black word, using predefined color control codes
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red,
                                      libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.green,
                                      libtcod.black)
    libtcod.console_print(
        stat_con, 1, 1, "Position: %c(%s, %s)%c" %
        (libtcod.COLCTRL_1, player.x, player.y, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 2,
                          "Defense: %s" % player.fighter.defense)
    libtcod.console_print(stat_con, 1, 3, "Power: %s" % player.fighter.power)
    render_bar(stat_con, 1, 4, STAT_PANEL_WIDTH - 2, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.darker_green, libtcod.dark_red)
    libtcod.console_print(
        stat_con, 1, 5, "Mouse: %c(%s, %s)%c" %
        (libtcod.COLCTRL_1, mouse.cx - STAT_PANEL_WIDTH, mouse.cy,
         libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 7,
                          "Current depth: " + str(current_depth))
    libtcod.console_print(
        stat_con, 1, 10,
        "Mouse %ctarget%c:" % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
    libtcod.console_print_rect(stat_con, 1, 11, STAT_PANEL_WIDTH - 2, 0,
                               ("%c" + get_names_under_mouse() + "%c") %
                               (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
Beispiel #3
0
def character_description(typ, id):
	libtcod.console_set_default_foreground(0, libtcod.white)
	libtcod.console_set_default_background(0, libtcod.black)
	libtcod.console_rect(0, 1, 11, 52, 10, True, libtcod.BKGND_SET)
	if typ == 'race':
		libtcod.console_print_rect(0, 2, 12, 50, 10, game.RACE_DESC[id])
	if typ == 'class':
		libtcod.console_print_rect(0, 2, 12, 50, 10, game.CLASS_DESC[id])
Beispiel #4
0
 def render_bar(self, con, x, y, w, value, max_value, bar_bg_color, bar_fg_color, text_color):
   ratio = int(w*(float(value)/max_value))
   libtcod.console_set_default_background(con, bar_fg_color)
   libtcod.console_rect(con, x, y, ratio, 1, False, libtcod.BKGND_SET)
   libtcod.console_set_default_background(con, bar_bg_color)
   libtcod.console_rect(con, x+ratio, y, w-ratio, 1, False, libtcod.BKGND_SET)
   libtcod.console_set_default_background(con, text_color)
   libtcod.console_print_rect(con, x+1, y, w, 1, "%03d / %03d" % (value, max_value))
Beispiel #5
0
def menu(header, options, width, options_params=None):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate total height for the header (after auto-wrap)
    # and one line per option
    header_height = libtcod.console_get_height_rect(
        con, 0, 0, width, SCREEN_HEIGHT, header
    )
    height = len(options) + header_height

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

    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect(window, 0, 0, width, height, header)

    # print all the options
    y = header_height
    letter_index = ord('a')

    longest_text = 0

    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print(window, 0, y, text)
        y += 1
        letter_index += 1

        if len(text) > longest_text:
            longest_text = len(text)

    # draw a line between the letter and the option
    libtcod.console_vline(window, 3, header_height,
                          height, libtcod.BKGND_LIGHTEN)

    if options_params:
        y = header_height
        last_char_x = longest_text
        # draw a line between the letter and the option
        libtcod.console_vline(window, last_char_x, header_height,
                              height, libtcod.BKGND_LIGHTEN)
        for param in options_params:
            libtcod.console_print(window, last_char_x+1, y, str(param))
            y += 1
            if len(str(param)) > longest_text:
                longest_text = len(str(param))

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

    # present the root console to the player
    libtcod.console_flush()
Beispiel #6
0
def loadingScreen(console, message):
   libtcod.console_set_default_background(console, libtcod.Color(0, 0, 0))
   libtcod.console_clear(console)
 
   #print the splash messages
   libtcod.console_set_default_foreground(console, libtcod.Color(200, 200, 200))
   libtcod.console_print_rect(console, 4, 8, SCREEN_WIDTH, SCREEN_HEIGHT, message)

   # blit the panel to the screen
   libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*4), 0, 0, 4)   
   libtcod.console_flush()
Beispiel #7
0
def menu(header, options, width):
    global key
    global mouse

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options!')
    # Calculate total height for the header (after auto-wrap)
    # and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

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

    # Print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_set_alignment(window, libtcod.LEFT)
    libtcod.console_set_default_background(window, libtcod.BKGND_NONE)
    libtcod.console_print_rect(window, 0, 0, width, height, header)

    # Print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '({}) {}'.format(chr(letter_index), option_text)
        libtcod.console_print(window, 0, y, text)
        y += 1
        letter_index += 1

    # Blit the contents of "window" to the root console
    x = int(round(SCREEN_WIDTH / 2 - width / 2))
    y = int(round(SCREEN_HEIGHT / 2 - height / 2))
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    # Present the root console to the player and wait for a key-press
    libtcod.console_flush()

    libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, False)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
    #(special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    # Convert the ASCII code to an index; if it corresponds to an
    # option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #8
0
def menu(header, options, width):
    global key
    global mouse

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options!')
    # Calculate total height for the header (after auto-wrap)
    # and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

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

    # Print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_set_alignment(window, libtcod.LEFT)
    libtcod.console_set_default_background(window, libtcod.BKGND_NONE)
    libtcod.console_print_rect(window, 0, 0, width, height, header)

    # Print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '({}) {}'.format(chr(letter_index), option_text)
        libtcod.console_print(window, 0, y, text)
        y += 1
        letter_index += 1

    # Blit the contents of "window" to the root console
    x = int(round(SCREEN_WIDTH / 2 - width / 2))
    y = int(round(SCREEN_HEIGHT / 2 - height / 2))
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    # Present the root console to the player and wait for a key-press
    libtcod.console_flush()

    libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, False)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #(special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    # Convert the ASCII code to an index; if it corresponds to an
    # option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #9
0
def menu(header, options, width, highlighted=[]):
    """Basic, general-purpose menu.
    Allows the user to choose from up to 26 text options."""
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")
    # calculate total height for the header (after auto-wrap) and one line per
    # option
    if header == "":
        header_height = 0
    else:
        header_height = tcod.console_get_height_rect(0, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + header_height
    # create an off-screen console that represents the menu's window
    window = tcod.console_new(width, height)

    # print the header, with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect(window, 0, 0, width, height, header)
    # print all the options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        text = "(" + chr(letter_index) + ") " + option_text
        tcod.console_print(window, 0, y, text)
        y += 1
        letter_index += 1
    for index in highlighted:
        w = len(options[index]) + 4
        tcod.console_set_default_background(window, tcod.grey)
        y = index + header_height
        tcod.console_rect(window, 0, y, w, 1, False, flag=tcod.BKGND_SET)
    # blit the contents of "window" to the root console
    x = SCREEN_WIDTH // 2 - width // 2
    y = SCREEN_HEIGHT // 2 - height // 2
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
    # present the root console to the player and wait for a key-press
    tcod.console_flush()
    tcod.sys_wait_for_event(tcod.EVENT_KEY_PRESS, key, mouse, True)

    # special case: changing to/from fullscreen
    if key.vk == tcod.KEY_F11:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    elif key.vk == tcod.KEY_ESCAPE:
        return "escape"
    else:
        # convert the ASCII code to an index; if it corresponds to an option,
        # return it
        index = key.c - ord("a")
        if index >= 0 and index < len(options):
            return index
        return None
Beispiel #10
0
    def start_new_round(self, winner_of_last_round=None):
        """starts a new round of pong
        says who won, shows a countdown, moves the ball to the center, resets the players
        at the end, wipes the conway sim and resumes play """

        # lets do stuff in an off-screen console, so we can use transparency
        # so the player can see the map
        con = tcod.console_new(self.width, self.height)
        time_elapsed = 0.0  # in seconds
        x = self.width / 2
        tcod.console_set_alignment(con, tcod.CENTER)
        while self.alive and not tcod.console_is_window_closed() and \
                time_elapsed < 3.0:
            y = self.height / 2
            if winner_of_last_round:
                tcod.console_set_default_foreground(con,
                                                    winner_of_last_round.color)
                player_num = self.players.index(winner_of_last_round) + 1
                string = "Player %d scores!" % player_num
                height = tcod.console_get_height_rect(con, x, y, self.width,
                                                      self.height, string)
                tcod.console_print_rect(con, x, y, self.width, height, string)
                y += height
            tcod.console_set_default_foreground(con, tcod.white)

            string = "New round starting in %d seconds..." % int(3 - time_elapsed)
            height = tcod.console_get_height_rect(con, x, y, self.width,
                                                  self.height,  string)
            tcod.console_print_rect(con, x, y, self.width, height, string)

            self.handle_input()
            self.update_conway()
            self.render_all()
            tcod.console_blit(con, 0, 0, 0, 0, 0, 0, 0, 1.0, 0.75)
            tcod.console_flush()
            time_elapsed += tcod.sys_get_last_frame_length()


        # delete tcod console we created
        tcod.console_delete(con)

        #reset the ball
        self.ball = Ball(1, 1)

        #reset the player positions
        for player in self.players:
            player.top = self.height / 2

        # wipe the conway simulation (by creating a new one)
        self.init_map(self.conway.size, self.conway.color)
Beispiel #11
0
def test_console_printing(console, fg, bg):
    libtcodpy.console_set_background_flag(console,
                                          libtcodpy.BKGND_SET)
    assert (libtcodpy.console_get_background_flag(console) ==
                     libtcodpy.BKGND_SET)

    libtcodpy.console_set_alignment(console, libtcodpy.LEFT)
    assert (libtcodpy.console_get_alignment(console) ==
                     libtcodpy.LEFT)

    libtcodpy.console_print(console, 0, 0, 'print')
    libtcodpy.console_print_ex(console, 0, 0, libtcodpy.BKGND_SET,
                               libtcodpy.LEFT, 'print ex')

    assert (libtcodpy.console_print_rect(
        console, 0, 0, 8, 8, 'print rect') > 0
        )
    assert (libtcodpy.console_print_rect_ex(
        console, 0, 0, 8, 8, libtcodpy.BKGND_SET, libtcodpy.LEFT,
        'print rect ex') > 0
        )
    assert (libtcodpy.console_get_height_rect(
        console, 0, 0, 8, 8, 'get height') > 0
        )

    libtcodpy.console_set_color_control(libtcodpy.COLCTRL_1, fg, bg)
 def print_rec(self, layer):
     libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.turquoise, libtcod.black)
     libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.gray, libtcod.black)
     if not self.hidden:
         libtcod.console_print_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{:c}{}:{:c}".format(libtcod.COLCTRL_2, self.name, libtcod.COLCTRL_STOP))
         libtcod.console_print(result_display, Category.pc[0], Category.pc[1], "{:c}{}{:c}".format(libtcod.COLCTRL_3, '|' * layer, libtcod.COLCTRL_STOP))
         Category.pc[1] += libtcod.console_get_height_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{:c}{}:{:c}".format(libtcod.COLCTRL_2, self.name, libtcod.COLCTRL_STOP))
     glist = self.get()
     for g in glist:
         libtcod.console_print_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{}".format(g))
         libtcod.console_print(result_display, Category.pc[0], Category.pc[1], "{:c}{}{:c}".format(libtcod.COLCTRL_3, '|' * layer, libtcod.COLCTRL_STOP))
         Category.pc[1] += libtcod.console_print_rect(result_display, Category.pc[0] + layer, Category.pc[1], 30 - Category.pc[0], 30, "{}".format(g))
         for s in self.sub:
             s.print_rec(layer + 1)
     if not len(glist):
         for s in self.sub:
             s.print_rec(layer + 1)
Beispiel #13
0
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 auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

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

    #print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect(window, 0, 0, width, height, header)

    #print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        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
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    #present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ENTER and key.lalt:  # (special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    #convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #14
0
def pick_direction():
    (w, h) = (20, 2)
    window = tcod.console_new(w, h)
    tcod.console_set_default_foreground(window, tcod.white)
    text = "Pick a direction."
    tcod.console_print_rect(window, 0, 0, w, h, text)
    x = SCREEN_WIDTH // 2 - w // 2
    y = SCREEN_HEIGHT // 2 - h // 2
    tcod.console_blit(window, 0, 0, w, h, 0, x, y, 1.0, 0.7)
    tcod.console_flush()
    global key
    tcod.sys_wait_for_event(tcod.EVENT_KEY_PRESS, key, mouse, True)
    # special case: changing to/from fullscreen
    if key.vk == tcod.KEY_F11:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    else:
        key_pressed = game.get_key(key)
        if key_pressed in direction_keys:
            return direction_keys[key_pressed]
        elif key_pressed == tcod.KEY_ESCAPE or tcod.console_is_window_closed():
            return None
Beispiel #15
0
def renderAll(objects, player, con, panel, infobar):
   # draw objects without actors first
   for object in objects:
      if not object.actor:
         object.graphic.draw(con)
   for object in objects:
      if object.actor:
         object.graphic.draw(con)
   
   libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, GAME_HEIGHT, 0, 0, GAME_Y)

   # do panel stuff
   libtcod.console_set_default_background(panel, PANEL_BACKGROUND_COLOUR)
   libtcod.console_clear(panel)
 
   # print the current game message
   libtcod.console_set_default_foreground(panel, getMessageColour())
   libtcod.console_print_rect(panel, 1, 1, SCREEN_WIDTH-1, PANEL_HEIGHT, getMessage())
   
   # blit the panel to the screen
   libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)

   # do info bar stuff
   libtcod.console_set_default_background(infobar, INFO_BAR_BACKGROUND_COLOUR)
   libtcod.console_clear(infobar)
   
   # print their current money and the time
   libtcod.console_set_default_foreground(infobar, getMoneyColour(player.actor.money))
   libtcod.console_print_rect(infobar, SCREEN_WIDTH/2 - 3, 0, SCREEN_WIDTH, INFO_BAR_HEIGHT, "$"+str(player.actor.money))
   libtcod.console_set_default_foreground(infobar, getTimeColour())
   libtcod.console_print_rect(infobar, SCREEN_WIDTH/2 + 3, 0, SCREEN_WIDTH, INFO_BAR_HEIGHT, getTimeString())
   
   libtcod.console_blit(infobar, 0, 0, SCREEN_WIDTH, INFO_BAR_HEIGHT, 0, 0, INFO_BAR_Y)
Beispiel #16
0
def splashScreen(console):
   libtcod.console_set_default_background(console, SPLASH_BACKGROUND_COLOUR)
   libtcod.console_clear(console)
   
   done = False
   counter = 0
   blinkOn = True
   blinkSpeed = 10

   while not done and not libtcod.console_is_window_closed():
      key = libtcod.console_check_for_keypress(True)
      if not key.vk == libtcod.KEY_NONE:
         done = True

      #print the splash messages
      libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR1)
      libtcod.console_print_rect(console, 4, 5, SCREEN_WIDTH, SCREEN_HEIGHT, "SWORD SHOP")
      libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR2)
      libtcod.console_print_rect(console, 4, 8, SCREEN_WIDTH, SCREEN_HEIGHT, "by luke david\n   fitzpatrick")
      if(blinkOn):
         libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3)
         libtcod.console_print_rect(console, 16, 13, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key")

      # blit the panel to the screen
      libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*6), 0, 0, 6)   
      
      libtcod.console_flush()

      counter += 1
      if counter >= blinkSpeed:
         counter = 0
         blinkOn = not blinkOn
         libtcod.console_clear(console)
Beispiel #17
0
def draw_stat_panel():
    # draw the boundary of the panel with a gold line
    old_foreground_color = libtcod.console_get_default_foreground(stat_con)
    libtcod.console_set_default_foreground(stat_con, libtcod.gold)
    libtcod.console_vline(stat_con, STAT_PANEL_WIDTH - 1, 0, STAT_PANEL_HEIGHT)
    libtcod.console_set_default_foreground(stat_con, old_foreground_color)

    # A string with a red over black word, using predefined color control codes
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red, libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.green, libtcod.black)
    libtcod.console_print(stat_con, 1, 1,
                          "Position: %c(%s, %s)%c" % (libtcod.COLCTRL_1, player.x, player.y, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 2, "Defense: %s" % player.fighter.defense)
    libtcod.console_print(stat_con, 1, 3, "Power: %s" % player.fighter.power)
    render_bar(stat_con, 1, 4, STAT_PANEL_WIDTH - 2, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.darker_green, libtcod.dark_red)
    libtcod.console_print(stat_con, 1, 5, "Mouse: %c(%s, %s)%c" % (
        libtcod.COLCTRL_1, mouse.cx - STAT_PANEL_WIDTH, mouse.cy, libtcod.COLCTRL_STOP))
    libtcod.console_print(stat_con, 1, 7, "Current depth: " + str(current_depth))
    libtcod.console_print(stat_con, 1, 10, "Mouse %ctarget%c:" % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
    libtcod.console_print_rect(stat_con, 1, 11, STAT_PANEL_WIDTH - 2, 0,
                               ("%c" + get_names_under_mouse() + "%c") % (libtcod.COLCTRL_2, libtcod.COLCTRL_STOP))
Beispiel #18
0
	def menu(self, header, options, width, back_color=libtcod.black, fore_color=libtcod.white):

		if self.con is None: self.con = 0
		if len(options) > 26: raise ValueError('too many items')

		con = self.con

		header_height = libtcod.console_get_height_rect(con, 0,0, width, self.SCREEN_HEIGHT, header)
		height = len(options) + header_height
		window = libtcod.console_new(width, height)
		print 'window id is:', window
		print

		libtcod.console_set_default_foreground(window, fore_color)
		libtcod.console_print_rect(window, 0,0, width,height, header)

		y = header_height
		for option_text in zip('abcdefghijklmnopqrstuvwxyz', options):
			text = '(%s) %s' % option_text
			libtcod.console_print(window, 0, y, text)
			y += 1

		x = self.SCREEN_WIDTH/2 - width/2
		y = self.SCREEN_HEIGHT/2 - height/2
		libtcod.console_blit(window, 0,0, width,height, 0, x,y, 1.0, 0.9)

		key = libtcod.Key()
		mouse = libtcod.Mouse()
		libtcod.console_flush()
		libtcod.sys_wait_for_event(libtcod.KEY_PRESSED, key, mouse, True)

		libtcod.console_clear(window)
		libtcod.console_blit(window, 0,0, width,height, 0, x,y, 1.0, 0.9)
		libtcod.console_delete(window)
		libtcod.console_flush()

		index = key.c - ord('a')
		if index >= 0 and index < len(options): return index
		return None
Beispiel #19
0
 def draw(self, color=rl.white):
     oldColor = rl.console_get_default_foreground(0)  # Store old color.
     rl.console_set_default_foreground(0, color)  # Apply window's color.
     # Draw the corners.
     rl.console_put_char_ex(0, self.x, self.y, rl.CHAR_DNW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1, self.y, rl.CHAR_DNE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x, self.y + self.h - 1, rl.CHAR_DSW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1,
                            self.y + self.h - 1, rl.CHAR_DSE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     # Draw the walls.
     for i in range(self.y + 1, self.y + self.h - 1):
         rl.console_put_char_ex(0, self.x, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.x + 1, self.x + self.w - 1):
         rl.console_put_char_ex(0, i, self.y, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 1, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     if self.title != None:  # Draw the title, if present.
         rl.console_print(0, self.x + 2, self.y, " {0} ".format(self.title))
     rl.console_set_default_foreground(
         0, oldColor)  # Revert color before drawing rest of window.
     rl.console_print_rect(0, self.x + 2, self.y + 1, self.w - 4,
                           self.h - 2, self.text)  # Draw the inner text.
Beispiel #20
0
 def draw(self, color=rl.white):
     if self.subBox != None:  # If there is a sub-box, draw that instead.
         self.subBox.draw()
         return
     rl.console_rect(0, self.x, self.y, self.w, self.h,
                     True)  # Reset background color for the box.
     # Draw the corners.
     rl.console_put_char_ex(0, self.x, self.y, rl.CHAR_DNW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1, self.y, rl.CHAR_DNE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x, self.y + self.h - 1, rl.CHAR_DSW,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     rl.console_put_char_ex(0, self.x + self.w - 1,
                            self.y + self.h - 1, rl.CHAR_DSE,
                            rl.console_get_default_foreground(0),
                            rl.console_get_default_background(0))
     # Draw the walls.
     for i in range(self.y + 1, self.y + self.h - 1):
         rl.console_put_char_ex(0, self.x, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.y + 1, self.y + self.h - 4):
         rl.console_put_char_ex(0, self.dividerX, i, rl.CHAR_DVLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     for i in range(self.x + 1, self.x + self.w - 1):
         rl.console_put_char_ex(0, i, self.y, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 1, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, i, self.y + self.h - 4, rl.CHAR_DHLINE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         # Draw the dividing joints between sections.
         rl.console_put_char_ex(0, self.dividerX, self.y, rl.CHAR_DTEES,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.dividerX, self.y + self.h - 4,
                                rl.CHAR_DTEEN,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x, self.y + self.h - 4,
                                rl.CHAR_DTEEE,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
         rl.console_put_char_ex(0, self.x + self.w - 1, self.y + self.h - 4,
                                rl.CHAR_DTEEW,
                                rl.console_get_default_foreground(0),
                                rl.console_get_default_background(0))
     if self.title != None:  # Draw the title, if present.
         rl.console_print(0, self.x + 2, self.y, " {0} ".format(self.title))
     # Draw every option and its current value (or "..." if it leads to a new menu).
     for i, option in enumerate(
             self.menuObj[self.optOffset:min(self.optOffset +
                                             self.optCap, len(self.menuObj)
                                             )]):  # Draw the options.
         if option[0] == None:
             rl.console_print(0, self.x + 4, self.y + 1 + i,
                              option[3][0][3])
         else:
             rl.console_print(0, self.x + 4, self.y + 1 + i, option[0])
         if isinstance(option[3], list):
             rl.console_print(0, self.dividerX + 2, self.y + 1 + i, "...")
         else:
             rl.console_print(
                 0, self.dividerX + 2, self.y + 1 + i,
                 str(option[3])[0:min(len(str(option[3])), 76 -
                                      self.dividerX)])
     # Draw the description of the current option or the current input, whichever is needed.
     color = ""  # The color to draw the input in. Or more specifically, the ascii mid-string color change code. Since the default is white, by default nothing needs to be done here.
     if self.inputMode != "":
         if self.inputIsValid(
                 self.currentInput, self.menuObj[self.selectedOption][1],
                 self.menuObj[self.selectedOption]
             [4]) == False:  # If the input isn't valid, make the color red.
             color = chr(rl.COLCTRL_FORE_RGB) + chr(255) + chr(64) + chr(64)
         if self.inputMode == "Text":
             rl.console_print(
                 0, 2, self.y + self.h - 3,
                 "Input the new value. Max length is {0}\n{2}{1}{3}".format(
                     self.menuObj[self.selectedOption][4],
                     self.currentInput[
                         self.inputOffset:min(self.inputOffset +
                                              76, len(self.currentInput))],
                     color, chr(rl.COLCTRL_STOP)))
         elif self.inputMode == "Number":
             rl.console_print(
                 0, 2, self.y + self.h - 3,
                 "Input the new value. Max value is {0}\n{2}{1}{3}".format(
                     self.menuObj[self.selectedOption][4],
                     self.currentInput[
                         self.inputOffset:min(self.inputOffset +
                                              76, len(self.currentInput))],
                     color, chr(rl.COLCTRL_STOP)))
     else:
         rl.console_print_rect(0, 2, self.y + self.h - 3, 76, 2,
                               self.menuObj[self.selectedOption][2])
         rl.console_print(0, self.x + 2,
                          self.y + 1 + self.selectedOption - self.optOffset,
                          chr(rl.CHAR_ARROW2_E))
     # Draw input cursor.
     if self.inputMode != "":
         rl.console_set_char_background(
             0, 2 + self.cursorPos - self.inputOffset, self.y + self.h - 2,
             rl.white)
         rl.console_set_char_foreground(
             0, 2 + self.cursorPos - self.inputOffset, self.y + self.h - 2,
             rl.black)
     # Draw scroll arrows as needed.
     if int(time.clock() * 2) % 2 == 0:
         if self.optOffset > 0:
             rl.console_print(0, self.x + int(self.w / 2), self.y,
                              chr(rl.CHAR_ARROW2_N))
         if self.optOffset + self.optCap < len(self.menuObj):
             rl.console_print(0, self.x + int(self.w / 2),
                              self.y + self.h - 1, chr(rl.CHAR_ARROW2_S))
         if self.inputOffset > 0:
             rl.console_print(0, self.x, self.y + self.h - 2,
                              chr(rl.CHAR_ARROW2_W))
         if self.inputOffset < len(self.currentInput) - 75:
             rl.console_print(0, self.x + self.w - 1, self.y + self.h - 2,
                              chr(rl.CHAR_ARROW2_E))
Beispiel #21
0
 def update(self):
     self.add_border()
     libtcod.console_print_rect(self.dialog_con, 1, 1, self.width - 2,
                                self.height, self.prompt_text)
     libtcod.console_blit(self.dialog_con, 0, 0, 0, 0, self.target_con,
                          self.x, self.y)
Beispiel #22
0
 def refresh(self):
     # First, handle the flow of combat or the active animation.
     if self.animPhase == 2: # If the blinking box phase is active, handle that.
         if time.time() >= self.animStarted + 0.5: # If a second has passed since this animation phase started, end it.
             self.animPhase = 0
             if self.checkBattleStatus() != None: # If the battle is won or lost, change the current scene.
                 return self.checkBattleStatus()
             self.advanceTurn() # Move to the next turn.
     else: # If there is no animation going on, handle the flow of combat.
         if self.turnOrder[0].isAI(): # If it's an enemy's turn, act according to their AI.
             self.parseTurnResults(self.turnOrder[0].aiAct(self.party,self.enemies)) # Execute the enemy AI, thne add the result to the log.
         elif len(self.moveBoxes) == 0: # Otherwise, it must be the player's turn. If there aren't any move boxes open, open one.
             self.moveBoxes.append(bx.SelectBox(22,3,-1,-1,None,self.turnOrder[0].getOptions(),-1))
     # Now on to the actual display.
     rl.console_clear(0) # Fill the window with the background color.
     for i,box in enumerate(self.partyBoxes): # Display the party boxes. Only the boxes themselves for now.
         if len(self.party) <= i or self.party[i].isDead(): # Draw a gray box if party member is not present or dead.
             box.draw(rl.darker_gray)
         else: # Otherwise, draw normal stats, aside from the bars.
             rl.console_print(0, 12, i*6+1, self.party[i].getHPLine()) # Draw HP.
             rl.console_print(0, 12, i*6+2, self.party[i].getAPLine()) # Draw AP.
             rl.console_print(0, 12, i*6+3, self.party[i].getMPLine()) # Draw MP.
             rl.console_print(0, 2, i*6+4, self.party[i].getStatusLine(18)) # Draw status effects.
         if len(self.party) <= i or self.party[i].getHP() <= 0: # Draw a red box if party member is unconscious.
             box.draw(rl.darker_red)
         elif self.animPhase == 2 and (self.animTarget == i or self.animTarget == ALL_ALLIES) and int((time.time() - self.animStarted) * 8) % 2 == 0: # If the current animPhase is 2, this is the current animation target, and the time since the animation started dictates the box should be dark red, make it dark red.
             pass
         else: # Otherwise, draw the normal party box.
             box.draw(rl.sky)
     for i,box in enumerate(self.enemyBoxes): # Display the enemy boxes. Only the boxes themselves for now.
         if len(self.enemies) <= i or self.enemies[i].getHP() <= 0: # Draw a gray box if enemy is not present or KO'd.
             box.draw(rl.darker_gray)
         elif self.animPhase == 2 and (self.animTarget - 4 == i or self.animTarget == ALL_ENEMIES) and int((time.time() - self.animStarted) * 8) % 2 == 0: # If the current animPhase is 2, this is the current animation target, and the time since the animation started dictates the box should be dark red, make it dark red.
             rl.console_print(0, 61, i*4+2, self.enemies[i].getStatusLine(18)) # Draw status effects.
         else:
             box.draw(rl.crimson) # Otherwise, draw the normal party box.
             rl.console_print(0, 61, i*4+2, self.enemies[i].getStatusLine(18)) # Draw status effects.
     self.infoBox.draw(rl.white) # Draw the combat log box.
     self.turnBox.draw(rl.white) # Draw the X's Turn box.
     rl.console_print_ex(0, 31, 1, rl.BKGND_NONE, rl.CENTER, "{0}".format(self.turnOrder[0].getColoredName())) # Draw whose turn it is.
     numBattlers = 0 # The number of conscious actors in the fight that will be shown in the turn order box (as such, this should never exceed 7).
     actorList = "" # The list of conscious actors in the fight, in the order they appear in turnOrder.
     for actor in self.turnOrder: # For each actor...
         if numBattlers < 8 and actor.getHP() > 0: # If they're conscious and the turn order box isn't already filled up...
             numBattlers += 1 # Increase the size of the box by one.
             actorList += actor.getColoredName()+"\n" # Add the battler to the list.
     self.turnOrderBox.setHeight(numBattlers+2) # Adjust the turn order box's size to match the amount of conscious battlers.
     self.turnOrderBox.draw(rl.white) # Draw the turn order box.
     rl.console_set_char(0, 42, 1, ">") # Draw the cursor in the turn order box. Purely aesthetic.
     rl.console_print(0, 44, 1, actorList) # Draw the list of conscious battlers in the turn order box.
     y = 11 # The line to draw the current log entry at.
     for msg in self.log: # Draw the lines of the log, advancing y as appropriate.
         rl.console_set_char(0, 24, y, ">") # Draw something to indicate when a log line starts. This ensures it is clear when one entry ends and a new one begins.
         rl.console_print_rect(0, 26, y, 31, 12, msg) # Draw the log line.
         y += rl.console_get_height_rect(0, 0, 0, 31, 12, msg) # Lower the y coordinate.
     # Once all that is drawn, draw the background image.
     rl.image_blit_rect(self.image, 0, 0, 0, 80, 24, rl.BKGND_SET) # Display the battle background image.
     rl.console_set_default_foreground(0, rl.white) # Sets the foreground (text) color to white.
     rl.console_set_default_background(0, rl.black) # Sets the background color to black.
     # However, only after that should the actual stats be drawn. This is so the life bar backgrounds can override the background image.
     for i,box in enumerate(self.partyBoxes): # Display the party boxes.
         if not len(self.party) <= i and not self.party[i].isDead(): # Don't draw stats if party member is not present or dead (should still show if merely KO'd.
             rl.console_print(0, 2, i*6+1, self.party[i].getHPBar()) # Draw HP bar.
             rl.console_print(0, 2, i*6+2, self.party[i].getAPBar()) # Draw AP bar.
             rl.console_print(0, 2, i*6+3, self.party[i].getMPBar()) # Draw MP bar.
     for i,box in enumerate(self.enemyBoxes): # Display the enemy boxes.
         if not len(self.enemies) <= i and not self.enemies[i].getHP() <= 0: # Don't draw stats if enemy is not present or KO'd.
             rl.console_print(0, 61, i*4+1, self.enemies[i].getHPBar()) # Draw HP bar.
             rl.console_print(0, 67, i*4+1, self.enemies[i].getAPBar()) # Draw AP bar.
             rl.console_print(0, 73, i*4+1, self.enemies[i].getMPBar()) # Draw MP bar.
     for i,box in enumerate(self.moveBoxes): # Draw all the move boxes, the current one being yellow. Since this can overlap the enemy stats, this must be drawn after that.
         if i+1 == len(self.moveBoxes):
             box.draw(rl.yellow)
         else:
             box.draw(rl.white)
Beispiel #23
0
    def print_description(self, console, x, y, width):
        print_height = 1
        if self.str_requirement != 0:
            if player.instance.player_stats.str < self.str_requirement:
                libtcod.console_set_default_foreground(console, libtcod.red)
            else:
                libtcod.console_set_default_foreground(console,
                                                       libtcod.dark_green)
            libtcod.console_print(
                console, x, y + print_height,
                'Strength Required: ' + str(self.str_requirement))
            print_height += 1
            libtcod.console_set_default_foreground(console, libtcod.white)
        libtcod.console_print(console, x, y + print_height,
                              'Slot: ' + self.slot)
        print_height += 1
        if self.subtype is not None:
            libtcod.console_print(console, x, y + print_height,
                                  'Category: ' + self.subtype)
            print_height += 1
        print_height += 1
        if self.level_progression is not None and self.level_progression != 0:
            libtcod.console_print(
                console, x, y + print_height,
                'Level: ' + str(self.level) + '/' + str(self.max_level))
            print_height += 1
        if self.armor_bonus != 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Armor: ' + str(self.armor_bonus))
            print_height += 1
        if self.weapon_dice is not None and self.weapon_dice != '0d0':
            r = main.dice_range(self.weapon_dice, normalize_size=4)
            libtcod.console_print(console, x, y + print_height,
                                  'Damage: ' + str(r[0]) + '-' + str(r[1]))
            print_height += 1
        if self.str_dice is not None and self.str_dice > 0:
            r = main.dice_range(str(self.str_dice) + 'd' +
                                str(player.instance.player_stats.str),
                                normalize_size=4)
            libtcod.console_print(
                console, x, y + print_height,
                'Strength Bonus: ' + str(r[0]) + '-' + str(r[1]))
            print_height += 1
        if self.accuracy_bonus != 0:
            acc_str = 'Accuracy: '
            if self.accuracy_bonus > 0:
                acc_str += '+'
            libtcod.console_print(console, x, y + print_height,
                                  acc_str + str(self.accuracy_bonus))
            print_height += 1
        if self.crit_bonus != 1.0:
            acc_str = 'Crit: x'
            libtcod.console_print(console, x, y + print_height,
                                  acc_str + str(self.crit_bonus))
            print_height += 1
        if self.attack_delay != 0:
            attacks = max(
                round(
                    float(player.instance.fighter.attack_speed()) /
                    float(self.attack_delay), 1), 1.0)
            libtcod.console_print(console, x, y + print_height,
                                  'Attack Speed: ' + str(attacks))
            print_height += 1
        if self.evasion_bonus != 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Evade: ' + str(self.evasion_bonus))
            print_height += 1
        if self.guaranteed_shred_bonus != 0:
            libtcod.console_print(
                console, x, y + print_height,
                'Auto-shred: ' + str(self.guaranteed_shred_bonus))
            print_height += 1
        if self.max_hp_bonus != 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Bonus HP: ' + str(self.max_hp_bonus))
            print_height += 1
        if self.pierce_bonus != 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Pierce: ' + str(self.pierce_bonus))
            print_height += 1
        if self.shred_bonus != 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Shred: ' + str(self.shred_bonus))
            print_height += 1
        if self.spell_power_bonus != 0:
            libtcod.console_print(
                console, x, y + print_height,
                'Spell Power: ' + str(self.spell_power_bonus))
            print_height += 1
        if self.spell_resist_bonus != 0:
            libtcod.console_print(
                console, x, y + print_height,
                'Spell Resist: ' + str(self.spell_resist_bonus))
            print_height += 1
        if self.sh_max > 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Shield: ' + str(self.sh_max))
            print_height += 1
        if self.sh_recovery > 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Recovery Time: ' + str(self.sh_recovery))
            print_height += 1
        if self.sh_raise_cost > 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Raise Cost: ' + str(self.sh_raise_cost))
            print_height += 1
        if self.weight != 0:
            libtcod.console_print(console, x, y + print_height,
                                  'Weight: ' + str(self.weight))
            print_height += 1
        if self.break_chance > 0:
            libtcod.console_print(
                console, x, y + print_height, 'It has a ' +
                str(self.break_chance) + '%%' + ' chance to break when used.')
            print_height += 1
        for r in self.resistances:
            libtcod.console_print(console, x, y + print_height,
                                  'Resist %s' % r)
            print_height += 1
        if self.ctrl_attack_desc:
            libtcod.console_set_default_foreground(console, libtcod.azure)
            text = 'Ctrl+attack: ' + self.ctrl_attack_desc
            h = libtcod.console_get_height_rect(console, x,
                                                y + print_height, width,
                                                main.SCREEN_HEIGHT(), text)
            libtcod.console_print_rect(console, x, y + print_height + 1, width,
                                       h, text)
            print_height += h + 1
            libtcod.console_set_default_foreground(console, libtcod.white)
        if hasattr(self, 'spell_list') and self.spell_list is not None:
            libtcod.console_set_default_foreground(console, libtcod.azure)
            libtcod.console_print(console, x, y + print_height, 'Spells:')
            libtcod.console_set_default_foreground(console, libtcod.white)
            for spell in self.flat_spell_list:
                level = self.spell_list[
                    spell]  # dictionaries don't preserve order - flat lists do
                spell_data = spells.library[spell]
                if level == 0:
                    libtcod.console_set_default_foreground(
                        console, libtcod.gray)
                libtcod.console_print(
                    console, x, y + print_height,
                    "- " + spell_data.name.title() + " " + str(level) + "/" +
                    str(spell_data.max_level))
                libtcod.console_set_default_foreground(console, libtcod.white)
                print_height += 1

        return print_height
Beispiel #24
0
def look():
	game.message.new('Looking... (Arrow keys to move cursor, ESC to exit)', game.turns)
	util.render_map()
	dx = game.char.x - game.curx
	dy = game.char.y - game.cury
	key = libtcod.Key()

	while not libtcod.console_is_window_closed():
		libtcod.console_set_default_background(0, libtcod.white)
		libtcod.console_rect(0, game.MAP_X + dx, dy + 1, 1, 1, False, libtcod.BKGND_SET)
		libtcod.console_flush()
		text = ""

		libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
		dx, dy = key_check(key, dx, dy)
		if key.vk == libtcod.KEY_ESCAPE:
			del game.message.log[len(game.message.log) - 1]
			util.render_message_panel()
			break

		if dx < 0:
			dx = 0
		if dy < 0:
			dy = 0
		if dx == game.MAP_WIDTH:
			dx -= 1
		if dy == game.MAP_HEIGHT:
			dy -= 1
		px = dx + game.curx
		py = dy + game.cury

		# create a list with the names of all objects at the cursor coordinates
		if dx in range(game.MAP_WIDTH - 1) and dy in range(game.MAP_HEIGHT - 1) and game.current_map.tile_is_explored(px, py):
			names = [obj for obj in game.current_map.objects if obj.x == px and obj.y == py]
			prefix = 'you see '
			if not libtcod.map_is_in_fov(game.fov_map, px, py):
				prefix = 'you remember seeing '
				for i in range(len(names) - 1, -1, -1):
					if names[i].entity is not None:
						names.pop(i)
			if (px, py) == (game.char.x, game.char.y):
				text = 'you see yourself'
			elif names == []:
				if game.current_map.tile_is_invisible(px, py):
					text = prefix + 'a floor'
				else:
					text = prefix + game.current_map.tile[px][py]['article'] + game.current_map.tile[px][py]['name']
			elif len(names) > 1:
				text = prefix
				for i in range(len(names)):
					if i == len(names) - 1:
						text += ' and '
					elif i > 0:
						text += ', '
					if names[i].item is not None:
						text += names[i].item.get_name(True)
					if names[i].entity is not None:
						text += names[i].entity.get_name(True)
			else:
				if names[0].item is not None:
					text = prefix + names[0].item.get_name(True)
				if names[0].entity is not None:
					text = prefix + names[0].entity.get_name(True)

		libtcod.console_set_default_foreground(game.con, libtcod.light_yellow)
		libtcod.console_rect(game.con, 0, 0, game.MAP_WIDTH, 2, True, libtcod.BKGND_NONE)
		libtcod.console_print_rect(game.con, 0, 0, game.MAP_WIDTH - 18, game.MAP_HEIGHT, text)
		libtcod.console_blit(game.con, 0, 0, game.MAP_WIDTH, game.MAP_HEIGHT, 0, game.MAP_X, game.MAP_Y)
	game.draw_map = True
Beispiel #25
0
 def console_print_rect(self,con,x,y,width,height,fmt):
     if con == 0:
         libtcod.console_print_rect(con,x,y,width,height,fmt)
     else:
         libtcod.console_print_rect(self.mConsole[con-1],x,y,width,height,fmt)
Beispiel #26
0
def handle_keys():
    global farm, key, mouse, panel_console, show_panel, entities
 
    if key.vk != libtcod.KEY_NONE:
        viewport_dx = 0
        viewport_dy = 0

        # vertical movement
        for case in switch(key.vk):
            if case(libtcod.KEY_UP): pass
            if case(libtcod.KEY_KP8): pass
            if case(libtcod.KEY_HOME): pass
            if case(libtcod.KEY_KP7): pass
            if case(libtcod.KEY_PAGEUP): pass
            if case(libtcod.KEY_KP9):
                viewport_dy -= 1
                break
            if case(libtcod.KEY_DOWN): pass
            if case(libtcod.KEY_KP2): pass
            if case(libtcod.KEY_END): pass
            if case(libtcod.KEY_KP1): pass
            if case(libtcod.KEY_PAGEDOWN): pass
            if case(libtcod.KEY_KP3):
                viewport_dy += 1
                break

        # horizontal movement
        for case in switch(key.vk):
            if case(libtcod.KEY_LEFT): pass
            if case(libtcod.KEY_KP4): pass
            if case(libtcod.KEY_HOME): pass
            if case(libtcod.KEY_KP7): pass
            if case(libtcod.KEY_END): pass
            if case(libtcod.KEY_KP1):
                viewport_dx -= 1
                break
            if case(libtcod.KEY_RIGHT): pass
            if case(libtcod.KEY_KP6): pass
            if case(libtcod.KEY_PAGEUP): pass
            if case(libtcod.KEY_KP9): pass
            if case(libtcod.KEY_PAGEDOWN): pass
            if case(libtcod.KEY_KP3):
                viewport_dx += 1
                break

        if viewport_dx != 0 or viewport_dy != 0:
            farm.viewport.move(viewport_dx, viewport_dy)

        if key.vk == libtcod.KEY_ESCAPE:
            return True  #exit game
        elif key.vk == libtcod.KEY_BACKSPACE and (key.lctrl or key.rctrl):
            farm.generate()
            entities = []
            place_ants(3)
            farm.place_entities(entities)
        else:
            key_char = chr(key.c)
            for case in switch(key_char):
                if case('i'):
                    show_panel = not show_panel

    if mouse.lbutton_pressed:
        (x,y) = (mouse.cx + farm.viewport.x, mouse.cy + farm.viewport.y)
        entity_list = []

        # Check for an ant?
        for entity in entities:
            if entity.x == x and entity.y == y:
                entity_list.append(str.format("{}\n---------------\nAnt ID: {}\nPosition: ({},{})\nState: {}", entity.name, id(entity), x, y, entity.state))

        if len(entity_list) != 0:
            libtcod.console_clear(panel_console)
            libtcod.console_print_rect(panel_console, 2, 2, PANEL_WIDTH-4, 10, "\n\n".join(entity_list))
Beispiel #27
0
def render_map():
	# recompute FOV if needed (the player moved or something)
	libtcod.console_rect(0, game.MAP_X, game.MAP_Y, game.MAP_WIDTH, game.MAP_HEIGHT, True)
	if game.fov_recompute:
		find_map_viewport()
		fov_radius()
		initialize_fov(True)
		libtcod.map_compute_fov(game.fov_map, game.char.x, game.char.y, game.FOV_RADIUS, game.FOV_LIGHT_WALLS, game.FOV_ALGO)
		game.fov_recompute = False

	# 'torch' animation
	if game.fov_torch:
		game.fov_torchx += 0.2
		tdx = [game.fov_torchx + 20.0]
		dx = libtcod.noise_get(game.fov_noise, tdx, libtcod.NOISE_SIMPLEX) * 1.5
		tdx[0] += 30.0
		dy = libtcod.noise_get(game.fov_noise, tdx, libtcod.NOISE_SIMPLEX) * 1.5
		di = 0.4 * libtcod.noise_get(game.fov_noise, [game.fov_torchx], libtcod.NOISE_SIMPLEX)

	# go through all tiles, and set their background color according to the FOV
	for y in range(game.MAP_HEIGHT):
		for x in range(game.MAP_WIDTH):
			px = x + game.curx
			py = y + game.cury
			if not libtcod.map_is_in_fov(game.fov_map, px, py):
				if game.draw_map and game.current_map.tile_is_explored(px, py):
					if game.current_map.tile_is_animated(px, py):
						libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['dark_color'], game.current_map.tile[px][py]['dark_back_color'])
					else:
						libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['dark_color'], game.current_map.tile[px][py]['back_dark_color'])
			else:
				if not game.fov_torch:
					if 'animate' in game.current_map.tile[px][py] or 'duration' in game.current_map.tile[px][py]:
						(front, back, game.current_map.tile[px][py]['lerp']) = render_tiles_animations(px, py, game.current_map.tile[px][py]['color'], game.current_map.tile[px][py]['back_light_color'], game.current_map.tile[px][py]['back_dark_color'], game.current_map.tile[px][py]['lerp'])
						libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], front, back)
					elif game.draw_map:
						libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['color'], game.current_map.tile[px][py]['back_light_color'])
				else:
					base = game.current_map.tile[px][py]['back_light_color']
					r = float(px - game.char.x + dx) * (px - game.char.x + dx) + (py - game.char.y + dy) * (py - game.char.y + dy)
					if r < game.SQUARED_TORCH_RADIUS:
						l = (game.SQUARED_TORCH_RADIUS - r) / game.SQUARED_TORCH_RADIUS + di
						if l < 0.0:
							l = 0.0
						elif l > 1.0:
							l = 1.0
						base = libtcod.color_lerp(base, libtcod.gold, l)
					libtcod.console_put_char_ex(game.con, x, y, game.current_map.tile[px][py]['icon'], game.current_map.tile[px][py]['color'], base)
				if not game.current_map.tile_is_explored(px, py):
					game.current_map.tile[px][py].update({'explored': True})

	# draw all objects in the map (if in the map viewport), except the player who his drawn last
	for obj in reversed(game.current_map.objects):
		if obj.y in range(game.cury, game.cury + game.MAP_HEIGHT) and obj.x in range(game.curx, game.curx + game.MAP_WIDTH) and game.current_map.tile_is_explored(obj.x, obj.y) and obj.name != 'player':
			if game.draw_map and obj.entity is not None:
				if libtcod.map_is_in_fov(game.fov_map, obj.x, obj.y) and not obj.entity.is_identified():
					skill = game.player.find_skill('Mythology')
					if (game.player.skills[skill].level * 0.8) + 20 >= roll_dice(1, 100):
						obj.entity.flags.append('identified')
						game.message.new('You properly identify the ' + obj.entity.unidentified_name + ' as ' + obj.entity.get_name(True) + '.', game.turns)
						game.player.skills[skill].gain_xp(3)
			if obj.entity is not None and not obj.entity.is_identified():
				obj.draw(game.con, libtcod.white)
			else:
				obj.draw(game.con)
	game.char.draw(game.con)
	libtcod.console_blit(game.con, 0, 0, game.MAP_WIDTH, game.MAP_HEIGHT, 0, game.MAP_X, game.MAP_Y)
	game.draw_map = False

	# move the player if using mouse
	if game.mouse_move:
		if mouse_auto_move() and not libtcod.path_is_empty(game.path):
			game.char.x, game.char.y = libtcod.path_walk(game.path, True)
			game.fov_recompute = True
			game.player_move = True
		else:
			items_at_feet()
			game.mouse_move = False

	# check where is the mouse cursor if not in the act of moving while using the mouse
	if not game.mouse_move:
		(mx, my) = (game.mouse.cx - game.MAP_X, game.mouse.cy - 1)
		px = mx + game.curx
		py = my + game.cury
		game.path_dx = -1
		game.path_dy = -1
		if my in range(game.MAP_HEIGHT) and mx in range(game.MAP_WIDTH):
			libtcod.console_set_char_background(0, mx + game.MAP_X, my + 1, libtcod.white, libtcod.BKGND_SET)
			if game.current_map.tile_is_explored(px, py) and not game.current_map.tile_is_blocked(px, py):
				game.path_dx = px
				game.path_dy = py
				if game.mouse.lbutton_pressed:
					target = [obj for obj in game.current_map.objects if obj.y == py and obj.x == px and obj.entity]
					if target:
						mouse_auto_attack(px, py, target[0])
					else:
						game.mouse_move = mouse_auto_move()
				# draw a line between the player and the mouse cursor
				if not game.current_map.tile_is_blocked(game.path_dx, game.path_dy):
					libtcod.path_compute(game.path, game.char.x, game.char.y, game.path_dx, game.path_dy)
					for i in range(libtcod.path_size(game.path)):
						x, y = libtcod.path_get(game.path, i)
						if (y - game.cury) in range(game.MAP_HEIGHT) and (x - game.curx) in range(game.MAP_WIDTH):
							libtcod.console_set_char_background(0, game.MAP_X + x - game.curx, game.MAP_Y + y - game.cury, libtcod.desaturated_yellow, libtcod.BKGND_SET)

	libtcod.console_set_default_foreground(0, libtcod.light_yellow)
	libtcod.console_print_rect(0, game.MAP_X, game.MAP_Y, game.MAP_WIDTH - 18, game.MAP_HEIGHT, get_names_under_mouse())
	if game.debug.enable:
		libtcod.console_print_ex(0, game.MAP_X + game.MAP_WIDTH - 1, game.MAP_Y, libtcod.BKGND_NONE, libtcod.RIGHT, str(game.gametime.hour) + ':' + str(game.gametime.minute).rjust(2, '0') + ' (%3d fps)' % libtcod.sys_get_fps())
	if game.hp_anim:
		render_floating_text_animations()
Beispiel #28
0
 def write_wrap(self, x, y, w, h, txt):
     libtcodpy.console_print_rect(self._panel, x, y, w, h, txt)
Beispiel #29
0
 def paragraph(self, text):
     self.line += libtcod.console_print_rect(0, 10, self.line, TEXT_WIDTH,
                                             0, text)
     self.line += 1
Beispiel #30
0
def char_info_window(c):
    # c == character
    width = CHAR_INFO_WIDTH

    header = "Character Information"

    char_attrs = [
        ('Name', c.name),
        ('Level', c.level),
        ('XP', c.xp)
    ]
    if c.combatant:
        combat_attrs = [
            ('HP', c.combatant.hp),
            ('Max HP', c.combatant.max_hp),
            ('Attack power', c.combatant.power),
            ('Defense power', c.combatant.defense)
        ]
    if c.caster:
        caster_attrs = [
            ('MP', c.caster.mp),
            ('Max MP', c.caster.max_mp),
            ('Hot/Cold factor', c.caster.hot_cold),
            ('Wet/Dry factor', c.caster.wet_dry)
        ]

    # calculate total height for the header
    # (after auto-wrap) and one line per attr,
    # plus 2 for each section header
    # (because of the preceding empty line), 4 extra in total
    header_height = libtcod.console_get_height_rect(
        con, 0, 0, width, SCREEN_HEIGHT, header
    )
    height = len(char_attrs + combat_attrs + caster_attrs) + header_height + 4

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

    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect(window, 0, 0, width, height, header)

    # print all the attributes
    y = header_height
    for attr in char_attrs:
        text = attr[0] + ': ' + str(attr[1])
        libtcod.console_print(window, 0, y, text)
        y += 1

    y += 1  # empty line
    libtcod.console_print(window, 0, y, 'Combat attributes')
    y += 1

    for attr in combat_attrs:
        text = attr[0] + ': ' + str(attr[1])
        libtcod.console_print(window, 0, y, text)
        y += 1

    y += 1  # empty line
    libtcod.console_print(window, 0, y, 'Caster attributes')
    y += 1

    for attr in caster_attrs:
        text = attr[0] + ': ' + str(attr[1])
        libtcod.console_print(window, 0, y, text)
        y += 1

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

    # present the root console to the player
    libtcod.console_flush()
Beispiel #31
0
 def paragraph(self, text):
     self.line += libtcod.console_print_rect(0, 10, self.line, TEXT_WIDTH, 0, text)
     self.line += 1
Beispiel #32
0
def change_settings(box, width, height, blitmap=False):
	confirm, cancel = False, False
	lerp = 1.0
	descending = True
	current = 0

	fonts = sorted(game.fonts, reverse=True)
	font = 0
	if game.setting_font == 'large':
		font = 2
	elif game.setting_font == 'medium':
		font = 1
	history = game.setting_history
	fullscreen = ['on', 'off']
	fs = 0
	if game.setting_fullscreen == 'off':
		fs = 1

	key = libtcod.Key()
	libtcod.console_print_rect(box, 2, 2, width - 4, 2, '(You may need to restart the game for the changes to take effect)')
	libtcod.console_print(box, 2, 5, 'Font size: ')
	libtcod.console_print(box, 2, 6, 'Message history size: ')
	libtcod.console_print(box, 2, 7, 'Fullscreen: ')
	while not confirm and not cancel:
		color, lerp, descending = color_lerp(lerp, descending)

		# font size setting
		if current == 0:
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_set_default_background(box, color)
		else:
			libtcod.console_set_default_foreground(box, libtcod.grey)
			libtcod.console_set_default_background(box, libtcod.black)
		libtcod.console_rect(box, 26, 5, 13, 1, True, libtcod.BKGND_SET)
		libtcod.console_print_ex(box, 32, 5, libtcod.BKGND_SET, libtcod.CENTER, fonts[font].capitalize())

		# message history size setting
		if current == 1:
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_set_default_background(box, color)
		else:
			libtcod.console_set_default_foreground(box, libtcod.grey)
			libtcod.console_set_default_background(box, libtcod.black)
		libtcod.console_rect(box, 26, 6, 13, 1, True, libtcod.BKGND_SET)
		libtcod.console_print_ex(box, 32, 6, libtcod.BKGND_SET, libtcod.CENTER, str(history))

		# full screen mode
		if current == 2:
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_set_default_background(box, color)
		else:
			libtcod.console_set_default_foreground(box, libtcod.grey)
			libtcod.console_set_default_background(box, libtcod.black)
		libtcod.console_rect(box, 26, 7, 13, 1, True, libtcod.BKGND_SET)
		libtcod.console_print_ex(box, 32, 7, libtcod.BKGND_SET, libtcod.CENTER, fullscreen[fs].capitalize())

		for i in range(5, 8):
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_print_ex(box, 25, i, libtcod.BKGND_NONE, libtcod.LEFT, chr(27))
			libtcod.console_print_ex(box, 39, i, libtcod.BKGND_NONE, libtcod.LEFT, chr(26))

		if blitmap:
			libtcod.console_blit(box, 0, 0, width, height, 0, ((game.MAP_WIDTH - width) / 2) + game.MAP_X, (game.MAP_HEIGHT - height) / 2, 1.0, 1.0)
		else:
			libtcod.console_blit(box, 0, 0, width, height, 0, (game.SCREEN_WIDTH - width) / 2, (game.SCREEN_HEIGHT - height) / 2, 1.0, 1.0)
		libtcod.console_flush()
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse())

		if key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_DOWN:
			lerp = 1.0
			descending = True
		if key.vk == libtcod.KEY_LEFT:
			if current == 0:
				font -= 1
				if font == -1:
					font = len(fonts) - 1
			if current == 1:
				history -= 50
				if history == 0:
					history = 1000
			if current == 2:
				if fs == 0:
					fs = 1
				else:
					fs = 0
		elif key.vk == libtcod.KEY_RIGHT:
			if current == 0:
				font += 1
				if font == len(fonts):
					font = 0
			if current == 1:
				history += 50
				if history > 1000:
					history = 50
			if current == 2:
				if fs == 0:
					fs = 1
				else:
					fs = 0
		elif key.vk == libtcod.KEY_UP:
			current -= 1
			if current == -1:
				current = 2
		elif key.vk == libtcod.KEY_DOWN:
			current += 1
			if current == 3:
				current = 0
		elif key.vk == libtcod.KEY_ESCAPE:
			cancel = True
		elif key.vk == libtcod.KEY_ENTER:
			confirm = True

	if confirm:
		game.setting_history = history
		game.setting_fullscreen = fullscreen[fs]
		if game.setting_fullscreen == 'on':
			libtcod.console_set_fullscreen(True)
		else:
			libtcod.console_set_fullscreen(False)
		if blitmap:
			game.message.trim_history()
		IO.save_settings(fonts[font], str(history), fullscreen[fs])