Example #1
0
    def __init__(self, snail, angle):
        """
        @param snail: The snail which has shooted this balloon
        @param angle: The angle which is used to calculate speed in x and y directions
        @summary: Initializes a bullet
        """
        ShootableObject.__init__(self, snail)

        self.image = load_image("bullet.png")
        self.rect = self.image.get_rect()
        self.angle = angle

        # Calculate the x and y speed of the bullet
        self.speed[0] = math.cos(math.radians(angle)) * 10.0 #(self.rect.width)
        self.speed[1] = math.sin(math.radians(angle)) * 10.0 #(self.rect.height)

        position = [0,0]
        position[0] = snail.rect.centerx
        position[1] = snail.rect.centery

        self.rect.center = position
Example #2
0
    def __init__(self, snail):
        """
        @param snail: The snail which has shooted this balloon
        @param gravity_direction: The gravity direction which should be used for this balloon
        @summary: Initializes a balloon
        """
        ShootableObject.__init__(self, snail)
        self._exploded = False
        self.image = load_image("balloon.png")
        self.rect = self.image.get_rect()
        self.gravity_direction = gravity_direction = snail.gravity_direction

        # Calculate the x and y speed of the bullet
        if(gravity_direction == Direction.UP):
            self.speed[1]= 10
            bullet_margin_y = self.rect.height / 2
            bullet_margin_x = 0
            self.image = pygame.transform.rotate(self.image, 180)
        if(gravity_direction == Direction.DOWN):
            self.speed[1]= -10
            bullet_margin_y = -self.rect.height / 2
            bullet_margin_x = 0
            self.image = pygame.transform.rotate(self.image, 0)
        if(gravity_direction == Direction.LEFT):
            self.speed[0]= 10
            bullet_margin_y = 0
            bullet_margin_x = self.rect.width / 2
            self.image = pygame.transform.rotate(self.image, 180+90)
        if(gravity_direction == Direction.RIGHT):
            self.speed[0]= -10
            bullet_margin_y = 0
            bullet_margin_x = -self.rect.width / 2
            self.image = pygame.transform.rotate(self.image, 90)

        self.rect.centerx = snail.rect.centerx + bullet_margin_x
        self.rect.centery = snail.rect.centery + bullet_margin_y