示例#1
0
    def __init__(self, pos, pitch, yaw, speed, nighttime, *groups):
        super(ClayPigeon, self).__init__(*groups)
        self.x, self.y = pos
        self.z = 0
        self.start_x, self.start_y = self.x, self.y
        self.speed = speed #70 #speed of time elapsed for trajectory, lower means faster clays
        self.glow = nighttime
        if self.glow:
            self.base_image = prepare.GFX["glow-clay"]
        else:
            self.base_image = prepare.GFX["clay"]
        self.width, self.height = self.base_image.get_size()
        self.original_width, self.original_height = self.width, self.height
        self.image = self.base_image
        self.rect = self.image.get_rect(center=(self.x, self.y))

        firing_speed = fs = 105
        pitch = radians(pitch)
        y = project((0, 0), pitch, 1)[1]
        x, z = project((0, 0), yaw, 1)
        z *= -1
        magnitude = sqrt(x**2 + y**2 + z**2)
        self.z_velocity = (z / magnitude) * firing_speed
        self.y_velocity = (y / magnitude) * firing_speed
        self.x_velocity = (x / magnitude) * firing_speed
        dist = ((fs**2)*sin(2*pitch)) / -GRAVITY
        self.flight_time = (dist / (fs*cos(pitch))) * .85

        self.animations = pg.sprite.Group()
        self.timer = 0
        self.alpha = 255
        self.shattered = False
示例#2
0
 def shoot(self, bullets, turkeys, all_sprites, animations):
     """
     Fire a bullet if the player has enough ammo and enough time has passed
     since the last shot.
     """
     if self.cooldown_timer >= self.cooldown_time:
         self.stop_walking()
         if self.shells <= 0:
             prepare.SFX["gunclick"].play()
         else:
             self.shells -= 1
             prepare.SFX["gunshot"].play()
             pos = project(self.pos, (self.angle - .1745) % (2 * pi),
                           42)  #end of rifle at 96x96
             bullet = Bullet(pos, self.angle, bullets, all_sprites)
             distance = 2000.
             x, y = project(pos, self.angle, distance)
             ani = Animation(centerx=x,
                             centery=y,
                             duration=distance / bullet.speed,
                             round_values=True)
             ani.callback = bullet.kill
             ani.start(bullet.rect)
             animations.add(ani)
             scare_rect = self.collider.inflate(1200, 1200)
             scared_turkeys = [
                 t for t in turkeys if scare_rect.colliderect(t.collider)
             ]
             for scared in scared_turkeys:
                 task = Task(scared.flee, 750, args=(self, ))
                 self.animations.add(task)
         task = Task(self.flip_state, 120, args=("idle", ))
         animations.add(task)
         self.cooldown_timer = 0
         self.flip_state("shoot")
 def shoot(self, bullets, turkeys, all_sprites, animations):
     """
     Fire a bullet if the player has enough ammo and enough time has passed
     since the last shot.
     """
     if self.cooldown_timer >= self.cooldown_time:
         self.stop_walking()
         if self.shells <= 0:
             prepare.SFX["gunclick"].play()
         else:
             self.shells -= 1
             prepare.SFX["gunshot"].play()
             pos = project(self.pos, (self.angle - .1745) % (2 * pi), 42) #end of rifle at 96x96
             bullet  = Bullet(pos, self.angle, bullets, all_sprites)
             distance = 2000.
             x, y  = project(pos, self.angle, distance)
             ani = Animation(centerx=x, centery=y, duration=distance/bullet.speed, round_values=True)
             ani.callback = bullet.kill
             ani.start(bullet.rect)
             animations.add(ani)
             scare_rect = self.collider.inflate(1200, 1200)
             scared_turkeys = [t for t in turkeys if scare_rect.colliderect(t.collider)]
             for scared in scared_turkeys:
                 task = Task(scared.flee, 750, args=(self,))
                 self.animations.add(task)
         task = Task(self.flip_state, 120, args=("idle",))
         animations.add(task)
         self.cooldown_timer = 0
         self.flip_state("shoot")
 def update(self, dt):
     self.rotation += self.rotation_speed * dt
     if self.rotation >= .25 * math.pi:
         self.base_image = next(self.images)
         self.rotation -= .25 * math.pi
     self.image = pg.transform.rotate(self.base_image, math.degrees(-self.rotation))
     self.rect = self.image.get_rect()
     self.pos = angles.project(self.pos, self.angle, self.speed * dt)
     self.rect.center = self.pos
 def update(self, dt):
     self.timer += dt
     if self.timer > self.duration:
         self.kill()
     self.intensity = 1 - (self.timer / float(self.duration))
     alpha = max(0, min(255, 255 * self.intensity))
     self.image = self.base_image.copy()
     self.image.fill((0, 0, 0, 255 - alpha), None, pg.BLEND_RGBA_SUB)
     self.pos = angles.project(self.pos, self.angle, self.speed * dt)
     self.rect.center = self.pos
 def update_map(self, level):
     player = level.player
     self.map_surf.fill((0,0,0))
     for planet in level.planets:
         mapx = int(planet.pos[0] * self.xscale)
         mapy = int(planet.pos[1] * self.yscale)
         pg.draw.circle(self.map_surf, planet.color,
                             (mapx, mapy), int(planet.radius * self.xscale))
     px, py = int(player.pos[0] * self.xscale), int(player.pos[1] * self.yscale)
     pg.draw.circle(self.map_surf, pg.Color(0, 220, 220), (px, py), 2)
     pg.draw.line(self.map_surf, pg.Color(0, 220, 220), (px, py), angles.project((px, py), player.angle, 4))
