Ejemplo n.º 1
0
def load_layer_to_map_cosmetic(map, x1, y1, xp_file_layer, rotation='None'):
    global id
    from MapGen import Themes
    if not xp_file_layer['width'] or not xp_file_layer['height']:
        raise AttributeError(
            'Attempted to call load_layer_to_console on data that didn\'t have a width or height key, check your data'
        )

    width = xp_file_layer['width'] - 2
    height = xp_file_layer['height'] - 2

    for x in range(1, width + 1):
        for y in range(1, height + 1):
            cell_data = xp_file_layer['cells'][x][y]
            fore_color = Color('{0},{1},{2}'.format(cell_data['fore_r'],
                                                    cell_data['fore_g'],
                                                    cell_data['fore_b']))
            back_color = Color('{0},{1},{2}'.format(cell_data['back_r'],
                                                    cell_data['back_g'],
                                                    cell_data['back_b']))
            # libtcod.console_put_char_ex(console, x, y, cell_data['keycode'], fore_color, back_color)
            char = cell_data['keycode']
            # print char
            # map[x1 + x][y1 + y].char = cell_data['keycode']
            # map[x1 + x][y1 + y].f_color = fore_color
            # map[x1 + x][y1 + y].b_color = back_color

            if rotation == '90':
                temp_y = x
                temp_x = -y
                temp_x += height + 1
            elif rotation == '270':
                temp_y = -x
                temp_x = y
                temp_y += width + 1
            elif rotation == '180':
                temp_y = -y
                temp_x = -x
                temp_y += height + 1
                temp_x += width + 1
            elif rotation == 'None':
                temp_y = y
                temp_x = x

            if char != 32:
                map[x1 + temp_x - 1][y1 + temp_y - 1].char = char
                map[x1 + temp_x - 1][y1 + temp_y - 1].f_color = fore_color
                map[x1 + temp_x - 1][y1 + temp_y -
                                     1].b_color = Themes.ground_bcolor()

    id += 1
    return map
Ejemplo n.º 2
0
def load_layer_to_console(console, xp_file_layer):
    if not xp_file_layer['width'] or not xp_file_layer['height']:
        raise AttributeError(
            'Attempted to call load_layer_to_console on data that didn\'t have a width or height key, check your data'
        )

    for x in range(xp_file_layer['width']):
        for y in range(xp_file_layer['height']):
            cell_data = xp_file_layer['cells'][x][y]
            fore_color = Color('{0},{1},{2}'.format(cell_data['fore_r'],
                                                    cell_data['fore_g'],
                                                    cell_data['fore_b']))
            back_color = Color('{0},{1},{2}'.format(cell_data['back_r'],
                                                    cell_data['back_g'],
                                                    cell_data['back_b']))
            Render.draw_char(console, x, y, cell_data['keycode'], fore_color,
                             back_color)
Ejemplo n.º 3
0
def large_button(x, y, text, hover, length=None, target=0):

    animation_console = target

    if hover:
        color = Color('light azure')
    else:
        color = Color('azure')

    if length is None:
        length = len(text)
    text = text.center(length)

    x = x - ((length + 2) / 2)
    base_color = color
    value = 40
    adj = Color("{0},{0},{0}".format(value))
    color1 = base_color - adj - adj
    color2 = base_color - adj
    color3 = base_color

    #Render.draw_char(animation_console, x + 1, y, libtcod.CHAR_HLINE, color, libtcod.BKGND_NONE)

    Render.draw_char(animation_console, x, y - 1, Constants.BOX_NW, color1,
                     libtcod.BKGND_NONE)
    Render.draw_char(animation_console, x, y, Constants.BOX_W, color2,
                     libtcod.BKGND_NONE)
    Render.draw_char(animation_console, x, y + 1, Constants.BOX_SW, color3,
                     libtcod.BKGND_NONE)

    for z in range(length):
        Render.draw_char(animation_console, x + z + 1, y - 1, Constants.BOX_S,
                         color1, libtcod.BKGND_NONE)
        Render.draw_char(animation_console, x + z + 1, y, text[z], color2,
                         libtcod.BKGND_NONE)
        Render.draw_char(animation_console, x + z + 1, y + 1, Constants.BOX_S,
                         color3, libtcod.BKGND_NONE)

    Render.draw_char(animation_console, x + 1 + length, y - 1,
                     Constants.BOX_NE, color1, libtcod.BKGND_NONE)
    Render.draw_char(animation_console, x + 1 + length, y, Constants.BOX_W,
                     color2, libtcod.BKGND_NONE)
    Render.draw_char(animation_console, x + 1 + length, y + 1,
                     Constants.BOX_SE, color3, libtcod.BKGND_NONE)
