예제 #1
0
def get_room_at_mouse(g_obj, mpos_mapped):
    rooms = g_obj.dungeon.get_rooms()
    rw, rh = g_obj.rw, g_obj.rh
    for r in rooms:
        gx, gy = r.grid_pos
        rr = Rect(gx * rw, gy * rh, rw, rh)
        if rr.collidepoint(mpos_mapped):
            return r
    return None
예제 #2
0
def should_be_open_tbt(self, lout, bx, by, roomx, roomy, ox, oy, tsw, tsh, m,
                       direction):
    if direction == "east":
        range_mod = 2
    else:
        range_mod = 2

    tw, th = self.tw, self.th

    cam = self.cam
    cx, cy = cam.get()
    # print(cx, cy)

    rw, rh = self.rw, self.rh

    rx = tw * roomx * rw
    ry = th * roomy * rh

    rsize = tw, th

    u = self.mc
    x, y = u.anim_pos
    rux, ruy = ox + x * tw, oy + y * th
    aox, aoy = 0, 0
    if (u.state == "attacking"
            and u.attack_weapon.attack_type == "melee") or u.dashing:
        aox, aoy = u.projectile_pos

    mc_pos = rux + aox + cx + tw / 2, ruy + aoy + cy + th / 2

    mpos = m

    mover = []
    inrange = []

    for dx, dy in product(range(tsw), range(tsh)):

        at = rx + (bx - ox + dx) * tw + cx, ry + (by - oy + dy) * th + cy
        # at = (bx+dx) * tw, (by+dy) * th
        # self.swin.blit(img, at)

        r = Rect(at, rsize)
        if r.collidepoint(mpos):
            mover.append(True)
        else:
            mover.append(False)
        if in_range(mc_pos, r.center, 3 + tw * range_mod):
            inrange.append(True)
        else:
            inrange.append(False)

    if any(inrange):  # and any(mover):
        return True
    else:
        return False
예제 #3
0
    def __init__(self, w, h):
        self.x, self.y = 0, 0
        self.w, self.h = w, h

        self.update_step = 2

        cw, ch = 180, 180

        self.cw, self.ch = cw, ch

        self.border_left = Rect((0, 0), (cw, h))
        self.border_bot = Rect((0, h - ch), (w, ch))
        self.border_right = Rect((w - cw, 0), (cw, h))
        self.border_top = Rect((0, 0), (w, ch))

        self.never_centered = True
예제 #4
0
 def setup(self):
     maxh = self.tree.h * self.th
     for n in self.tree.get_all_nodes():
         gx, gy = n.get_gpos()
         x, y = gx * self.tw, gy * self.th
         r = Rect(x, maxh - y, self.tw, self.th)
         n.rect = r
예제 #5
0
def draw_dungeon_nlayers(g_obj, nlayers):
    rl = g_obj.renderlogic

    pre = rl.prerendered

    pr = pre.rooms

    dung = g_obj.dungeon

    for room in dung.get_rooms():
        gx, gy = room.grid_pos

        tw, th = room.tilesets.tw, room.tilesets.th

        rw, rh = g_obj.rw, g_obj.rh
        raw, rah = rw * tw, rh * th

        ox, oy = g_obj.cam.get()

        rx, ry = gx * raw + ox, gy * rah + oy

        sw, sh = g_obj.w, g_obj.h

        buffer = max((2 * tw, 2 * th))
        screen_rect = Rect(-buffer, -buffer, sw + buffer * 2, sh + buffer * 2)

        room_rect = Rect(rx, ry, raw, rah)
        # print(room_rect.topleft)

        if not (screen_rect.colliderect(room_rect)):
            continue

        in_this_room = dung.get_room().room_id == room.room_id

        x, y = ox, oy
        nx, ny = 0, 0

        mw, mh = room.layout.w, room.layout.h

        floors_img = pr[room.room_id][nlayers]

        g_obj.swin.blit(floors_img, (rx, ry))
