def render_small_number(text, color, shake=0):
    """ Renders a number using numbers_small.png.

    Supports the . character.
    """
    width = numbers_small.single_width * len(text)
    surface = graphics.new_surface((width, numbers_small.single_height))

    x = 0
    for char in text:
        if char == ".":
            sprite_num = 10
        else:
            sprite_num = int(char)

        x_offset = round((random.random() - 0.5) * (shake * 2))
        y_offset = round((random.random() - 0.5) * (shake * 2))

        numbers_small.draw(surface, (x + x_offset, y_offset), sprite_num)
        x += numbers_small.single_width

    pixel_array = pygame.PixelArray(surface)
    pixel_array.replace(colors.TEXT_PLACEHOLDER, color)

    return surface
Exemple #2
0
    def __init__(self):
        self.undos = []
        self.changed = False
        self.changes_grid = [[[-1] * levels.HEIGHT
                              for _ in range(levels.WIDTH)]
                             for _ in range(levels.LAYER_COUNT)]

        self.selected_layer = levels.LAYER_BLOCKS

        self.level = None
        self.level_num = -1
        self.selected_tile = levels.EMPTY

        self.level_surface = graphics.new_surface(constants.SCREEN_SIZE)
        self.ui_surface = graphics.new_surface(SCREEN_SIZE)

        self.SAVE_AND_EXIT = 0
        self.SAVE_AND_PLAY = 1
        self.ADD_SHELL = 2
        self.REMOVE_SHELL = 3
        self.FIRST_SHELL_BUTTON = 4

        buttons = ButtonSet()
        buttons.add(small_button((10, SCREEN_HEIGHT - 40)))
        buttons.add(small_button((50, SCREEN_HEIGHT - 40)))
        buttons.add(small_button((SCREEN_WIDTH - 65, SCREEN_HEIGHT - 230)))
        buttons.add(small_button((SCREEN_WIDTH - 65, SCREEN_HEIGHT - 200)))

        buttons.draw_arrow(self.SAVE_AND_EXIT, buttons.ARROW_LEFT)
        buttons.draw_arrow(self.SAVE_AND_PLAY, buttons.ARROW_RIGHT)
        buttons.draw_plus(self.ADD_SHELL)
        buttons.draw_minus(self.REMOVE_SHELL)

        self.buttons = buttons

        self.placing_start = False
        self.placing_end = False

        self.switch_to_menu = False
        self.switch_to_player = False