Ejemplo n.º 4
0
def draw_box_bar(x, y, total_width, name, value, maximum, bar_color,
                 back_color, target):
    # render a bar (HP, experience, etc). first calculate the width of the bar

    pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35)

    bar_width = int(float(value) / maximum * total_width)
    og_y = y
    height = 1
    offset_color = Color("128, 128, 128")

    if name != '':
        set_background(target, libtcod.black)
        set_foreground(target, Color("51, 51, 51"))
        print_line(target, x, y, name)
        y += 1
        height += 1

    #print "Bar Colors"
    #print bar_color
    #print back_color
    ''' render MAX value '''
    # set_background(target, back_color-offset_color)
    # set_foreground(target, bar_color-offset_color)
    for x1 in range(x, x + total_width):
        draw_char(target, x1, y, Utils.get_unicode(219), back_color,
                  libtcod.BKGND_SET)
        draw_char(target, x1, y, Utils.get_unicode(255), bar_color,
                  libtcod.BKGND_SET)
    ''' render current value '''
    #set_background(target, back_color)
    # set_foreground(target, bar_color)
    for x1 in range(x, x + bar_width):
        draw_char(target, x1, y, Utils.get_unicode(219), back_color,
                  libtcod.BKGND_SET)
        draw_char(target, x1, y, Utils.get_unicode(254), bar_color,
                  libtcod.BKGND_SET)

    if Utils.is_mouse_in(x, og_y, total_width, height):
        terminal.composition(terminal.TK_OFF)
        line = str(value) + "/" + str(maximum)
        set_foreground(target, 'white')
        print_line(target, x, y, line)
        terminal.composition(terminal.TK_ON)
Ejemplo n.º 5
0
def get_offset_color(map_x, map_y, source_x, source_y):
    try:
        dist = int(distance_between(map_x, map_y, source_x, source_y))
    except:
        dist = 0
    offset_value = int((float(dist) / Constants.TORCH_RADIUS) * 255)
    offset_value = max(0, min(offset_value, 255)) / 2
    offset_color = Color('{0},{1},{2}'.format(offset_value, offset_value,
                                              offset_value))
    return offset_color
Ejemplo n.º 6
0
    def __init__(self,
                 x,
                 y,
                 char,
                 name,
                 color,
                 speed=10,
                 blocks=False,
                 blocks_sight=False,
                 delay=0,
                 fighter=None,
                 always_visible=False,
                 ai=None,
                 item=None,
                 equipment=None,
                 ranged=None):
        self.name = name
        self.blocks = blocks
        self.blocks_sight = blocks_sight
        self.x = x
        self.y = y
        self.delay = delay
        self.base_speed = speed
        self.char = char
        self.color = Color(color)
        self.always_visible = always_visible
        self.path = None
        self.status = Status.StatusList()

        # Optional Components
        self.fighter = fighter
        if self.fighter:  # let the fighter component know who owns it
            self.fighter.owner = self

        self.ranged = ranged
        if self.ranged:  # let the fighter component know who owns it
            self.ranged.owner = self

        self.ai = ai
        if self.ai:  # let the AI component know who owns it
            self.ai.owner = self

        self.item = item
        if self.item:  # let the Item component know who owns it
            self.item.owner = self

        self.equipment = equipment
        if self.equipment:  # let the Equipment component know who owns it
            self.equipment.owner = self
            self.item = Components.Item()
            self.item.owner = self
