コード例 #1
0
ファイル: centerinfo.py プロジェクト: realliance/RiichiRoyale
def render_center_info(board_render):
    center_info_surface = Surface((250, 250))
    match = board_render.match
    group = LayeredUpdates()

    # Background
    info_rect = Rect(0, 0, 250, 250)
    info_rect.center = board_render.surface.get_rect().center
    pygame.draw.rect(center_info_surface, (0, 0, 0), info_rect)

    current_path = os.path.dirname(os.path.realpath(__file__))
    font_path = os.path.join(
        current_path, "..", "..", "resources", "fonts", "SourceSans3-Semibold.ttf"
    )
    font = Font(font_path, 30)
    large_font = Font(font_path, 42)

    # Round Title
    round_text = "{} {}".format("East" if match.east_prevalent else "South", match.round_number)
    round_surface = font.render(round_text, True, (255, 255, 255))
    round_sprite = Sprite()
    round_sprite.image = round_surface
    round_sprite.rect = round_surface.get_rect()
    round_sprite.rect.center = info_rect.center
    round_sprite.rect.y -= (round_surface.get_rect().height // 2)
    round_sprite.layer = 1
    group.add(round_sprite)

    # Tiles Left in Wall
    tile_count_surface = large_font.render(str(len(match.current_board.wall)), True, (255, 255, 255))
    wall_remaining_sprite = Sprite()
    wall_remaining_sprite.image = tile_count_surface
    wall_remaining_sprite.rect = tile_count_surface.get_rect()
    wall_remaining_sprite.rect.center = info_rect.center
    wall_remaining_sprite.rect.y += (tile_count_surface.get_rect().height // 3)
    wall_remaining_sprite.layer = 1
    group.add(wall_remaining_sprite)

    # Wind Markers
    create_wind_markers(match, info_rect, group)

    # Turn Marker
    create_turn_marker(match, info_rect, group)

    # Riichi Markers
    create_riichi_markers(match, info_rect, group)

    background_sprite = Sprite()
    background_sprite.rect = info_rect
    background_sprite.image = center_info_surface
    background_sprite.layer = 0
    group.add(background_sprite)
    return group
コード例 #2
0
ファイル: centerinfo.py プロジェクト: realliance/RiichiRoyale
def create_turn_marker(board, parent_rect, group):
    MARKER_OFFSET = 20
    MARKER_WIDTH = 5
    current_turn = board.current_board.current_turn
    if current_turn % 2 == 0:
        marker_size = (parent_rect.width - MARKER_OFFSET, MARKER_WIDTH)
    else:
        marker_size = (MARKER_WIDTH, parent_rect.width - MARKER_OFFSET)
    marker_size_half = (marker_size[0] / 2, marker_size[1] / 2)
    parent_half_width = parent_rect.width / 2
    parent_half_height = parent_rect.height / 2
    SEAT_OFFSETS = [
        (0, parent_half_height - marker_size_half[1]),
        (parent_half_width - marker_size_half[0], 0),
        (0, -parent_half_height + marker_size_half[1]),
        (-parent_half_width + marker_size_half[0], 0),
    ]

    turn_marker_surface = Surface(marker_size)
    turn_marker_surface.fill((255, 255, 255))
    sprite = Sprite()
    sprite.rect = turn_marker_surface.get_rect()
    sprite.image = turn_marker_surface
    sprite.rect.center = parent_rect.center
    sprite.rect.x += SEAT_OFFSETS[current_turn][0]
    sprite.rect.y += SEAT_OFFSETS[current_turn][1]
    sprite.layer = 2
    group.add(sprite)
コード例 #3
0
ファイル: centerinfo.py プロジェクト: realliance/RiichiRoyale
def create_wind_markers(match, parent_rect, group):
    current_path = os.path.dirname(os.path.realpath(__file__))
    font_path = os.path.join(
        current_path, "..", "..", "resources", "fonts", "SourceSans3-Semibold.ttf"
    )
    font = Font(font_path, 40)
    MARKER_SIZE = (40, 40)
    MARKER_SIZE_HALF = (MARKER_SIZE[0] / 2, MARKER_SIZE[1] / 2)
    MARKER_OFFSET = 40
    parent_half_width = parent_rect.width / 2
    parent_half_height = parent_rect.height / 2
    SEAT_OFFSETS = [
        (0, parent_half_height - MARKER_SIZE_HALF[1] - MARKER_OFFSET),
        (parent_half_width - MARKER_SIZE_HALF[0] - MARKER_OFFSET, 0),
        (0, -parent_half_height + MARKER_SIZE_HALF[1] + MARKER_OFFSET),
        (-parent_half_width + MARKER_SIZE_HALF[0] + MARKER_OFFSET, 0),
    ]
    WIND_ORDERS = [
        ["E", "S", "W", "N"],
        ["N", "E", "S", "W"],
        ["W", "N", "E", "S"],
        ["S", "W", "N", "E"],
    ]
    current_east_seat = match.current_board.current_dealer
    wind_order = WIND_ORDERS[current_east_seat]

    for i in range(4):
        wind = wind_order[i]
        background_surface = Surface(MARKER_SIZE)
        if i == current_east_seat:
            background_color = (255, 0, 0)
        else:
            background_color = (100, 100, 100)
        background_surface.fill(background_color)
        font_surface = font.render(wind, True, (255, 255, 255))
        font_width, font_height = font.size(wind)
        background_surface.blit(
            font_surface,
            ((MARKER_SIZE[0] - font_width) / 2, (MARKER_SIZE[1] - font_height) / 2),
        )

        sprite = Sprite()
        sprite.rect = background_surface.get_rect()
        sprite.image = background_surface
        sprite.rect.center = parent_rect.center
        sprite.rect.x += SEAT_OFFSETS[i][0]
        sprite.rect.y += SEAT_OFFSETS[i][1]
        sprite.layer = 2
        group.add(sprite)
コード例 #4
0
ファイル: centerinfo.py プロジェクト: realliance/RiichiRoyale
def create_riichi_markers(match, parent_rect, group):
    MARKER_OFFSET = 60
    MARKER_Y_OFFSET = 10
    MARKER_WIDTH = 15

    i = -1
    for player in match.players:
        i += 1
        if not player.riichi_declared:
            continue

        if i % 2 == 0:
            marker_size = (parent_rect.width - MARKER_OFFSET, MARKER_WIDTH)
        else:
            marker_size = (MARKER_WIDTH, parent_rect.width - MARKER_OFFSET)
        marker_size_half = (marker_size[0] / 2, marker_size[1] / 2)
        parent_half_width = parent_rect.width / 2
        parent_half_height = parent_rect.height / 2
        SEAT_OFFSETS = [
            (0, parent_half_height - marker_size_half[1] - MARKER_Y_OFFSET),
            (parent_half_width - marker_size_half[0] - MARKER_Y_OFFSET, 0),
            (0, -parent_half_height + marker_size_half[1] + MARKER_Y_OFFSET),
            (-parent_half_width + marker_size_half[0] + MARKER_Y_OFFSET, 0),
        ]

        riichi_marker_surface = Surface(marker_size)
        marker_rect = riichi_marker_surface.get_rect()
        riichi_marker_surface.fill((255, 255, 255))
        pygame.draw.circle(
            riichi_marker_surface,
            (255, 0, 0),
            (marker_rect.width / 2, marker_rect.height / 2),
            5,
        )
        sprite = Sprite()
        sprite.rect = marker_rect
        sprite.image = riichi_marker_surface
        sprite.rect.center = parent_rect.center
        sprite.rect.x += SEAT_OFFSETS[i][0]
        sprite.rect.y += SEAT_OFFSETS[i][1]
        sprite.layer = 2
        group.add(sprite)
コード例 #5
0
def render_bot_icons(board_render):
    ICON_SIZE = (50, 50)
    group = LayeredUpdates()

    SEAT_POS = [
        None, (board_render.surface.get_width() - ICON_SIZE[0] - 10, 80),
        (460 - ICON_SIZE[0] - 10, 10), (10, 80)
    ]

    game_view = board_render.match.game_manager.get_active_view()

    icon_cache = game_view.bot_icon_cache
    ais = game_view.ai_list
    ai_icons = []
    dud_ai_icon = pygame.Surface(ICON_SIZE, pygame.SRCALPHA)
    load_image_resource("dudB.png", dud_ai_icon, size=ICON_SIZE)
    for i in range(4):
        for icon in icon_cache:
            if icon['ai'] == ais[i]:
                surface = pygame.Surface(ICON_SIZE, pygame.SRCALPHA)
                load_image_resource(icon['icon'], surface, size=ICON_SIZE)
                ai_icons += [surface]
                break

    is_story_mode = hasattr(game_view, "match_dict")
    for seat in range(4):
        if seat == 0:
            continue
        sprite = Sprite()
        sprite.rect = (SEAT_POS[seat], ICON_SIZE)
        sprite.layer = 0
        if is_story_mode and seat != 2:
            sprite.image = dud_ai_icon
        else:
            sprite.image = ai_icons[seat]
        group.add(sprite)
    return group
コード例 #6
0
def render_score_screen(board_render):
    should_show_screen = board_render.board_manager.round_should_end
    group = LayeredUpdates()

    if not should_show_screen:
        return group

    current_path = os.path.dirname(os.path.realpath(__file__))
    font_path = os.path.join(
        current_path, "..", "..", "resources", "fonts", "SourceSans3-Semibold.ttf"
    )
    font = Font(font_path, 40)
    font_small = Font(font_path, 24)

    match = board_render.match
    scores = match.scores
    delta_scores = match.delta_scores
    total_scores = list(map(lambda s: s[0] + s[1], zip(scores, delta_scores)))

    winner_indices = numpy.argwhere(numpy.array(delta_scores) > 0).flatten()
    winner_names = []

    array = numpy.array(total_scores)
    temp = array.argsort()[::-1]
    ranks = numpy.empty_like(temp)
    ranks[temp] = numpy.arange(len(array))

    icons = get_object('boticons')['bot']

    screen_surface = Surface(board_render.surface.get_size(), pygame.SRCALPHA)
    screen_surface.fill((0, 0, 0))

    ROUND_COMPLETE = "Round Complete"

    round_complete_surface = font.render(ROUND_COMPLETE, True, (255, 255, 255))
    font_width, font_height = font.size(ROUND_COMPLETE)

    icon_size = (100, 100)

    player_list = match.ai_list

    x = screen_surface.get_width() // 5
    y = font_height + 5

    for seat in range(4):
        ai_name = player_list[seat]
        name = None
        icon = None
        for entry in icons:
            if entry['ai'] == ai_name:
                name = entry['name']
                icon = entry['icon']
                break
        if name is None:
            raise "BOT WAS NOT DEFINED."

        if seat in winner_indices:
            winner_names += [name]

        icon_surface = Surface(icon_size, pygame.SRCALPHA)
        load_image_resource(icon, icon_surface, size=icon_size)

        screen_surface.blit(
            icon_surface,
            (x, y)
        )

        player_name = font.render(name, True, (255, 255, 255))
        _, name_h = font.size(name)

        screen_surface.blit(
            player_name,
            (x + icon_size[0] + 10, y)
        )

        score_string = "{} Points".format(scores[seat])
        score_render = font_small.render(score_string, True, (255, 255, 255))
        _, score_h = font_small.size(score_string)

        screen_surface.blit(
            score_render,
            (x + icon_size[0] + 10, y + name_h + 5)
        )

        delta_string = "{}{}".format("+" if delta_scores[seat] >= 0 else "", delta_scores[seat])
        delta_render = font_small.render(delta_string, True, (255, 255, 255))
        _, delta_h = font_small.size(delta_string)

        screen_surface.blit(
            delta_render,
            (x + icon_size[0] + 10, y + name_h + 5 + score_h + 5)
        )

        total_string = "Total: {} Points".format(total_scores[seat])
        total_render = font_small.render(total_string, True, (255, 255, 255))

        screen_surface.blit(
            total_render,
            (x + icon_size[0] + 10, y + name_h + 5 + score_h + 5 + delta_h + 5)
        )

        place_string = "{}".format(ranks[seat] + 1)
        place_render = font.render(place_string, True, (255, 255, 255))
        place_w, place_h = font.size(place_string)

        screen_surface.blit(
            place_render,
            (x - place_w - 5, y + ((icon_size[1] - place_h) // 2))
        )

        y += icon_size[1] + 70

    LOADING_NEXT_ROUND = "Loading next Round..."
    loading_surface = font.render(LOADING_NEXT_ROUND, True, (255, 255, 255))
    loading_width, loading_height = font.size(LOADING_NEXT_ROUND)

    screen_surface.blit(
        loading_surface,
        (screen_surface.get_width() - loading_width - 10, screen_surface.get_height() - loading_height - 10)
    )

    screen_surface.blit(
        round_complete_surface,
        ((screen_surface.get_width() // 2) - (font_width // 2), 10),
    )

    result_pos = (screen_surface.get_width() * 0.6, screen_surface.get_height() // 3)

    if board_render.board_manager.did_exhaustive_draw:
        EXHAUSTIVE = "Exhaustive Draw"
        exhaustive_surface = font.render(EXHAUSTIVE, True, (255, 255, 255))

        screen_surface.blit(
            exhaustive_surface,
            result_pos
        )
    else:
        WINNERS = "Winners:"
        winners = ", ".join(winner_names)

        winner_text = font_small.render(WINNERS, True, (255, 255, 255))
        winner_name_text = font_small.render(winners, True, (255, 255, 255))

        screen_surface.blit(
            winner_text,
            result_pos
        )

        screen_surface.blit(
            winner_name_text,
            (result_pos[0], result_pos[1] + winner_text.get_rect().height + 5)
        )




    background_sprite = Sprite()
    background_sprite.rect = screen_surface.get_rect()
    background_sprite.image = screen_surface
    background_sprite.layer = 0
    group.add(background_sprite)



    return group