예제 #6
0
def draw_menus(g_obj):
    # pause menu
    rect_width = 800
    rect_height = 600
    pause_rect = Rect(0, 0, rect_width, rect_height)
    pause_rect.center = (g_obj.w / 2, g_obj.h / 2)

    if g_obj.ui.get_selected() == "in game menu":
        # draw background
        pygame.draw.rect(g_obj.swin, pygame.Color(100, 100, 100, 255),
                         pause_rect)
        # draw buttons
        button_height = rect_height / 4
        for b in g_obj.menu.menu_items:
            b_rect = Rect(0, 0, 600, 100)
            b_rect.center = (g_obj.w / 2, g_obj.h / 2 + button_height)
            pygame.draw.rect(g_obj.swin, pygame.Color(40, 40, 40, 255), b_rect)
            b.rect = b_rect
            # text here
            font = g_obj.font
            img = font.render(b.text, 1, pygame.Color(255, 255, 255, 255))
            g_obj.swin.blit(
                img, (g_obj.w / 2 - img.get_width() / 2,
                      (g_obj.h / 2 + button_height) - img.get_height() / 2))
            button_height -= 150
    pass
예제 #7
0
def draw_dungeon_layer(g_obj, name, wmap=None):
    dung = g_obj.dungeon

    for room in dung.get_rooms():
        gx, gy = room.grid_pos

        tw, th = room.tilesets.tw, room.tilesets.th

        rw, rh = g_obj.rw, g_obj.rh
        raw, rah = rw * tw, rh * th

        rx, ry = gx * raw, gy * rah

        sw, sh = g_obj.w, g_obj.h

        buffer = max((2 * tw, 2 * th))
        screen_rect = Rect(-buffer, -buffer, sw + buffer * 2, sh + buffer * 2)

        ox, oy = g_obj.cam.get()

        room_rect = Rect(rx + ox, ry + oy, raw, rah)
        # print(room_rect.topleft)

        if not (screen_rect.colliderect(room_rect)):
            continue

        layer = room.layout.get_layer(name)

        in_this_room = dung.get_room().room_id == room.room_id

        x, y = ox, oy
        nx, ny = 0, 0

        mw, mh = room.layout.w, room.layout.h

        somesurf_red = g_obj.nwsurf
        somesurf_green = g_obj.wsurf

        for tx, ty, n in product(range(mw), range(mh),
                                 room.layout.layers.keys()):
            if n != name:  # draw only specified layer
                continue
            tile_index = room.layout.get_tile_index(n, tx, ty)
            if tile_index == None:  # transparent tile
                continue
            tile = room.tilesets.get_tile(*tile_index)
            x, y = tx * tw + ox + rx, ty * th + oy + ry
            cr = Rect(x, y, tw, th)
            if not screen_rect.colliderect(cr):
                continue
            # g_obj.swin.blit(tile.image, (x, y))
            tx, ty = tx + rw, ty + rh
            if wmap != None:
                if 0 <= tx < len(wmap) and 0 <= ty < len(wmap[0]):
                    walkable = wmap[tx][ty]
                    if walkable:
                        g_obj.swin.blit(somesurf_green, (x, y))
                    else:
                        g_obj.swin.blit(somesurf_red, (x, y))
예제 #8
0
def prerender_room(g_obj, room, layers):
    rw, rh = g_obj.rw, g_obj.rh
    tw, th = g_obj.tw, g_obj.th
    sw, sh = tw * rw, th * rh
    new_surf = pygame.Surface((sw, sh), flags=pygame.HWSURFACE)
    new_surf.set_colorkey((0, 0, 0))
    new_surf.fill((0, 0, 0))
    for name in layers:
        dung = g_obj.dungeon

        gx, gy = room.grid_pos

        tw, th = room.tilesets.tw, room.tilesets.th

        # rw, rh = g_obj.rw, g_obj.rh
        # raw, rah = rw * tw, rh * th

        # rx, ry = gx * raw, gy * rah

        sw, sh = g_obj.w, g_obj.h

        buffer = max((2 * tw, 2 * th))
        screen_rect = Rect(-buffer, -buffer, sw + buffer * 2, sh + buffer * 2)

        ox, oy = 0, 0

        # room_rect = Rect(rx+ox, ry+oy, raw, rah)

        # layer = room.layout.get_layer(name)

        # in_this_room = dung.get_room().room_id == room.room_id

        # x, y = ox, oy
        # nx, ny = 0, 0

        mw, mh = room.layout.w, room.layout.h

        for tx, ty, n in product(range(mw), range(mh),
                                 room.layout.layers.keys()):
            if n != name:  # draw only specified layer
                continue
            tile_index = room.layout.get_tile_index(n, tx, ty)
            tile_orient = room.layout.get_tile_orient(n, tx, ty)
            if tile_index == None:  # transparent tile
                continue
            tile = room.tilesets.get_tile(*tile_index)
            x, y = tx * tw + ox, ty * th + oy
            cr = Rect(x, y, tw, th)
            if not screen_rect.colliderect(cr):
                continue
            img = tile.image
            if tile_orient[0] == 1:
                img = pygame.transform.flip(img, 1, 0)
            if tile_orient[1] == 1:
                img = pygame.transform.flip(img, 0, 1)
            if tile_orient[2] == 1:
                # img = pygame.transform.flip(img, 1, 1)
                img = pygame.transform.rotate(img, 270)

            # img = tile.image
            new_surf.blit(img, (x, y))

    return new_surf