Ejemplo n.º 7
0
def render_stat_bars():

    pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35)

    # SHOW PLAYER STAT BARS
    Render.draw_box_bar(pos.x, pos.y, 14, '',
                        GameState.get_player().fighter.hp,
                        GameState.get_player().fighter.base_max_hp,
                        Color("178,0,45"), Color("64,0,16"),
                        layers['side_panel_console'])
    Render.draw_box_bar(pos.x, pos.y + 1, 14, '',
                        GameState.get_player().fighter.sp,
                        GameState.get_player().fighter.base_max_sp,
                        Color("0,30,255"), Color("0,10,64"),
                        layers['side_panel_console'])
    Render.draw_box_bar(
        pos.x,
        pos.y + 2,
        14,
        '',
        GameState.get_player().fighter.xp,
        1000,  # TODO: will be NEXT_LVL_XP
        Color("255,255,0"),
        Color("65,65,0"),
        layers['side_panel_console'])

    # RENDER MONSTER HEALTH BARS
    temp_y = 3
    for object in GameState.current_level.get_visible_objects():
        if object.fighter and object.base_speed != 0 and (
                object is not GameState.get_player()
        ):  # and Fov.is_visible(obj=object)
            if temp_y < 17:  # TODO: Make constant to scale UI
                Render.draw_box_bar(Constants.MAP_CONSOLE_WIDTH + 1, temp_y,
                                    17, object.name, object.fighter.hp,
                                    object.fighter.max_hp, Color("0,255,0"),
                                    Color("0,64,0"),
                                    layers['side_panel_console'])
                temp_y += 2
Ejemplo n.º 8
0
def skill_tree():
    key = libtcod.Key()
    mouse = libtcod.Mouse()

    # calculate total height for the header (after auto-wrap) and one line per option
    width = Constants.MAP_CONSOLE_WIDTH
    height = Constants.MAP_CONSOLE_HEIGHT

    st = libtcod.console_new(width, height)
    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(st, Constants.UI_PopFore)
    libtcod.console_set_default_background(st, Constants.UI_PopBack)

    libtcod.console_print_frame(st,
                                0,
                                0,
                                width,
                                height,
                                clear=True,
                                flag=libtcod.BKGND_SET,
                                fmt="Skill Tree")

    Render.print_rect(st, 4, 4, width, height, 'Insert Skill Tree')

    # blit the contents of "window" to the root console
    x = 0
    y = 0

    file = open('Assets\skill_tree.map', 'r')

    # fill map with "blocked" tiles
    #kills = [[' ' for y in range(Constants.MAP_CONSOLE_HEIGHT)] for x in range(Constants.MAP_CONSOLE_WIDTH)]

    skills = [[Skill(' ') for y in range(Constants.MAP_HEIGHT)]
              for x in range(Constants.MAP_WIDTH)]

    selected_x = 0
    selected_y = 0

    for y in range(Constants.MAP_CONSOLE_HEIGHT):
        line = file.readline()
        # print line
        x = 0
        for c in line:
            if c == 'S':
                selected_x = x
                selected_y = y
                skills[x][y] = Skill(c, True)
            else:
                skills[x][y] = Skill(c)
            x += 1

    # print selected_x, selected_y

    button_text = 'Exit'
    ct_button = Button(button_text,
                       width / 2,
                       height - 3,
                       length=6,
                       function=close_window)

    while True:

        libtcod.console_flush()
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if key.vk == libtcod.KEY_LEFT:
            if skills[selected_x - 1][selected_y].char == "-":
                selected_x -= 2
        elif key.vk == libtcod.KEY_RIGHT:
            if skills[selected_x + 1][selected_y].char == "-":
                selected_x += 2
        elif key.vk == libtcod.KEY_UP:
            if skills[selected_x][selected_y - 1].char == "|":
                selected_y -= 2
        elif key.vk == libtcod.KEY_DOWN:
            if skills[selected_x][selected_y + 1].char == "|":
                selected_y += 2
        elif key.vk == libtcod.KEY_SPACE:
            skills[selected_x][selected_y].purchased = True

        if selected_y < 0:
            selected_y = 0
        if selected_x < 0:
            selected_x = 0

        offset = 20, 10

        for y in range(Constants.MAP_CONSOLE_HEIGHT):
            for x in range(Constants.MAP_CONSOLE_WIDTH):
                # print skills
                if selected_x == x and selected_y == y:
                    color = Color('purple')
                else:
                    if skills[x][y].purchased:
                        color = Color('green')
                    else:
                        color = Color('white')

                char = skills[x][y].char
                if char == "|":
                    Render.draw_char(st, x + x + offset[0], y + y + offset[1],
                                     libtcod.CHAR_VLINE, libtcod.white,
                                     Constants.UI_PopBack)
                elif char == "-":
                    Render.draw_char(st, x + x + offset[0], y + y + offset[1],
                                     libtcod.CHAR_HLINE, libtcod.white,
                                     Constants.UI_PopBack)
                elif char == ".":
                    if color == Color('purple'):
                        Render.draw_char(st, x + x + offset[0] + 1,
                                         y + y + offset[1] - 1,
                                         libtcod.CHAR_DNE, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0],
                                         y + y + offset[1] - 1,
                                         libtcod.CHAR_DHLINE, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] - 1,
                                         y + y + offset[1] - 1,
                                         libtcod.CHAR_DNW, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] - 1,
                                         y + y + offset[1],
                                         libtcod.CHAR_DVLINE, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] + 1,
                                         y + y + offset[1],
                                         libtcod.CHAR_DVLINE, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] + 1,
                                         y + y + offset[1] + 1,
                                         libtcod.CHAR_DSE, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0],
                                         y + y + offset[1] + 1,
                                         libtcod.CHAR_DHLINE, color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] - 1,
                                         y + y + offset[1] + 1,
                                         libtcod.CHAR_DSW, color,
                                         Constants.UI_PopBack)
                    else:
                        Render.draw_char(st, x + x + offset[0] + 1,
                                         y + y + offset[1] - 1, ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0],
                                         y + y + offset[1] - 1, ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] - 1,
                                         y + y + offset[1] - 1, ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] - 1,
                                         y + y + offset[1], ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] + 1,
                                         y + y + offset[1], ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] + 1,
                                         y + y + offset[1] + 1, ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0],
                                         y + y + offset[1] + 1, ' ', color,
                                         Constants.UI_PopBack)
                        Render.draw_char(st, x + x + offset[0] - 1,
                                         y + y + offset[1] + 1, ' ', color,
                                         Constants.UI_PopBack)

                    Render.draw_char(st, x + x + offset[0], y + y + offset[1],
                                     chr(4), libtcod.white,
                                     Constants.UI_PopBack)

                elif char != ' ' and char != chr(10):
                    Render.draw_char(st, x + x + offset[0] + 1,
                                     y + y + offset[1] - 1, libtcod.CHAR_DNE,
                                     color, Constants.UI_PopBack)
                    Render.draw_char(st, x + x + offset[0],
                                     y + y + offset[1] - 1,
                                     libtcod.CHAR_DHLINE, color,
                                     Constants.UI_PopBack)
                    Render.draw_char(st, x + x + offset[0] - 1,
                                     y + y + offset[1] - 1, libtcod.CHAR_DNW,
                                     color, Constants.UI_PopBack)

                    Render.draw_char(st, x + x + offset[0] - 1,
                                     y + y + offset[1], libtcod.CHAR_DVLINE,
                                     color, Constants.UI_PopBack)

                    Render.draw_char(st, x + x + offset[0], y + y + offset[1],
                                     char, libtcod.red, Constants.UI_PopBack)

                    Render.draw_char(st, x + x + offset[0] + 1,
                                     y + y + offset[1], libtcod.CHAR_DVLINE,
                                     color, Constants.UI_PopBack)

                    Render.draw_char(st, x + x + offset[0] + 1,
                                     y + y + offset[1] + 1, libtcod.CHAR_DSE,
                                     color, Constants.UI_PopBack)
                    Render.draw_char(st, x + x + offset[0],
                                     y + y + offset[1] + 1,
                                     libtcod.CHAR_DHLINE, color,
                                     Constants.UI_PopBack)
                    Render.draw_char(st, x + x + offset[0] - 1,
                                     y + y + offset[1] + 1, libtcod.CHAR_DSW,
                                     color, Constants.UI_PopBack)

        if ct_button.draw(x, y) == 'close':
            return

        libtcod.console_blit(st, 0, 0, width, height, 0, 0, 0, 1.0, 1.0)
