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))
def __init__(self, container, shark_size): DirtySprite.__init__(self, container) self.rect = pygame.Rect([150, shark_size[1] - 155, shark_size[0], 10]) # self.rect.x = -1000 self.image = pygame.transform.scale( gfx("shark_laser.png", convert_alpha=True), self.rect.size )
def build_seat( filter1, # type: pymunk.ShapeFilter normal_rect, # type: pygame.Rect pymunk_objects, # type: List[Any] sprites, # type: List[ShapeSprite] ): # type: (...) -> pymunk.Body """ Builds our unicycle cat's unicycle seat. :param filter1: The pymunk Shape filter. :param normal_rect: The cat's normal rect. :param pymunk_objects: The cat's list of pymunk objects. :param sprites: The list of pygame sprites for the cat. """ seat_body = pymunk.Body() seat_body.center_of_gravity = normal_rect.midbottom seat_body.position = normal_rect.topleft seat_shape = make_hitbox(seat_body, normal_rect) seat_shape.mass = 0.5 seat_shape.elasticity = 0 seat_shape.friction = 2 seat_shape.filter = filter1 seat_sprite = ShapeSprite(resources.gfx("seat.png", convert_alpha=True), seat_shape) seat_sprite.layer = 1 sprites.append(seat_sprite) pymunk_objects.append(seat_body) pymunk_objects.append(seat_shape) return seat_body
def build_cat( normal_rect, # type: pygame.Rect pymunk_objects, # type: List[Any] sprites, # type: List[ShapeSprite] ): # type: (...) -> Tuple[pymunk.Body, pygame.Rect] """ Build the cat. :param normal_rect: The cat's normal rect. :param pymunk_objects: The cat's list of pymunk objects. :param sprites: The list of pygame sprites for the cat. :return: The cat's pymunk Body and pygame Rect hitbox. """ cat_surface = resources.gfx("cat.png", convert_alpha=True) cat_rect = pygame.Rect(0, 0, 64, 48) cat_body = pymunk.Body() cat_shape = make_hitbox(cat_body, cat_rect) cat_body.position = normal_rect.x, normal_rect.y - cat_rect.height - 10 cat_shape.mass = 0.001 cat_shape.elasticity = 0.1 cat_shape.friction = 10.0 cat_shape.filter = pymunk.ShapeFilter(group=0b000010) cat_sprite = ShapeSprite(cat_surface, cat_shape, 1.5) cat_sprite.layer = 2 sprites.append(cat_sprite) pymunk_objects.append(cat_body) pymunk_objects.append(cat_shape) return cat_body, cat_rect
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()
def __init__(self, rect): super(Ball, self).__init__() radius = rect.width / 2 body = Body() body.position = rect.center self.shape = Circle(body, radius) self.shape.mass = ball_mass self.shape.elasticity = .25 self.shape.friction = 1 self.rect = Rect(0, 0, rect.width, rect.width) self.original_image = resources.gfx("yarnball.png", convert_alpha=True) self.pymunk_shapes = (body, self.shape)
def __init__(self, game): super().__init__(game) self.player = None self.active = True self.geometry = list() self.space = pymunk.Space() self.space.gravity = (0, 1000) self.sprites = LayeredUpdates() self.event_handler = event_handling.EventQueueHandler() self.background = resources.gfx("background.png", convert=True) self.load() pygame.mixer.music.load(resources.music_path("zirkus.ogg")) pygame.mixer.music.play(-1)
def build_feet( filter1, # type: pymunk.ShapeFilter normal_rect, # type: pygame.Rect pymunk_objects, # type: List[Any] body_body, # type: pymunk.Body seat_body, # type: pymunk.Body ): # type: (...) -> Tuple[pymunk.Body, pygame.Sprite] """ Builds our unicycle cat's feet. :param filter1: The pymunk Shape filter. :param normal_rect: The cat's normal rect. :param pymunk_objects: The cat's list of pymunk objects. :param body_body: The cat's body Pymunk.Body. :param seat_body: The unicycle seat's Pymunk.Body. """ radius = normal_rect.width * 0.55 feet_body = pymunk.Body() feet_shape = pymunk.Circle(feet_body, radius, (0, 0)) feet_shape.mass = 1 feet_shape.elasticity = 0 feet_shape.friction = 100 feet_shape.filter = filter1 feet_sprite = ShapeSprite(resources.gfx("wheel.png", convert_alpha=True), feet_shape) feet_sprite.layer = 0 pymunk_objects.append(feet_body) pymunk_objects.append(feet_shape) # adjust the position of the feet and body feet_body.position = normal_rect.midbottom # motor and joints for feet joint = pymunk.PivotJoint(body_body, feet_body, (normal_rect.centerx, normal_rect.bottom - 10), (0, 0)) pymunk_objects.append(joint) joint = pymunk.PivotJoint(seat_body, feet_body, (normal_rect.centerx, normal_rect.bottom - 10), (0, 0)) pymunk_objects.append(joint) return feet_body, feet_sprite
def build(space, group): scale = 2 normal_rect = pygame.Rect(0, 0, 32 * scale, 40 * scale) model = CatModel() sprites = list() pymunk_objects = list() seat_surface = resources.gfx("seat.png", convert_alpha=True) feet_surface = resources.gfx("wheel.png", convert_alpha=True) filter1 = pymunk.ShapeFilter(group=0b000001) filter2 = pymunk.ShapeFilter(group=0b000010) # Main body body_body = pymunk.Body(0.00001, pymunk.inf) body_body.position = normal_rect.topleft model.main_body = body_body pymunk_objects.append(body_body) # seat seat_body = pymunk.Body() seat_body.center_of_gravity = normal_rect.midbottom seat_body.position = normal_rect.topleft seat_shape = make_hitbox(seat_body, normal_rect) seat_shape.mass = .5 seat_shape.elasticity = 0 seat_shape.friction = 2 seat_shape.filter = filter1 seat_sprite = ShapeSprite(seat_surface, seat_shape) seat_sprite._layer = 1 sprites.append(seat_sprite) pymunk_objects.append(seat_body) pymunk_objects.append(seat_shape) # build feet radius = normal_rect.width * .55 feet_body = pymunk.Body() model.feet = feet_body feet_shape = pymunk.Circle(feet_body, radius, (0, 0)) feet_shape.mass = 1 feet_shape.elasticity = 0 feet_shape.friction = 100 feet_shape.filter = filter1 feet_sprite = ShapeSprite(feet_surface, feet_shape) feet_sprite._layer = 0 sprites.append(feet_sprite) pymunk_objects.append(feet_body) pymunk_objects.append(feet_shape) # adjust the position of the feet and body feet_body.position = normal_rect.midbottom # motor and joints for feet motor = pymunk.SimpleMotor(body_body, feet_body, 0.0) model.motor = motor pymunk_objects.append(motor) x, y = normal_rect.midbottom y -= 10 joint = pymunk.PivotJoint(body_body, feet_body, (x, y), (0, 0)) pymunk_objects.append(joint) joint = pymunk.PivotJoint(seat_body, feet_body, (x, y), (0, 0)) pymunk_objects.append(joint) # cat cat_surface = resources.gfx("cat.png", convert_alpha=True) cat_rect = pygame.Rect(0, 0, 64, 48) cat_body = pymunk.Body() cat_shape = make_hitbox(cat_body, cat_rect) cat_body.position = normal_rect.x, normal_rect.y - cat_rect.height - 10 cat_shape.mass = 0.001 cat_shape.elasticity = .1 cat_shape.friction = 10.0 cat_shape.filter = filter2 cat_sprite = ShapeSprite(cat_surface, cat_shape, 1.5) cat_sprite._layer = 2 sprites.append(cat_sprite) pymunk_objects.append(cat_body) pymunk_objects.append(cat_shape) # hold cat the the seat spring = pymunk.DampedSpring(seat_body, cat_body, normal_rect.midtop, cat_rect.midbottom, 0, 1, 0) pymunk_objects.append(spring) # tilt corrector spring = pymunk.DampedRotarySpring(body_body, seat_body, radians(0), 60000, 20000) spring.collide_bodies = False pymunk_objects.append(spring) model.sprites = sprites model.pymunk_objects = pymunk_objects space.add(pymunk_objects) group.add(*sprites) return model
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
def __init__(self, group, pos, vel): image = gfx("ring.png", convert_alpha=True) FlyingObject.__init__(self, group, pos, vel, image)
def __init__(self, group, pos, vel): image = gfx("fish_" + random.choice(Fish.colors) + ".png", convert_alpha=True) FlyingObject.__init__(self, group, pos, vel, image)