Beispiel #1
0
class Boom:
    """Boom Class"""
    def __init__(self,
                 name="boom",
                 pos=(0, 0),
                 angle=90,
                 length=200,
                 background=None,
                 shape=None,
                 displayed=None,
                 area=None,
                 hook=None):
        self.name = name
        self.pos = pos
        self.angle = angle
        self.length = length
        self.background = background
        self.shape = shape
        self.displayed = displayed
        self.area = area
        self.hook = hook
        print(self.name + " creation completed")

    def turn_left(self, value):
        self.angle += value
        self.hook.pos = (self.pos[0] + self.length - int(self.hook.size / 2) +
                         self.hook.radius * math.sin(math.radians(self.angle)),
                         self.pos[1] + self.length - int(self.hook.size / 2) +
                         self.hook.radius * math.cos(math.radians(self.angle)))

    def turn_right(self, value):
        self.angle -= value
        self.hook.pos = (self.pos[0] + self.length - int(self.hook.size / 2) +
                         self.hook.radius * math.sin(math.radians(self.angle)),
                         self.pos[1] + self.length - int(self.hook.size / 2) +
                         self.hook.radius * math.cos(math.radians(self.angle)))

    def display(self, screen):
        self.background = pygame.Surface((2 * self.length, 2 * self.length),
                                         pygame.SRCALPHA).convert_alpha()
        self.background.fill(pygame.Color(0, 0, 0,
                                          0))  # fill with transparent color

        if self.shape == "LINE":
            pygame.draw.line(
                surface=self.background,
                color=pygame.Color("black"),
                start_pos=(self.length, self.length),
                end_pos=(self.length +
                         self.length * math.sin(math.radians(self.angle)),
                         self.length +
                         self.length * math.cos(math.radians(self.angle))),
                width=8)

            screen.blit(self.background, (self.pos[0], self.pos[1]))

        elif self.shape == "AREA":
            if self.area is None:
                self.area = Area(name="Boom",
                                 pos=(self.pos[0] + self.length,
                                      self.pos[1] + self.length),
                                 angle=self.angle,
                                 width=8,
                                 length=self.length,
                                 color=pygame.Color("black"))
                self.area.init_background()

            self.area.angle = self.angle  # update the angle in the area class

            pygame.draw.polygon(surface=self.background,
                                color=pygame.Color("black"),
                                points=self.area.coordinates_from_side())

            screen.blit(self.background, (self.pos[0], self.pos[1]))