Ejemplo n.º 9
0
def beastiary(width=10, height=10, title=None, text=None):

    # calculate total height for the header (after auto-wrap) and one line per option
    if width is None:
        width = Constants.MAP_CONSOLE_WIDTH - 10

    if height is None:
        height = libtcod.console_get_height_rect(
            0, 0, 0, width, Constants.SCREEN_HEIGHT, text) + 7

    pop = libtcod.console_new(width, height)
    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(pop, Constants.UI_PopFore)
    libtcod.console_set_default_background(pop, Constants.UI_PopBack)

    libtcod.console_print_frame(pop,
                                0,
                                0,
                                width,
                                height,
                                clear=True,
                                flag=libtcod.BKGND_SET,
                                fmt=title)
    # blit the contents of "window" to the root console

    x = 0
    y = 0

    button_text = 'Click to Continue'
    button = Button(button_text, width / 2, height - 3, function=close_window)

    img = libtcod.image_load('Images//cipher_warden_80x80_test_01.png')
    libtcod.image_set_key_color(img, Color(0, 0, 0))
    # show the background image, at twice the regular console resolution
    libtcod.image_blit_2x(img, pop, 9, 2)

    libtcod.console_set_default_foreground(pop, Constants.UI_PopFore)
    libtcod.console_set_default_background(pop, Constants.UI_PopBack)
    Render.print_rect(pop, 3, 3, width - 6, height, text)

    background = libtcod.console_new(Constants.SCREEN_WIDTH,
                                     Constants.SCREEN_HEIGHT)
    libtcod.console_blit(0, 0, 0, Constants.SCREEN_WIDTH,
                         Constants.SCREEN_HEIGHT, background, 0, 0, 1.0, 1.0)

    dragging = False

    click_x = None

    while True:
        Input.update()
        mouse = Input.mouse

        Render.blit(background, 0)
        # libtcod.console_blit(background, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, 0, 0, 0, 1.0, 1.0)
        libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, .85)

        if mouse.lbutton and x <= mouse.cx <= x + width and (mouse.cy == y
                                                             or dragging):
            if click_x is None:
                click_x = mouse.cx - x
            x = mouse.cx - click_x  # (width / 2)
            y = mouse.cy
            dragging = True
        else:
            dragging = False
            click_x = None

        if button.draw(x, y) == 'close':
            return
        libtcod.console_flush()