예제 #9
0
def lighting_pass_old(g_obj):
    dung = g_obj.dungeon

    for room in dung.get_rooms():
        gx, gy = room.grid_pos

        tw, th = room.tilesets.tw, room.tilesets.th

        rw, rh = g_obj.rw, g_obj.rh
        raw, rah = rw * tw, rh * th

        rx, ry = gx * raw, gy * rah

        sw, sh = g_obj.w, g_obj.h

        buffer = max((2 * tw, 2 * th))
        screen_rect = Rect(-buffer, -buffer, sw + buffer * 2, sh + buffer * 2)

        ox, oy = g_obj.cam.get()

        room_rect = Rect(rx + ox, ry + oy, raw, rah)
        # print(room_rect.topleft)

        if not (screen_rect.colliderect(room_rect)):
            continue

        in_this_room = dung.get_room().room_id == room.room_id

        x, y = ox, oy
        nx, ny = 0, 0

        mw, mh = room.layout.w, room.layout.h

        tindx_x_l = [8, 9, 10, 11, 12, 13, 14, 15]
        tindx_y = 9

        torches = []

        for tx, ty, n in product(range(mw), range(mh),
                                 room.layout.layers.keys()):
            add_torch = False
            if n == "Torches":
                tile_index = room.layout.get_tile_index(n, tx, ty)
                if tile_index != None:  # transparent tile
                    tile = room.tilesets.get_tile(*tile_index)
                    tilex, tiley = tile_index[1:]
                    # print(tilex, tiley)
                    if tindx_y == tiley and tilex in tindx_x_l:
                        add_torch = True

            x, y = tx * tw + ox + rx, ty * th + oy + ry
            cr = Rect(x, y, tw, th)
            if not screen_rect.colliderect(cr):
                continue
            if not in_this_room:
                g_obj.swin.blit(g_obj.darktile, (x, y))

            if add_torch:
                torches.append((x, y))

        td = 6

        wtr = td
        htr = td

        tcx, tcy = 2.5, 2.5

        for t in torches:
            for xtr, ytr in product(range(wtr), range(htr)):
                if not in_range((tcx, tcy), (xtr, ytr), int(td / 2)):
                    continue
                dist = get_distance((tcx, tcy), (xtr, ytr))
                xt, yt = t[0] + (xtr - tcx) * tw, t[1] + (ytr - tcy) * th
                intensity = 0
                for i in range(3):
                    if i > dist:
                        break
                    intensity += 1
                tseed = (t[0], t[1])
                tintensity = g_obj.renderlogic.torches.get_torch_intensity(
                    tseed)
                g_obj.lighttile.set_alpha(
                    int((60 - intensity * 20) * tintensity))
                g_obj.swin.blit(g_obj.lighttile, (xt, yt))
