Example #1
0
    def __init__(self, pos, image, space, anim_name="", num_frames=1, sequence=[0, 1], frequency=8):
        self.is_movable = True
        GameObject.__init__(
            self, pos, util.to_sprite(util.load_image("data/info_sign0.png")), space, OBJECT_TYPE_INFO, pm.inf
        )
        self.body, self.shape = create_box(space, (pos.x, pos.y), frequency, 12.0)
        self.shape.collision_type = OBJECT_TYPE_INFO
        self.info_bubble = util.load_image(image)
        space.add_static(self.shape)
        self._show_info = False
        self.cool_down = 0.0

        if not anim_name == "":
            self.animation = animation.new_animation(anim_name, "png", num_frames, frequency, sequence)
        self.animation.play()
Example #2
0
    def load(self, filepath, space):
        import sys

        # goal
        doorblock = util.load_image("data/entity_door0.png")

        # standard blocks
        rblock = util.load_image("data/red_block16.png")
        gblock = util.load_image("data/green_block16.png")
        bblock = util.load_image("data/blue_block16.png")
        wblock = util.load_image("data/bw_block16.png")
        # keys
        rkblock = util.load_image("data/red_key0.png")
        gkblock = util.load_image("data/green_key0.png")
        bkblock = util.load_image("data/blue_key0.png")
        # movable
        r_movableblock = util.load_image("data/red_movable_block0.png")
        g_movableblock = util.load_image("data/green_movable_block0.png")
        b_movableblock = util.load_image("data/blue_movable_block0.png")

        with open(filepath) as f:
            data = f.readlines()

        xoffset = 7
        yoffset = 3

        for rnum, row in enumerate(data):
            for cnum, col in enumerate(row):
                movable = False
                if col == "1":
                    block = r_movableblock
                    movable = True
                    type = gameobject.OBJECT_TYPE_RED
                elif col == "2":
                    block = g_movableblock
                    movable = True
                    type = gameobject.OBJECT_TYPE_GREEN
                elif col == "3":
                    block = b_movableblock
                    movable = True
                    type = gameobject.OBJECT_TYPE_BLUE
                elif col == "R":
                    block = rblock
                    type = gameobject.OBJECT_TYPE_RED
                elif col == "G":
                    block = gblock
                    type = gameobject.OBJECT_TYPE_GREEN
                elif col == "B":
                    block = bblock
                    type = gameobject.OBJECT_TYPE_BLUE
                elif col == "W":
                    block = wblock
                    type = gameobject.OBJECT_TYPE_BW
                elif col == "X":
                    block = rkblock
                    type = gameobject.OBJECT_TYPE_KEY_RED
                elif col == "Y":
                    block = gkblock
                    type = gameobject.OBJECT_TYPE_KEY_GREEN
                elif col == "Z":
                    block = bkblock
                    type = gameobject.OBJECT_TYPE_KEY_BLUE
                elif col == "D":
                    block = doorblock
                    type = gameobject.OBJECT_TYPE_GOAL
                    self.doorpos = (cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
                elif col == "P":
                    self.player.body.position = (cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
                    continue
                else:
                    continue
                pos = util.vec2(cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
                if movable:
                    go = gameobject.MovableBlock(pos, util.to_sprite(block), space, type)
                    self.game_objects.append(go)
                else:
                    go = gameobject.StaticBlock(pos, util.to_sprite(block), space, type)
                    self.tiles.append(go)
Example #3
0
    def __init__(self, pos, space):
        gameobject.GameObject.__init__(self, pos, util.to_sprite(util.load_image("data/bw_player16.png")), space, gameobject.OBJECT_TYPE_PLAYER, 10.0)
        self.body, self.shape = gameobject.create_ball(space, (pos.x, pos.y), 8, 6)
        space.add(self.body, self.shape)
        self.shape.collision_type = gameobject.OBJECT_TYPE_PLAYER
        #self.shape.collision_type = gameobject.OBJECT_TYPE_PLAYER
        self.stop_hammer_time = False
        self.in_air = True
        self.is_pushing = False

        self.honk_timer = False
        self.honk_time = 4
        self.time_to_honk = 0
        self.show_honk = False
        self.honk_animation = animation.new_animation("data/honk_honk","png",1,1,[0,1,1])
        self.honk_animation_r = animation.new_animation("data/honk_honk_r","png",1,1,[0,1,1])
        #util.load_image("data/honk_honk0.png")#animation.new_animation("data/")

        self.animations = {}
        self.active_color = game.CBLUE

        #load animations
        animation_freq = 4

        red_player_push_left = animation.new_animation("data/red_guy_push","png",1,animation_freq,[0,1])
        red_player_push_right = animation.new_animation("data/red_guy_push_r","png",1,animation_freq,[0,1])

        red_player_walk_left = animation.new_animation("data/red_guy_walk","png",1,animation_freq,[0,1])
        red_player_walk_right = animation.new_animation("data/red_guy_walk_r","png",1,animation_freq,[0,1])

        green_player_walk_left = animation.new_animation("data/green_guy_walk","png",1,animation_freq,[0,1])
        green_player_walk_right = animation.new_animation("data/green_guy_walk_r","png",1,animation_freq,[0,1])

        green_player_push_left = animation.new_animation("data/green_guy_push","png",1,animation_freq,[0,1])
        green_player_push_right = animation.new_animation("data/green_guy_push_r","png",1,animation_freq,[0,1])

        blue_player_walk_left = animation.new_animation("data/blue_guy_walk","png",1,animation_freq,[0,1])
        blue_player_walk_right = animation.new_animation("data/blue_guy_walk_r","png",1,animation_freq,[0,1])

        blue_player_push_left = animation.new_animation("data/blue_guy_push","png",1,animation_freq,[0,1])
        blue_player_push_right = animation.new_animation("data/blue_guy_push_r","png",1,animation_freq,[0,1])

        #player_walk_left.play()
        self.image = None

        # red player animations:
        self.animations["red_player_walk_left"] = red_player_walk_left
        self.animations["red_player_walk_right"] = red_player_walk_right

        self.animations["red_player_push_left"] = red_player_push_left
        self.animations["red_player_push_right"] = red_player_push_right

        # green player animations:
        self.animations["green_player_walk_left"] = green_player_walk_left
        self.animations["green_player_walk_right"] = green_player_walk_right

        self.animations["green_player_push_left"] = green_player_push_left
        self.animations["green_player_push_right"] = green_player_push_right

        # blue player animations:
        self.animations["blue_player_walk_left"] = blue_player_walk_left
        self.animations["blue_player_walk_right"] = blue_player_walk_right

        self.animations["blue_player_push_left"] = blue_player_push_left
        self.animations["blue_player_push_right"] = blue_player_push_right

        self.current_animation = red_player_walk_left
        self.look_dir = game.PDIR_LEFT
        self.active_color = game.CRED
        self.has_changed = True
Example #4
0
            )
            self.animation.draw(canvas, pos, True)
        else:
            if self.animation.playing:
                self.animation.stop()

    def activate(self):
        # called when player lala
        self.cool_down = 2.0
        self._show_info = True

    def deactivate(self):
        self._show_info = False


splosion_red = util.to_sprite(util.load_image("data/red_explosion.png"))
splosion_green = util.to_sprite(util.load_image("data/green_explosion.png"))
splosion_blue = util.to_sprite(util.load_image("data/blue_explosion.png"))


class SplosionBlock(GameObject):
    def __init__(self, pos, space, color_type):
        if color_type == OBJECT_TYPE_RED:
            t_sprite = splosion_red
        elif color_type == OBJECT_TYPE_GREEN:
            t_sprite = splosion_green
        else:
            t_sprite = splosion_blue
        GameObject.__init__(self, pos, t_sprite, space, OBJECT_TYPE_SPLOSION, pm.inf)
        self.body, self.shape = create_ball(self, (pos.x, pos.y), mass=0.6, radius=0.4)
        self.shape.collision_type = OBJECT_TYPE_SPLOSION