示例#7
0
 def move(self, dt, colliders):
     if self.state == "shoot":
         return
     elif self.state != "move":
         self.flip_state("move")
         self.start_walking()
     dist = self.speed * dt * self.hustle
     pos = project(self.pos, self.angle, dist)
     collider = self.collider.copy()
     collider.center = pos
     if not any((collider.colliderect(obj.collider) for obj in colliders)):
         self.pos = pos
         self.rect.center = self.pos
         self.collider.center = self.pos
 def move(self, dt, colliders):
     if self.state == "shoot":
         return
     elif self.state != "move":
         self.flip_state("move")
         self.start_walking()
     dist = self.speed * dt * self.hustle
     pos = project(self.pos, self.angle, dist)
     collider = self.collider.copy()
     collider.center = pos
     if not any((collider.colliderect(obj.collider) for obj in colliders)):
         self.pos = pos
         self.rect.center = self.pos
         self.collider.center = self.pos
示例#9
0
 def __init__(self, image_name, pivot, radius, angle,
                      minute_length, *groups):
     super(CelestialBody, self).__init__(*groups)
     self.name = image_name
     self.image = prepare.GFX[image_name]
     self.rect = self.image.get_rect()
     self.timer = 0
     self.pivot = pivot
     self.radius = radius
     self.z = 50000
     self.ends = [project(self.pivot, angle - (x * pi), self.radius)
                        for x in (0, .5, 1, 1.5)]
     self.transitions = cycle([("in_sine", "out_sine"),
                                         ("out_sine", "in_sine")])
     self.ends = cycle(self.ends)
     self.rect.center = next(self.ends)
     self.animations = pg.sprite.Group()
     self.make_ani(minute_length)
 def __init__(self, image_name, pivot, radius, angle, minute_length,
              *groups):
     super(CelestialBody, self).__init__(*groups)
     self.name = image_name
     self.image = prepare.GFX[image_name]
     self.rect = self.image.get_rect()
     self.timer = 0
     self.pivot = pivot
     self.radius = radius
     self.z = 50000
     self.ends = [
         project(self.pivot, angle - (x * pi), self.radius)
         for x in (0, .5, 1, 1.5)
     ]
     self.transitions = cycle([("in_sine", "out_sine"),
                               ("out_sine", "in_sine")])
     self.ends = cycle(self.ends)
     self.rect.center = next(self.ends)
     self.animations = pg.sprite.Group()
     self.make_ani(minute_length)
 def move(self, dt):
     self.pos = angles.project(self.pos, self.angle, self.speed * dt)
     self.rect.center = self.pos