Ejemplo n.º 10
0
def display_mainMenu():
    # new_game()

    width = Constants.SCREEN_WIDTH
    height = Constants.SCREEN_HEIGHT

    Render.draw_rect(10,
                     0,
                     0,
                     width,
                     height,
                     frame=True,
                     f_color=Color('dark azure'),
                     bk_color=Color('darkest azure'),
                     title="DEEP FRIED SUPERNOVA v0.01")

    Render.print_rect(10, 4, 4, width, height,
                      'Welcome to Deep Fried Supernova')

    # blit the contents of "window" to the root console
    x = 0
    y = 0

    button_text = 'New Game'
    ng_button = Button(button_text,
                       width / 2,
                       height - 12,
                       length=16,
                       function=new_game,
                       target=10)

    button_text = 'Continue Game'
    ct_button = Button(button_text,
                       width / 2,
                       height - 9,
                       length=16,
                       function=continue_game,
                       target=10)

    button_text = 'Quit'
    qt_button = Button(button_text,
                       width / 2,
                       height - 6,
                       length=16,
                       function=close_window,
                       target=10)

    img = libtcod.image_load('diner_logo_sm.png')
    # libtcod.image_set_key_color(img, Color(0, 0, 0))

    # show the background image, at twice the regular console resolution
    #libtcod.image_blit_2x(img, mm, 37, 2)

    #libtcod.console_blit(mm, 0, 0, width, height, 0, 0, 0, 1.0, 1.0)

    while True:
        Input.update()

        if qt_button.draw(0, 0) == 'close':
            return

        if ct_button.draw(0, 0) == 'continue':
            return

        ng_button.draw(0, 0)
        terminal.refresh()
