示例#1
0
    def __init__(self, pos=SCREEN_CENTER):
        Entity.__init__(self, (18, 18), pos)

        # Acceleration vector that will be rotated and added to velocity
        self.acceleration = Vector(0, -0.2)

        # controls how quickly the ship slows down
        self.slow_speed = 0.1

        # controls how quickly the ship rotates and slows its rotation
        self.rotate_increment = 0.5
        self.slow_rotation = self.rotate_increment / 2

        # 10 frame cooldown, start at 0
        self.fire_cooldown = 0

        # Group of all lasers for collision purposes
        self.lasers = SpriteGroup()

        # Draws an arrow facing in the direction of angle to serve as the ship
        size = self.image.get_size()
        arrow_points = [
            (0, size[1] - 1),  # bottom left
            ((size[0] - 1) / 2, 0),  # top middle
            (size[0] - 1, size[1] - 1)  # bottom right
        ]
        draw_lines(self.image, COLOR.WHITE, False, arrow_points, 2)
示例#2
0
    def __init__(self, tier=1, speed=3, angle=0, pos=(0, 0)):
        # Tier determines the size, and how many times it breaks apart
        size = (tier * 15, tier * 15)
        Entity.__init__(self, size, pos)

        self.tier = tier

        self.velocity.from_polar((speed, angle))
        self.angle = angle
        self.position = Vector(pos)

        # The angle spread of the children when the asteroid breaks apart
        self.spread = 20

        first = (size[0] - 1) / 3
        second = first * 2
        third = first * 3
        octagon = [
            (first, 0),  # top 1
            (second, 0),  # top 2
            (third, first),  # right 1
            (third, second),  # right 2
            (second, third),  # bottom 1
            (first, third),  # bottom 2
            (0, second),  # left 1
            (0, first)  # left 2
        ]
        draw_polygon(self.image, COLOR.WHITE, octagon, 2)

        Asteroid.group.add(self)
示例#3
0
    def __init__(self, pos=(0, 0), angle=0):
        Entity.__init__(self, (5, 2), pos)

        # 60 frames = 1 second
        self.lifetime = 60

        self.orig_img.fill(COLOR.WHITE)

        # angle 0 points right, so subtract 90 degrees
        angle = angle - 90
        self.velocity.from_polar((self.max_velocity, angle))
        self.rotate(angle)
示例#4
0
 def __init__(self, *args):
     """Create a viewport entity that displays contents of a camera inside the world.
     Arguments are either (Camera, int, int) for a new camera or
     (Camera) for an existing one
     """
     Entity.__init__(self)
     if len(args) == 1:
         self.camera = args[0]
     elif len(args) == 3:
         scene = args[0]
         width = args[1]
         height = args[2]
         self.camera = Camera(scene, width, height)
     else:
         raise TypeError, "Viewport's constructor takes either 4 or 2 arguments, %i given" % len(args)+1