Exemple #1
0
 def _start_jump(self, key):
     self.jump_key = key
     if self.touching_ground and not self.jumping:
         self.jumping = True
         self.jumping_time = 0
         self.player_data.cat_speed[1] -= 12.5
         sfx("cat_jump.ogg", play=1)
Exemple #2
0
    def reset_on_death(self):
        """Reset on death.

        What to do when you die, reset the level.
        """
        self.player_data.reset()
        self.total_time = 0

        self.elephant.last_animation = 0
        self.elephant.state = 0
        self.elephant.just_happened = None
        self.elephant.dirty = 1
        self.elephant_active = False
        self.elephant.animate(self.total_time)

        # make the shark leave
        self.shark_active = False
        self.shark.last_animation = 0
        self.shark.dirty = True

        if self.shark.get_state() in ("aiming", "fire laser"):
            self.shark.just_happened = None
            self.shark.set_state("leaving")
            self.shark.applaud = False
        else:
            self.shark.just_happened = None
            self.shark.set_state("offscreen")
            self.shark.animate(self.total_time)

        sfx("shark_appear.ogg", fadeout=1000)

        if self.shark.lazer:
            self.shark.lazer.kill()
Exemple #3
0
 def _meow(self):
     # Play a meow sound, but not the same one twice in a row
     meow_names = self.meow_names[:]
     if self.last_meow in self.meow_names:
         meow_names.remove(self.last_meow)
     self.last_meow = random.choice(meow_names)
     sfx(self.last_meow, play=1)
     self._reset_meow()
    def update(self, *args, **kwargs):
        FlyingObject.update(self, *args, **kwargs)

        if (
            distance(
                [self.rect[0], self.rect[1]], kwargs["player_data"].cat_head_location
            )
            < 100
        ):
            kwargs["player_data"].increment_score()
            self.kill()
            sfx("eatfish.ogg", play=1)
Exemple #5
0
    def __init__(self, cat_holder):
        AnimatedCat.__init__(self)
        self.cat_holder = cat_holder
        self.image = gfx("cat_unicycle1.png", convert_alpha=True)
        self.rect = self.image.get_rect()
        sfx("cat_jump.ogg")

        self.images = []
        self.flipped_images = []

        for i in range(self.num_frames):
            img = gfx("cat_unicycle%d.png" % (i + 1), convert_alpha=True)
            self.images.append(img)
            self.flipped_images.append(pygame.transform.flip(img, 1, 0))