Ejemplo n.º 11
0
def render_common():
    import Input

    pos = Pos(Constants.MAP_CONSOLE_WIDTH, 0)

    # ERRORS
    Render.set_foreground(layers['side_panel_console'], Color("0,70,140"))
    """ LEVEL NUMBER """
    Render.print_rect(layers['side_panel_console'], pos.x + 1, pos.y + 1, 17,
                      1, "Level 1".center(17, ' '))
    """ MOUSE X / Y """
    Render.print_rect(
        layers['side_panel_console'], pos.x + 9, pos.y + 18, 17, 2,
        "X: " + str(Input.mouse.cx) + "  \nY: " + str(Input.mouse.cy) + "  ")
    """ STATS """
    color = Color("175,175,255")
    #print color
    Render.set_foreground(layers['panel_console'], color)
    #terminal.color('green')

    player = GameState.player

    Render.print_line(layers['side_panel_console'],
                      Constants.MAP_CONSOLE_WIDTH + 5, 18,
                      str(player.fighter.base_str).rjust(3))
    Render.print_line(layers['side_panel_console'],
                      Constants.MAP_CONSOLE_WIDTH + 5, 19,
                      str(player.fighter.base_def).rjust(3))
    Render.print_line(layers['side_panel_console'],
                      Constants.MAP_CONSOLE_WIDTH + 5, 20,
                      str(player.fighter.base_agl).rjust(3))
    Render.print_line(layers['side_panel_console'],
                      Constants.MAP_CONSOLE_WIDTH + 5, 21,
                      str(player.fighter.base_stm).rjust(3))
    Render.print_line(layers['side_panel_console'],
                      Constants.MAP_CONSOLE_WIDTH + 5, 22,
                      str(player.fighter.base_skl).rjust(3))
    Render.print_line(layers['side_panel_console'],
                      Constants.MAP_CONSOLE_WIDTH + 5, 23,
                      str(player.fighter.base_int).rjust(3))
    """ Items """
    ranged_items = [equip for equip in GameState.inventory if equip.ranged]
    equipped_ranged = [
        equip.name for equip in ranged_items if equip.equipment.is_equipped
    ]
    if equipped_ranged:
        Render.print_line(layers['side_panel_console'],
                          Constants.MAP_CONSOLE_WIDTH + 9, 20,
                          equipped_ranged[0])
    """ CONTROLS """
    Render.print_line(layers['side_panel_console'], 59, 39,
                      "Move/Attack:      NUMPAD/ARROWS")
    Render.print_line(layers['side_panel_console'], 59, 40,
                      "Fire:                         F")
    Render.print_line(layers['side_panel_console'], 59, 41,
                      "Pickup:                       G")
    Render.print_line(layers['side_panel_console'], 59, 42,
                      "Pop-Up Test:                  B")
    Render.print_line(layers['side_panel_console'], 59, 43,
                      "Decend:                       <")
    Render.print_line(layers['side_panel_console'], 59, 44,
                      "Change Weapon:              [[/]]")
    Render.print_line(layers['side_panel_console'], 59, 45,
                      "DEBUG:                        X")
    """ DUNGEON NAME """
    pos = Pos(0, Constants.MAP_CONSOLE_HEIGHT)

    Render.print_rect(layers['panel_console'], pos.x + 1, pos.y + 1,
                      Constants.SCREEN_WIDTH - 19, 1,
                      GameState.dungeon_name.center(57, ' '))
