Example #1
0
 def evnt_hndlr(self, event):
     if event.type == MOUSEBUTTONDOWN:
         if event.button == 1:
             wind = pvector.PVector(3, 0)
             for m in self.movers:
                 m.applyForce(wind)
         elif event.button == 3:
             wind = pvector.PVector(-3, 0)
             for m in self.movers:
                 m.applyForce(wind)
Example #2
0
    def __init__(self, screen_width, screen_height):
        super(Snake, self).__init__()

        self.base_acc = 0.3
        self.max_velocity = 2

        self.v_location = pvector.PVector(30, 200)
        self.v_velocity = pvector.PVector(0, 0)
        self.v_acceleration = pvector.PVector(self.base_acc, self.base_acc)

        self.size = 3

        self.time = math.pi
Example #3
0
    def __init__(self, x, y):
        super(Mover, self).__init__()

        self.location = pvector.PVector(x, y)
        self.velocity = pvector.PVector(0, 0)
        self.acceleration = pvector.PVector(0, 0)

        self.mass = 1
        self.max_velo = 40
        self.do_limit = False

        # The gravitational constant for attraction
        self.G = 0.05
Example #4
0
    def update(self, delta):
        gravity = pvector.PVector(0, .16)
        for m in self.movers:
            m.applyGravity(gravity)

        for m in self.movers:
            m.update()
Example #5
0
    def update(self, delta):
        self.c.update()

        gravity = pvector.PVector(0, .51)
        for m in self.movers:
            m.applyGravity(gravity)
            m.applyFriction(1)
            m.update()
Example #6
0
 def shoot(self):
     m = mover.Mover(self.spawnpos.x, self.spawnpos.y)
     init_velocity_mag = 20
     init_velocity = pvector.PVector(init_velocity_mag,
                                     math.radians(self.angle+90),
                                     False)
     m.velocity.add(init_velocity)
     return m
Example #7
0
    def update(self):
        self.time += math.pi / 20
        sine = math.sin(self.time) / 2
        v_sine = pvector.PVector(0, sine)
        self.v_acceleration.set(self.base_acc, self.base_acc)
        self.v_acceleration.add(v_sine)

        print(self.v_acceleration)

        # Apply acceleration to velocity and location. Also limit speed
        self.v_velocity.add(self.v_acceleration)
        self.v_velocity.limit(self.max_velocity)
        self.v_location.add(self.v_velocity)
Example #8
0
    def update(self):
        self.angle += self.change_angle
        if self.angle > self.max_angle:
            self.angle = self.max_angle
        elif self.angle < self.min_angle:
            self.angle = self.min_angle

        # Calculate the spawn position of the next mover
        spawn_x = self.width * math.cos(math.radians(-self.angle))
        spawn_x += self.bottomleft[0]
        spawn_y = self.width * math.sin(math.radians(-self.angle))
        spawn_y += self.bottomleft[1]
        self.spawnpos = pvector.PVector(spawn_x, spawn_y)
Example #9
0
    def __init__(self, bottomleft):
        super(Canon, self).__init__()
        self.bottomleft = bottomleft

        # Fixed size of the canon
        self.width = 75
        self.height = 25

        # Angle of the canon
        self.angle = 45
        self.max_angle = 80
        self.min_angle = 10

        self.change_angle = 0

        # Initialize the image of the canon
        self.image = pygame.Surface((self.width, self.height))

        # Calculate the spawn position of the next mover
        self.spawnpos = pvector.PVector(0, 0)