Exemple #6
0
    def __init__(self, scene):
        DirtySprite.__init__(self)

        self.scene = scene

        self.animation = ElephantAnimation()

        # stamp.
        sfx("foot_elephant.ogg")

        self.rect = pygame.Rect(
            [0, 0, self.scene.width // 2, self.scene.height])
        self.image = Surface((self.rect[2], self.rect[3])).convert()
        self.image.fill((255, 0, 0))

        self.rect.x = -1000
        self.rect.y = -1000
Exemple #7
0
    def _collide_flying_objects(self):
        """object physics"""
        height = self.height
        dt_scaled = self.dt_scaled

        # move fish and not fish
        for fish in reversed(self.fish.sprites()):
            fish.pos[0] += fish.velocity[0] * dt_scaled  # speed of the throw
            fish.velocity[1] += 0.2 * dt_scaled  # gravity
            fish.pos[1] += fish.velocity[1] * dt_scaled  # y velocity
            # check out of bounds
            if fish.pos[1] > height:
                self.fish.remove(fish)
                fish.kill()
        for fish in reversed(self.not_fish.sprites()):
            fish.pos[0] += fish.velocity[0] * dt_scaled  # speed of the throw
            fish.velocity[1] += 0.2 * dt_scaled  # gravity
            fish.pos[1] += fish.velocity[1] * dt_scaled  # y velocity
            # check out of bounds
            if fish.pos[1] > height:
                self.not_fish.remove(fish)
                fish.kill()

        # check collision with the cat
        for fish in reversed(self.fish.sprites()):
            if (distance([fish.rect[0], fish.rect[1]],
                         self.player_data.cat_head_location) < 100):
                self.player_data.increment_score()
                self.fish.remove(fish)
                sfx("eatfish.ogg", play=1)
                fish.kill()
        for fish in reversed(self.not_fish.sprites()):
            if (distance([fish.rect[0], fish.rect[1]],
                         self.player_data.cat_head_location) < 50):
                self.not_fish.remove(fish)
                fish.kill()
                self.player_data.angle_to_not_fish = (math.atan2(
                    self.player_data.cat_head_location[1] - fish.rect[1],
                    self.player_data.cat_head_location[0] - fish.rect[0],
                ) - math.pi / 2)
                side = 1 if self.player_data.angle_to_not_fish < 0 else -1
                self.player_data.cat_angular_vel += side * random.uniform(
                    0.08, 0.15)
                sfx(random.choice(self.boing_names), play=True)
Exemple #8
0
    def fire_laserbeam(self, debug):
        """
        Fires the shark's head mounted laser cannon.

        :param debug:
        """
        if debug:
            print(self.just_happened)
        self.lazer = Lazer(self.container, (self.width, self.height))

        sfx("shark_lazer.ogg", play=1)

        if (
            self.scene.player_data.cat_location[1]
            > self.scene.player_data.cat_wire_height - 3
        ):
            sfx("cat_shot.ogg", play=1)

            self.lazered = True
        else:
            self.lazered = False
Exemple #9
0
    def _move_cat(self):
        """Move, accelerate, and tilt the cat."""

        # accelerate the cat left or right
        if self.right_pressed:
            self.player_data.cat_speed[0] = min(
                self.player_data.cat_speed[0] + 0.3 * self.dt_scaled,
                self.player_data.cat_speed_max,
            )
            self.player_data.cat_angle -= 0.003 * self.dt_scaled

        if self.left_pressed:
            self.player_data.cat_speed[0] = max(
                self.player_data.cat_speed[0] - 0.3 * self.dt_scaled,
                -self.player_data.cat_speed_max,
            )
            self.player_data.cat_angle += 0.003 * self.dt_scaled

        # make the cat fall
        angle_sign = 1 if self.player_data.cat_angle > 0 else -1
        self.player_data.cat_angular_vel += 0.0002 * angle_sign * self.dt_scaled
        self.player_data.cat_angle += self.player_data.cat_angular_vel * self.dt_scaled
        if (self.player_data.cat_angle > math.pi / 2
                or self.player_data.cat_angle < -math.pi / 2
            ) and self.player_data.cat_location[1] > self.height - 160:
            sfx("cat_crash.ogg", play=1)
            self.reset_on_death()

        # move cat
        self.player_data.cat_location[0] += (self.player_data.cat_speed[0] *
                                             self.dt_scaled)
        self.player_data.cat_location[1] += (self.player_data.cat_speed[1] *
                                             self.dt_scaled)
        if (self.player_data.cat_location[1] > self.player_data.cat_wire_height
                and self.player_data.cat_location[0] > 0.25 * self.width):
            self.touching_ground = True
            self.player_data.cat_location[1] = self.player_data.cat_wire_height
            self.player_data.cat_speed[1] = 0
        else:
            self.touching_ground = False
Exemple #10
0
    def event(self, event):
        """
        Process an event.

        :param event: The event to process
        """
        events = self.event_handler.process_event(event)
        position = self.player.position

        for evt in events:
            try:
                cmd, arg = self.fsm((evt.button, evt.held))
            except ValueError:
                continue

            if cmd == "move":
                resources.sfx("cat_wheel.ogg", False, True)
                resources.sfx("cat_wheel.ogg", True)
                self.player.accelerate(arg)

            if cmd == "idle":
                self.player.brake()

            elif cmd == "jump":
                resources.sfx("cat_jump.ogg", True)
                self.player.main_body.apply_impulse_at_world_point((0, -600),
                                                                   position)
Exemple #11
0
    def _cat_out_of_bounds(self):
        """check for out of bounds"""

        # in the pool
        if self.player_data.cat_location[1] > self.height:
            sfx("splash.ogg", play=1)
            self._meow()
            self.reset_on_death()

        # to the right of screen.
        if self.player_data.cat_location[0] > self.width:
            self.player_data.cat_location[0] = self.width
            if self.player_data.cat_angle > 0:
                self.player_data.cat_angle *= 0.7

        self.player_data.cat_head_location = [
            int(self.player_data.cat_location[0] +
                100 * math.cos(self.player_data.cat_angle - math.pi / 2)),
            int(self.player_data.cat_location[1] +
                100 * math.sin(self.player_data.cat_angle - math.pi / 2)),
        ]

        if (self.player_data.cat_location[0] > 0.98 * self.width
                and self.player_data.cat_location[1] >
                self.player_data.cat_wire_height - 30):
            # bump the cat back in
            self._meow()
            sfx(random.choice(self.boing_names), play=True)
            self.player_data.cat_angular_vel -= 0.01 * self.dt_scaled
            self.player_data.cat_speed[0] = -5
            self.player_data.cat_speed[1] = -20
            # self.reset_on_death()
        if (self.player_data.cat_location[0] < 0.25 * self.width
                and self.player_data.cat_location[1] >
                self.player_data.cat_wire_height - 30):
            pass
Exemple #12
0
    def update(self, *args, **kwargs):
        """
        Update the elephant.
        """
        # if self.animation.just_happened is not None:
        #     print(self.animation.just_happened)
        from_top = 100

        if self.animation.just_happened == "offscreen":
            self.dirty = True
            self.rect.x = -1000
            self.rect.y = -1000
            sfx("foot_elephant.ogg", stop=1)
        elif self.animation.just_happened == "poise left":
            self.rect.x = 0
            self.rect.y = from_top - self.scene.height
            self.dirty = True
            sfx("foot_elephant.ogg", play=1)
        elif self.animation.just_happened == "stomp left":
            # (self.height - self.image.get_height()) - self.scene.cat_wire_height
            self.rect.y = self.scene.cat_wire_height - self.scene.height
            self.rect.x = 0
            self.dirty = True

            if collide_rect(self, self.scene.cat):
                self.scene.reset_on_death()
                self.dirty = True

        elif self.animation.just_happened == "poise right":
            self.rect.x = self.scene.width // 2
            self.rect.y = from_top - self.scene.height
            self.dirty = True
            sfx("foot_elephant.ogg", play=1)
        elif self.animation.just_happened == "stomp right":
            self.rect.x = self.scene.width // 2
            self.rect.y = self.scene.cat_wire_height - self.scene.height
            self.dirty = True
            if collide_rect(self, self.scene.cat):
                self.scene.reset_on_death()
                self.dirty = True
Exemple #13
0
 def _stop_jump(self):
     self.jumping = False
     sfx("cat_jump.ogg", fadeout=50)
Exemple #14
0
    def __init__(self, *args, **kwargs):
        Scene.__init__(self, *args, **kwargs)

        (width, height) = (1920 // 2, 1080 // 2)
        self.width, self.height = width, height

        # Loading screen should always be a fallback active scene
        self.active = False
        self.first_render = True

        self.myfont = pygame.font.SysFont("monospace", 20)

        self.background = gfx("background.png", convert=True)
        # self.cat_unicycle = gfx('cat_unicycle.png').convert_alpha()
        # self.fish = gfx('fish.png').convert_alpha()
        # self.foot = gfx('foot.png').convert_alpha()
        # self.foot_part = gfx('foot_part.png').convert_alpha()
        # self.shark = gfx('shark.png').convert_alpha()

        sfx("cat_jump.ogg")
        sfx("eatfish.ogg")
        sfx("splash.ogg")
        sfx("cat_crash.ogg")

        self.meow_names = [
            "cat_meow01.ogg", "cat_meow02.ogg", "cat_meow03.ogg"
        ]
        self.last_meow = None

        self.touching_ground = True
        self.jumping = False
        self.jumping_time = 0
        self.jump_key = None

        for meow_name in self.meow_names:
            sfx(meow_name)

        self.boing_names = ["boing1.ogg", "boing2.ogg", "boing3.ogg"]
        for boing_name in self.boing_names:
            sfx(boing_name)

        self.people_mad = False
        self.people_mad_duration = 3000  # ms
        self.people_mad_current_time = 0
        self.next_notfish = 0
        self.notfish_time = 0

        self.last_joy_right_tilt = 0
        self.last_joy_left_tilt = 0

        self.left_pressed = False
        self.right_pressed = False
        self.player_data = PlayerData(width, height)

        # timing
        self.dt_scaled = 0
        self.total_time = 0

        # elephant and shark classes
        self.elephant = Elephant(self)
        self.shark_active = False  # is the shark enabled yet
        self.elephant_active = False
        self.cat = Cat(self)
        self.score_text = Score(self)

        self.allsprites = None  # type: Optional[LayeredDirty]
        self.shark = None  # type: Optional[Shark]
        self.init_sprites()

        # lists of things to catch by [posx, posy, velx, vely]
        # self.fish = [[0, height / 2, 10, -5]]
        self.fish = LayeredDirtyAppend()
        self.fish.extend([Fish(self.allsprites, (0, height / 2), (10, -5))])

        self.not_fish = LayeredDirtyAppend()

        self.unicycle_sound = sfx("unicycle.ogg",
                                  play=True,
                                  loops=-1,
                                  fadein=500)

        self._reset_meow()

        # difficulty varibles
        self.number_of_not_fish = 0
Exemple #15
0
    def update(self, *args, **kwargs):

        if self.debug and self.just_happened:
            print(self.just_happened)

        if self.just_happened == "offscreen":
            sfx("shark_gone.ogg", stop=1)

            self.rect.x = -1000
            self.dirty = True

        elif self.just_happened == "about_to_appear":
            music(stop=True)
            self.applaud = True
            sfx("shark_appear.ogg", play=1)

        elif self.just_happened == "poise":
            sfx("shark_attacks.ogg", play=1)

            self.rect.x = -30
            self.dirty = True

        elif self.just_happened == "fire laser":
            self.fire_laserbeam(self.debug)

        elif self.just_happened == "leaving":
            sfx("shark_appear.ogg", fadeout=3500)
            sfx("shark_attacks.ogg", stop=1)
            sfx("shark_gone.ogg", play=1)
            self.dirty = True
            if self.lazered:
                sfx("boo.ogg", play=True)
                self.scene.reset_on_death()
                self.lazered = False
                self.scene.annoy_crowd()
            elif self.applaud:
                sfx("applause.ogg", play=1)
            if self.lazer:
                self.lazer.kill()
                self.lazer = None
Exemple #16
0
    def __init__(self, container, scene, width, height):
        DirtySprite.__init__(self, container)
        self.debug = False
        self.container = container
        self.scene = scene
        self.width, self.height = width, height

        self.state = 0  #
        self.states = {
            0: "offscreen",
            1: "about_to_appear",
            2: "poise",
            3: "aiming",
            4: "fire laser",
            5: "leaving",
        }
        self.last_state = 0
        self.just_happened = None
        self.lazered = False  # was the cat hit?
        self.lazer = None  # type: Optional[Lazer]
        self.laser_height = height - 150  # where should the laser be on the screen?

        # TODO: to make it easier to test the shark
        #        self.time_between_appearances = 1000 #ms
        # self.time_between_appearances = 5000 #ms

        # self.time_of_about_to_appear = 1000#ms
        # self.time_of_poise = 1000 #ms
        # self.time_of_aiming = 500 #ms
        # self.time_of_laser = 200 #ms
        # self.time_of_leaving = 1000 #ms

        self.timings = {
            "time_between_appearances": 5000,
            "time_of_about_to_appear": 1000,
            "time_of_poise": 1000,
            "time_of_aiming": 500,
            "time_of_laser": 200,
            "time_of_leaving": 1000,
        }
        self.last_animation = 0  # ms

        self.applaud = True

        sfx("default_shark.ogg")
        sfx("shark_appear.ogg")
        sfx("shark_gone.ogg")
        sfx("shark_lazer.ogg")
        sfx("applause.ogg")
        sfx("cat_shot.ogg")
        sfx("boo.ogg")

        self.image = gfx("shark.png", convert_alpha=True)
        # gfx('foot_part.png').convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.x = -1000
        self.rect.y = self.height - self.image.get_height()