예제 #10
0
def draw_combat_ui(g_obj):
    # draw informational ui

    tw, th = g_obj.tw, g_obj.th

    turns_w = int(g_obj.w / 2) - int(16 * g_obj.scale * 4.5)
    turns_h = 16 * g_obj.scale

    px, py = turns_w, turns_h

    draw_turns = 8
    units = g_obj.cc.use_list
    n = g_obj.cc.turn
    i = 0
    while len(units) > 0:
        not_all_dead = False
        for unit in units[n:] + units[:n]:
            if unit.state == "dead":
                continue

            not_all_dead = True

            i += 1

            f = unit.animations["Idle"].get_frame()

            frame = unit.animations["Idle"].get_frame()
            images = []
            for f in frame.tiles:
                ind, to = f[:3], f[3:]
                image = g_obj.tilesets.get_tile(*ind).image
                images.append((image, to))

            px += 16 * g_obj.scale

            for img, to in images:
                tx, ty = to
                g_obj.swin.blit(img, (px + tx * tw, py + ty * th * -1))

            if i == draw_turns:
                break

        if not_all_dead == False:
            break

        if i == draw_turns:
            break

    # draw ap and hp for the unit the is mouse overed,
    # otherwise draw the one that's currently taking his turn

    cu = g_obj.cc.get_current_unit()
    if g_obj.ui.at_mouse["unit"] != None:
        cu = g_obj.ui.at_mouse["unit"]

    if cu != None:
        ca = int(cu.ap.current_ap)
        ta = cu.ap.get_ap()
        # if ta % 1 > 0:
        # ta = (round(ta + 0.5))
        ta = int(ta)

        ap_green = get_tile_img(g_obj, "main_set", f_flat(254))
        ap_yellow = get_tile_img(g_obj, "main_set", f_flat(255))

        exc_ap = (5 - cu.ap.base_ap)
        scale = 16
        x_spot = 128 * 5 + 16 * g_obj.scale + exc_ap * scale

        uiinfo_w = 16

        apx = x_spot

        apy = 16 * g_obj.scale + 64

        for i in range(0, uiinfo_w * ca, uiinfo_w):
            g_obj.swin.blit(ap_yellow, (apx + i, apy))
        for i in range(0, uiinfo_w * ta, uiinfo_w):
            g_obj.swin.blit(ap_green, (apx + i, apy))

        mhp = cu.get_health()
        dmg = cu.damage_taken
        hp = mhp - dmg

        h_repr = 5

        #x_spot = 128 * 5 + 16 * g_obj.scale

        hpx = g_obj.w - x_spot - 16

        hpy = 16 * g_obj.scale + 64

        hp_red = get_tile_img(g_obj, "main_set", f_flat(252))
        hp_yellow = ap_yellow

        for i in range(0, uiinfo_w * h_repr, uiinfo_w):
            g_obj.swin.blit(hp_yellow, (hpx - i + exc_ap * scale, hpy))
        for i in range(0, uiinfo_w * int((h_repr * hp) / mhp + 0.5), uiinfo_w):
            g_obj.swin.blit(hp_red, (hpx - i + exc_ap * scale, hpy))

        statuses = cu.statuses

        # draw the dude under mouse position

        frame = cu.current_animation().get_frame()
        images = []
        for f in frame.tiles:
            ind, to = f[:3], f[3:]
            image = g_obj.tilesets.get_tile(*ind).image
            images.append((image, to))

        midx = (apx + hpx) // 2
        for i, to in images:
            tx, ty = to
            g_obj.swin.blit(i, (midx + tx * tw, hpy + ty * th * -1))

    gray = 100, 100, 100
    blue = 135, 206, 250

    g_obj.swin.blit(g_obj.ui_bg, (0, g_obj.h - 48 - 16))

    # draw interactive ui
    cu = g_obj.mc
    ui_ = g_obj.ui.ui1
    for k in ui_.ui_elements.keys():
        ele = ui_.ui_elements[k]

        pos = ele.box.topleft

        if k == "left hand" and cu != None and cu.equipment.hand_two != None:
            if ui_.selected_element == k:
                invert_color = True
            else:
                invert_color = False
            weapon = cu.equipment.hand_two
            f = weapon.widget_frame
            img = get_tile_img(g_obj, "main_set", f_flat(f))
            if invert_color:
                arr = pygame.surfarray.array3d(img)
                arr[::, ::, 1] = 0
                arr[::, ::, 2] = 0
                pxred = pygame.surfarray.make_surface(arr)
                pxred.set_colorkey((0, 0, 0))
                img = pxred
            images = [(img, (0, 0))]
        elif k == "right hand" and cu != None and cu.equipment.hand_one != None:
            if ui_.selected_element == k:
                invert_color = True
            else:
                invert_color = False
            weapon = cu.equipment.hand_one
            f = weapon.widget_frame
            img = get_tile_img(g_obj, "main_set", f_flat(f))
            if invert_color:
                arr = pygame.surfarray.array3d(img)
                arr[::, ::, 1] = 0
                arr[::, ::, 2] = 0
                pxred = pygame.surfarray.make_surface(arr)
                pxred.set_colorkey((0, 0, 0))
                img = pxred
            images = [(img, (0, 0))]
        elif "ability" in k and cu != None and cu.memory.is_filled(k):
            if ui_.selected_element == k:
                invert_color = True
            else:
                invert_color = False

            abi = cu.memory.get_learned(k)
            aclass = abi.abi_class

            if aclass == "Brawler":
                f = 190
            elif aclass == "Sharpshooter":
                f = 191
            elif aclass == "Engineer":
                f = 189
            elif aclass == "God":
                f = 447

            img = get_tile_img(g_obj, "main_set", f_flat(f))

            if invert_color:
                arr = pygame.surfarray.array3d(img)
                arr[::, ::, 1] = 0
                arr[::, ::, 2] = 0
                pxred = pygame.surfarray.make_surface(arr)
                pxred.set_colorkey((0, 0, 0))
                img = pxred

            images = [(img, (0, 0))]

        else:
            frame = ele.get_frame()
            images = []
            for f in frame.tiles:
                ind, to = f[:3], f[3:]
                image = g_obj.tilesets.get_tile(*ind).image
                images.append((image, to))

        for i, to in images:
            tx, ty = to
            # draw_x = int(g_obj.cam.cw/2) + 64
            # draw_y = - int(g_obj.cam.ch/2) - 128 - 32 + 8*g_obj.scale
            draw_x = 16
            draw_y = -4 - th
            ele.draw_x = draw_x
            ele.draw_y = draw_y

            px, py = (pos[0] + draw_x + tx * tw,
                      pos[1] + draw_y + ty * th * -1)
            g_obj.swin.blit(i, (px, py))

            if "ability" in ele.name:
                abi = get_selected_ability(ele.name, g_obj.mc.memory)
                if abi != None and abi.cooldown.cooldown != 0:
                    rect = Rect(px, py, tw, th)
                    f = abi.cooldown.cooldown / abi.cooldown.usage_cd
                    sa = radians(360 - 360 * (f))
                    ea = radians(360)
                    radius = int(tw / 2 - 1)
                    pygame.draw.arc(g_obj.swin, blue, rect, sa, ea, radius)

        # draw xp, level

        mc = g_obj.mc
        xp = mc.xp
        xpup = mc.xp_to_lup

        w, h = 50, 20

        b = 10

        bx = g_obj.w - w * 5 - 50 - b * 5
        by = g_obj.h - 50 + 11

        x, y = bx, by

        for i in range(xpup):
            r = Rect(x, y, w, h)
            x += w + b
            pygame.draw.rect(g_obj.swin, gray, r)

        x, y = bx, by

        for i in range(xp):
            r = Rect(x, y, w, h)
            x += w + b
            pygame.draw.rect(g_obj.swin, blue, r)

        # draw bullets
        white = 255, 255, 255
        text = "x {0}".format(mc.currency)
        img = g_obj.font.render(text, 0, white)

        bullet = get_tile_img(g_obj, "main_set", f_flat(299))

        bpos = bx - 225, by - 15
        tpos = bx - 175, by - 15
        g_obj.swin.blit(bullet, bpos)
        g_obj.swin.blit(img, tpos)