Ejemplo n.º 12
0
def target_mode(source, target=None, ranged_componenet=None):
    """ Reset Params """
    targets = []
    target_x = 0
    target_y = 0
    if source is None:
        source = GameState.get_player()
    """ If no target supplied, Enter Targeting mode """
    if target is None:
        tile_effected = set([])
        # Utils.message('Choose Target. Left Click/Space to execute. Right Click/ESC to cancel.', libtcod.gold)
        ''' Get list of visible enemies to cycle through '''
        target_list = GameState.current_level.closest_monsters(
            ranged_componenet.max_range)
        if target_list:
            target_list = cycle(target_list)
            target = next(target_list)[0]
        ''' Used to detect mouse movement '''
        mouse = Input.mouse
        mouse_last_x, mouse_last_y = mouse.cx, mouse.cy
        mouse_moved = False

        while True:
            ''' Clear Screen '''
            Render.clear_layer(layers['overlay_console'])
            """
            Render.draw_rect(layers['overlay_console'], 0, 0,
                             Constants.MAP_CONSOLE_WIDTH,
                             Constants.MAP_CONSOLE_HEIGHT,
                             frame=True,
                             f_color=terminal.color_from_argb(255, 255, 100, 100),
                             bk_color=terminal.color_from_name('transparent'),
                             title="Targeting Mode - Right Click/ESC to Cancel")
            # """
            ''' Get Inputs '''
            Input.update()
            key = Input.key
            ''' determine if mouse moved, otherwise use auto-target '''
            if mouse.cx != mouse_last_x or mouse.cy != mouse_last_y:
                mouse_moved = True
                moues_last_x, mouse_last_y = mouse.cx, mouse.cy
            if mouse_moved:
                target_x, target_y = Utils.to_map_coordinates(
                    mouse.cx, mouse.cy)
            elif target:
                target_x, target_y = target.x, target.y
            else:
                target_x, target_y = source.x, source.y
            ''' determine line of fire (You may not be able to hit every enemy you see) '''
            line = Utils.get_line((source.x, source.y), (target_x, target_y),
                                  walkable=True,
                                  ignore_mobs=True,
                                  max_length=ranged_componenet.max_range)
            for point in line:
                if point == (None, None):
                    break
                point = Utils.to_camera_coordinates(point[0], point[1])
                #libtcod.console_set_char_background(0, point[0], point[1], libtcod.lighter_blue, libtcod.BKGND_SET)
                Render.draw_char(layers['overlay_console'], point[0], point[1],
                                 0x2588,
                                 terminal.color_from_argb(128, 64, 64, 255))

            if len(line) > 0:
                index = Utils.find_element_in_list((None, None), line)

                if index is None:
                    point = line[-1]
                else:
                    point = line[index - 1]

                circle = Utils.get_circle_points(point[0], point[1],
                                                 ranged_componenet.aoe)
                if circle:
                    tile_effected = set(circle)

                    for points in circle:
                        points = Utils.to_camera_coordinates(
                            points[0], points[1])
                        Render.draw_char(
                            layers['overlay_console'], points[0], points[1],
                            0x2588, terminal.color_from_argb(128, 200, 32, 32))
                        Render.draw_char(
                            layers['overlay_console'], points[0], points[1],
                            0xE000, terminal.color_from_argb(128, 255, 0, 0))

            if mouse.lbutton_pressed or key == terminal.TK_SPACE:
                # target_tile = (target_x, target_y)
                # print tile_effected
                for target in tile_effected:
                    # target = Map.to_map_coordinates(target[0], target[1])
                    monster = GameState.current_level.get_monster_at(
                        (target[0], target[1]))
                    if monster is not None:
                        print "Monster: " + str(monster) + " at " + str(target)
                        targets.append(monster)
                break

            if mouse.rbutton_pressed or key == terminal.TK_ESCAPE:
                break

            if key == terminal.TK_F:
                if target_list:
                    target = next(target_list)[0]

            GameState.render_ui()

        if not targets:  # no enemy found within maximum range
            Utils.message('Cancelled.', Color('red'))
            Render.clear_layer(layers['overlay_console'])
            return 'cancelled'
        else:
            targets = GameState.current_level.get_monsters_in_range_at(
                target, ranged_componenet.aoe)
    Render.clear_layer(layers['overlay_console'])

    # TODO: Allow targeting Empty tiles

    # zap it!
    if ranged_componenet.animation:
        ranged_componenet.animation_params['origin'] = (source.x, source.y)
        ranged_componenet.animation_params['target'] = (target_x, target_y)
        ranged_componenet.animation_params['target_angle'] = Utils.get_angle(
            source.x, source.y, target_x, target_y)

        GameState.add_animation(ranged_componenet.animation,
                                ranged_componenet.animation_params)

    for target in targets:
        if target.fighter:
            # TODO: Combat should handle all messages......

            Utils.message(
                '[color={1}]{2} [color={0}]takes [color={3}]{4} damage[color={0}].'
                ''.format(Constants.COMBAT_MESSAGE_DEFAULT_COLOR,
                          Constants.COMBAT_MESSAGE_MONSTER_NAME_COLOR,
                          target.name, Constants.COMBAT_MESSAGE_DAMAGE_COLOR,
                          ranged_componenet.owner.equipment.power_bonus))
            target.fighter.take_damage(
                ranged_componenet.owner.equipment.power_bonus)
    Render.clear_layer(5)
    return 'fired'
Ejemplo n.º 13
0
####################################################################
# START LIBTCOD SPECIFIC CODE

##################################
# Used primarily internally to parse the data, feel free to reference them externally if it's useful.
# Changing these programattically will, of course, screw up the parsing (unless the format changes and you're using an old copy of this file)
##################################

# the solid square character
poskey_tile_character = 219

# some or all of the below may appear in libtcod's color definitions; and in fact, you can use libtcod colors as you please for position keys.
# These are merely the colors provided in the accompanying palette.

poskey_color_red = Color('255, 0, 0')
poskey_color_lightpurple = Color(
    '254, 0, 255'
)  # specifically 254 as 255, 0, 255 is considered a transparent key color in REXPaint
poskey_color_orange = Color('255, 128, 0')
poskey_color_pink = Color('255, 0, 128')
poskey_color_green = Color('0, 255, 0')
poskey_color_teal = Color('0, 255, 255')
poskey_color_yellow = Color('255, 255, 0')
poskey_color_blue = Color('0, 0, 255')
poskey_color_lightblue = Color('0, 128, 255')
poskey_color_purple = Color('128, 0, 255')
poskey_color_white = Color('255, 255, 255')

id = 1