def create_base(self):
        surf = Surface((64, 32), pygame.SRCALPHA, 32)

        pygame.draw.rect(surf, self.color, Rect(0, 8, 44, 16))
        pygame.draw.polygon(surf, self.color, [(44, 0), (64, 16), (44, 32)])

        # noinspection PyArgumentList
        self.base_image = surf.convert_alpha()
        self.drawable = Drawable(self.base_image.copy(), self.position, True,
                                 True)
 def __init__(self,
              instance,
              position=(0, 0),
              text="",
              color=WHITE,
              new_font=font,
              get_text_function=None):
     Entity.__init__(self, instance)
     self.my_font = new_font
     self.text = text
     self.color = color
     self.drawable = Drawable(None, None, True, False)
     self.position = position
     self.get_text_function = get_text_function
 def create_drawable(self):
     self.drawable = Drawable()
Пример #4
0
 def create_drawable(self):
     self.drawable = Drawable(texture["ship"], (0, 0), False, True)
class Arrow(Entity):
    color = None
    target = None
    scale = 1

    camera = None

    def __init__(self, instance, target, color, size):
        Entity.__init__(self, instance)
        self.scale = size
        self.color = color
        self.target = target
        self.base_image = None

        self.ARROW_AXIS_LEFT = value["arrow.left_axis"]
        self.ARROW_AXIS_BOTTOM = value["arrow.bottom_axis"]
        self.ARROW_AXIS_RIGHT = value["arrow.right_axis"]
        self.ARROW_AXIS_TOP = value["arrow.top_axis"]
        self.my_font = font["arrow_font"]
        self.create_base()

    def create_base(self):
        surf = Surface((64, 32), pygame.SRCALPHA, 32)

        pygame.draw.rect(surf, self.color, Rect(0, 8, 44, 16))
        pygame.draw.polygon(surf, self.color, [(44, 0), (64, 16), (44, 32)])

        # noinspection PyArgumentList
        self.base_image = surf.convert_alpha()
        self.drawable = Drawable(self.base_image.copy(), self.position, True,
                                 True)

    def update_image(self):
        if self.instance is None:
            return

        if self.instance.camera.point_on_screen(self.target.position):
            self.on_screen = False
            return
        self.on_screen = True

        distance, angle = distance_and_angle(
            (self.instance.camera.x + value["init.half_width"],
             self.instance.camera.y + value["init.half_height"]),
            (self.target.x, self.target.y))

        angle = -angle
        co, si = cos(angle), sin(angle)

        x_axis = self.ARROW_AXIS_LEFT
        if co > 0:
            x_axis = self.ARROW_AXIS_RIGHT
        x_dist = abs((x_axis - value["init.half_width"]) * co)

        y_axis = self.ARROW_AXIS_BOTTOM
        if si > 0:
            y_axis = self.ARROW_AXIS_TOP
        y_dist = abs((y_axis - value["init.half_height"]) * si)

        if x_dist > y_dist:
            new_x = x_axis
            new_y = abs(x_axis - value["init.half_width"]
                        ) * -1 * si + value["init.half_height"]
        else:
            new_y = y_axis
            new_x = abs(y_axis - value["init.half_height"]
                        ) * co + value["init.half_width"]

        if new_x > self.ARROW_AXIS_RIGHT: new_x = self.ARROW_AXIS_RIGHT
        if new_x < self.ARROW_AXIS_LEFT: new_x = self.ARROW_AXIS_LEFT
        if new_y < self.ARROW_AXIS_TOP: new_y = self.ARROW_AXIS_TOP
        if new_y > self.ARROW_AXIS_BOTTOM: new_y = self.ARROW_AXIS_BOTTOM
        self.position = new_x, new_y
        string = str(int(distance))
        label = self.my_font.render(string, 1, BLACK)

        image = self.base_image.copy()
        if hasattr(self.target, "name"):
            label2 = self.my_font.render(self.target.name, 1, WHITE)
            if co < 0:
                image.blit(pygame.transform.rotate(label2, 180), (0, -8))
            else:
                image.blit(label2, (0, -8))
        if co < 0:
            image.blit(pygame.transform.rotate(label, 180), (10, 6))
        else:
            image.blit(label, (10, 6))
        size = (int(64 * self.scale), int(32 * self.scale))

        self.drawable._image = pygame.transform.rotate(
            pygame.transform.scale(image, size), angle * 180 / pi)

    def update(self, delta_time):
        self.update_image()

    def draw(self, screen, offset):
        if self.drawable is not None and self.visible and self.on_screen:
            self.drawable.draw(screen, offset)
Пример #6
0
 def create_drawable(self):
     self.drawable = Drawable(texture["repair_earth"], self.position, False,
                              True)
     self.sound = sound["earth_heal"]
Пример #7
0
 def create_drawable(self):
     self.drawable = Drawable(texture["heart"], self.position, False, True)
     self.sound = sound["heal_sound"]
Пример #8
0
 def create_drawable(self):
     self.image = texture["goblin"]
     self.drawable = Drawable(None, None, False, True)
     self.base_projectile.image = texture["goblin_bomb"]
     self.base_projectile.damage = self.weapon_damage
     self.base_projectile.sound = sound["destroyed"]
Пример #9
0
 def create_drawable(self):
     self.drawable = Drawable(texture["hunter"], None, False, True)
     self.base_projectile.drawable = texture["hunter_missile"]
     self.base_projectile.damage = self.weapon_damage
     self.base_projectile.sound = sound["destroyed"]