Exemple #3
0
    def render_downscaled_body(self, scale):
        total_width = self.downscaled_total_width(scale)
        total_height = self.downscaled_total_height(scale)
        surface = graphics.new_surface((total_width, total_height))

        # Draws cap
        cap_x = self.cap_x // scale
        cap_width = total_width - (cap_x * 2)
        cap_height = self.cap_height // scale
        cap_rect = (cap_x, 0, cap_width, cap_height)
        pygame.draw.rect(surface, colors.CAP_PLACEHOLDER, cap_rect)

        # Draws the top of the bottle (the part that curves into the cap)
        top_y = cap_height
        top_width = self.top.width // scale
        top_height = self.top.height // scale
        top_sprite = self.top.render()
        top_scaled = pygame.transform.scale(top_sprite, (top_width, top_height))
        color = colors.BODY_PLACEHOLDER
        draw_wedge(surface, (0, top_y), top_scaled, total_width, color)

        # Draws the body of the bottle
        body_y = top_y + top_height
        body_height = (self.body_height + self.bottom.height) // scale
        body_rect = (0, body_y, total_width, body_height)
        pygame.draw.rect(surface, colors.BODY_PLACEHOLDER, body_rect)

        # Draws the label
        label_y = body_y + (self.label_y_offset // scale)
        label_height = self.label_height // scale
        label_rect = (0, label_y, total_width, label_height)
        pygame.draw.rect(surface, colors.LABEL_PLACEHOLDER, label_rect)

        # Note that the bottom of the bottle does not need to be drawn
        # It is too small, so when scaled down, you can't really see it

        # bottom_y = body_y + body_height
        # bottom_width = self.bottom.single_width // scale
        # bottom_height = self.bottom.single_height
        # bottom_sprite = self.bottom.render()
        # bottom_scaled = pygame.transform.scale(bottom_sprite, (bottom_width, bottom_height))
        # color = colors.LABEL_PLACEHOLDER
        # draw_wedge(surface, (0, bottom_y), bottom_scaled, total_width, color)

        # Colors in the bottle
        pixel_array = pygame.PixelArray(surface)
        pixel_array.replace(colors.CAP_PLACEHOLDER, self.palette.cap_color)
        pixel_array.replace(colors.BODY_PLACEHOLDER, self.palette.body_color)
        pixel_array.replace(colors.LABEL_PLACEHOLDER, self.palette.label_color)
        pixel_array.close()

        return surface
Exemple #4
0
    def __init__(self, rect):
        self.rect = pygame.Rect(rect)
        self.x = rect[0]
        self.y = rect[1]
        self.w = rect[2]
        self.h = rect[3]

        self.sprite = graphics.new_surface((self.w, self.h))
        graphics.border(self.sprite, self.OUTLINE_COLOR, 2)
        self.hidden = False

        self.highlight = False
        self.selected = False
Exemple #5
0
    def render_bottle_icon_row(self, width, offset, symbols=None):
        if symbols:
            misc.force_length(symbols, len(self.bottles), const.SYMBOL_NONE)
        else:
            symbols = [const.SYMBOL_NONE] * len(self.bottles)

        scale = self.BOTTLE_ICON_SCALE

        height = self._max_bottle_icon_height() + 4
        surface = graphics.new_surface((width, height))

        x = -offset
        for bottle, symbol in zip(self.bottles, symbols):
            bottle_width = bottle.downscaled_total_width(scale)

            # Skips any bottle that isn't rendered due to the offset
            if x + bottle_width > 0:
                y = (height - bottle.downscaled_total_height(scale)) // 2
                sprite = bottle.render_downscaled_body(scale)
                surface.blit(sprite, (x, y))

                if symbol == const.SYMBOL_CHECK:
                    check_x = x + bottle_width - 8
                    check_y = y + bottle.downscaled_total_height(scale) - 10
                    checkmark.draw(surface, (check_x, check_y))

                elif symbol == const.SYMBOL_CROSS:
                    cross_x = x + bottle_width - 8
                    cross_y = y + bottle.downscaled_total_height(scale) - 10
                    cross.draw(surface, (cross_x, cross_y))

            x += bottle_width + self.BOTTLE_ICON_SPACING

            # Stops rendering bottles if the end of the surface is reached
            if x > width:
                break

        return surface
Exemple #6
0
    def render_body(self):
        surface = graphics.new_surface(self.total_size)

        # Draws the cap of the bottle
        cap_width = self.body_width - self.cap_x * 2
        cap_rect = (self.cap_x, 0, cap_width, self.cap_height)
        pygame.draw.rect(surface, colors.CAP_PLACEHOLDER, cap_rect)

        # Draws the top of the bottle (the part that curves into the cap)
        top_y = self.cap_height
        color = colors.BODY_PLACEHOLDER
        top_sprite = self.top.render()
        draw_wedge(surface, (0, top_y), top_sprite, self.body_width, color)

        # Draws the body of the bottle
        body_y = top_y + self.top.height
        body_rect = (0, body_y, self.body_width, self.body_height)
        pygame.draw.rect(surface, colors.BODY_PLACEHOLDER, body_rect)

        label_y = body_y + self.label_y_offset
        label_rect = (0, label_y, self.body_width, self.label_height)
        pygame.draw.rect(surface, colors.LABEL_PLACEHOLDER, label_rect)

        # Draws the bottom of the bottle
        bottom_y = body_y + self.body_height
        color = colors.BODY_PLACEHOLDER
        bottom_sprite = self.bottom.render()
        draw_wedge(surface, (0, bottom_y), bottom_sprite, self.body_width, color)

        # Colors in the bottle
        pixel_array = pygame.PixelArray(surface)
        pixel_array.replace(colors.CAP_PLACEHOLDER, self.palette.cap_color)
        pixel_array.replace(colors.BODY_PLACEHOLDER, self.palette.body_color)
        pixel_array.replace(colors.LABEL_PLACEHOLDER, self.palette.label_color)
        pixel_array.close()

        return surface