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")
Exemplo n.º 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 add_leaf(self, tree, spot_info):
     """Add a falling leaf."""
     fall_time = randint(2000, 2500)
     leaf = Leaf(tree, spot_info, self.leaves, self.all_sprites)
     y = leaf.rect.centery + leaf.fall_distance
     ani = Animation(centery=y, duration=fall_time, round_values=True)
     ani.callback = leaf.land
     ani.start(leaf.rect)
     ani2 = Animation(centery=leaf.collider.centery + leaf.fall_distance,
                                duration=fall_time, round_values=True)
     ani2.start(leaf.collider)
     fade = Animation(img_alpha=0, duration=3000, delay=fall_time,
                               round_values=True)
     fade.callback = leaf.kill
     fade.update_callback = leaf.set_alpha
     fade.start(leaf)
     self.animations.add(ani, ani2, fade)
Exemplo n.º 4
0
 def go_down(self):
     ani = Animation(y=80,
                     duration=self.time_span // 2,
                     round_values=True,
                     transition="in_quad")
     ani.callback = self.finish
     ani.start(self.rect)
     self.animations.add(ani)
Exemplo n.º 5
0
 def fade_out(self):
     ani = Animation(curtain_alpha=255,
                     duration=6000,
                     round_values=True,
                     transition="out_quad")
     ani.callback = self.leave_state
     ani.start(self)
     self.animations.add(ani)
Exemplo n.º 6
0
 def add_leaf(self, tree, spot_info):
     """Add a falling leaf."""
     fall_time = randint(2000, 2500)
     leaf = Leaf(tree, spot_info, self.leaves, self.all_sprites)
     y = leaf.rect.centery + leaf.fall_distance
     ani = Animation(centery=y, duration=fall_time, round_values=True)
     ani.callback = leaf.land
     ani.start(leaf.rect)
     ani2 = Animation(centery=leaf.collider.centery + leaf.fall_distance,
                      duration=fall_time,
                      round_values=True)
     ani2.start(leaf.collider)
     fade = Animation(img_alpha=0,
                      duration=3000,
                      delay=fall_time,
                      round_values=True)
     fade.callback = leaf.kill
     fade.update_callback = leaf.set_alpha
     fade.start(leaf)
     self.animations.add(ani, ani2, fade)
Exemplo n.º 7
0
    def _animate_hide_sprite(self, sprite):
        """Animate and hide the sprite
        :param sprite: pygame.sprite.Sprite
        :return: None
        """

        def kill():
            del self._animation_dict[sprite]
            sprite.kill()

        ani = Animation(y=800, round_values=True,
                        duration=500, transition='out_quint')
        ani.callback = kill
        ani.start(sprite.rect)
        self._animation_dict[sprite] = ani
        return ani
Exemplo n.º 8
0
 def __init__(self, leader_centerpoint, animations, all_sprites, *groups):
     super(Flock, self).__init__(*groups)
     x, y = leader_centerpoint
     for offset in self.offsets:
         center = x + offset[0], y + offset[1]
         duck = Duck(center, all_sprites)
         if offset == (0, 0):
             self.leader = duck
         dest = duck.rect.y + (prepare.WORLD_SIZE[1] * 2)
         ani = Animation(y=dest, duration=self.fly_time, round_values=True)
         ani.callback = duck.kill
         ani.start(duck.rect)
         flap_time = randint(100, 150)
         task = Task(duck.flap, flap_time, self.fly_time // flap_time)
         animations.add(ani, task)
     finish = Task(self.kill, self.fly_time + 100)
     animations.add(finish)
     self.honked = False
 def __init__(self, leader_centerpoint, animations, all_sprites, *groups):
     super(Flock, self).__init__(*groups)
     x, y  = leader_centerpoint
     for offset in self.offsets:
         center = x + offset[0], y + offset[1]
         duck = Duck(center, all_sprites)
         if offset == (0, 0):
             self.leader = duck
         dest = duck.rect.y + (prepare.WORLD_SIZE[1] * 2)
         ani = Animation(y=dest, duration=self.fly_time, round_values=True)
         ani.callback = duck.kill
         ani.start(duck.rect)
         flap_time = randint(100, 150)
         task = Task(duck.flap, flap_time, self.fly_time // flap_time)
         animations.add(ani, task)
     finish = Task(self.kill, self.fly_time + 100)
     animations.add(finish)
     self.honked = False
Exemplo n.º 10
0
    def __init__(self, time_span):
        self.time_span = time_span
        self.screen_rect = pg.display.get_surface().get_rect()
        self.image = pg.transform.scale2x(prepare.GFX["moon"])
        w, h = self.image.get_size()
        self.rect = self.image.get_rect(topleft=(-w // 2, 80))

        self.animations = pg.sprite.Group()
        ani = Animation(y=-50,
                        duration=time_span // 2,
                        round_values=True,
                        transition="out_quad")
        ani.callback = self.go_down
        ani.start(self.rect)
        ani2 = Animation(x=self.screen_rect.right - w // 2,
                         duration=time_span,
                         round_values=True,
                         transition="linear")
        ani2.start(self.rect)
        self.animations.add(ani, ani2)
Exemplo n.º 11
0
 def add_chair(self, midbottom, direction):
     """Add a single chair to the chairlift."""
     centerx, bottom = midbottom
     if direction == "up":
         x_offset = 18
         destination = self.top_lifthut.rect.bottom + 10 
         distance = bottom - destination
         klass = UpChair
     elif direction == "down":
         x_offset = -19
         destination = self.bottom_lifthut.rect.top + 70
         distance = destination - bottom
         klass = DownChair
     duration = distance * 30
     chair = klass((centerx + x_offset, bottom), self.chairs)
     ani = Animation(bottom=destination, duration=duration, round_values=True)
     opposite = "up" if direction == "down" else "down"
     ani.start(chair.rect)
     ani.callback = chair.kill
     task = Task(self.recycle_chair, interval=duration, args=(opposite,))
     self.animations.add(ani, task)