예제 #11
0
def lighting_pass(g_obj):
    dung = g_obj.dungeon

    for room in dung.get_rooms():
        gx, gy = room.grid_pos

        tw, th = room.tilesets.tw, room.tilesets.th

        rw, rh = g_obj.rw, g_obj.rh
        raw, rah = rw * tw, rh * th

        rx, ry = gx * raw, gy * rah

        sw, sh = g_obj.w, g_obj.h

        buffer = max((2 * tw, 2 * th))
        screen_rect = Rect(-buffer, -buffer, sw + buffer * 2, sh + buffer * 2)

        ox, oy = g_obj.cam.get()

        room_rect = Rect(rx + ox, ry + oy, raw, rah)
        # print(room_rect.topleft)

        if not (screen_rect.colliderect(room_rect)):
            continue

        in_this_room = dung.get_room().room_id == room.room_id

        x, y = ox, oy
        nx, ny = 0, 0

        mw, mh = room.layout.w, room.layout.h

        if not in_this_room:
            g_obj.swin.blit(g_obj.renderlogic.prerendered.darkness,
                            (rx + ox, ry + oy))

        tindx_x_l = [8, 9, 10, 11, 12, 13, 14, 15]
        tindx_y = 9

        torches = []

        for tx, ty, n in product(range(mw), range(mh),
                                 room.layout.layers.keys()):
            add_torch = False
            if n == "Torches":
                tile_index = room.layout.get_tile_index(n, tx, ty)
                if tile_index != None:  # transparent tile
                    # tile = room.tilesets.get_tile(*tile_index)
                    tilex, tiley = tile_index[1:]
                    # print(tilex, tiley)
                    if tindx_y == tiley and tilex in tindx_x_l:
                        add_torch = True
            x, y = tx * tw + ox + rx, ty * th + oy + ry
            if add_torch:
                torches.append((x, y))

        for t in torches:
            xt, yt = t
            tseed = (t[0], t[1])
            tintensity = g_obj.renderlogic.torches.get_torch_intensity(tseed)

            actual_intensity = int(tintensity * 60)

            torch_img = g_obj.renderlogic.prerendered.torches[actual_intensity]

            g_obj.swin.blit(torch_img, (int(xt - tw * 2.5), int(yt - th * 2)))
예제 #12
0
 def draw(self, surface: pygame.Surface, position, rect: Rect, offset=(0, 0)):
     scale = self.get_scale_factor()
     x = scale[0] * rect.w * position[0] + offset[0]
     y = scale[1] * rect.h * position[1] + offset[1]
     surface.blit(self.scaled_image, (x, y), area=rect.scale(scale).to_tuple())
예제 #13
0
def create_ui_interactive(self, g_obj):
    # set commands for creating UI

    creation_commands = [
        ["uielement", "end turn", "uibtn_endturn"],
        ["spacing"],
        ["uielement", "move", "uibtn_move"],
        ["spacing"],
        ["uielement", "right hand", "uibtn_righthand"],
        ["spacing"],
        ["uielement", "left hand", "uibtn_lefthand"],
        ["spacing"]
    ]

    for i in range(5):
        command_name = "ability {0}".format(str(i + 1))
        animation_name = "uibtn_ability"

        gen_command = ["uielement", command_name, animation_name]

        creation_commands.append(gen_command)

    creation_commands.append(["spacing"])

    for i in range(5):
        command_name = "syringe {0}".format(str(i + 1))
        animation_name = "uibtn_syringe"

        gen_command = ["uielement", command_name, animation_name]

        creation_commands.append(gen_command)

    other_creation_commands = [
        ["spacing"],
        ["spacing"],
        ["spacing"],
        ["uielement", "skill tree", "uibtn_skilltree"],
        ["spacing"],
        ["spacing"],
        ["spacing"],
        ["uielement", "in game menu", "uibtn_ingamemenu"]
    ]

    creation_commands += other_creation_commands

    # now initialize it

    ui_start_x, ui_start_y = 0, g_obj.h - 0
    ui_x = ui_start_x
    ui_y = ui_start_y

    ui_w, ui_h = 16 * g_obj.scale, 16 * g_obj.scale  # scaled tile size

    ui_b = 0  # border
    ui_s = 16  # spacing value

    for command in creation_commands:
        if command[0] == "uielement":
            name, animation_name = command[1:]
            ele = UIInteractiveElement()
            ele.box = Rect(ui_x, ui_y, ui_w, ui_h)
            # print(ui_x, ui_y, ui_w, ui_h)
            ele.animations = g_obj.animations.new_animation_set_instance(animation_name)
            ele.name = name
            self.ui_elements[name] = ele
            ui_x += ui_w
        elif command[0] == "spacing":
            ui_x += ui_s

        ui_x += ui_b

    skilltree_element = self.ui_elements["skill tree"]
    menu_element = self.ui_elements["in game menu"]
    self.lock_elements = [skilltree_element, menu_element]