Ejemplo n.º 1
0
    public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        Goomba goomba = shape1.GetComponent <Goomba>();
        Player player = shape2.GetComponent <Player>();

        if (goomba.dieAnim.isDying() || player.isDying())
        {
            arbiter.Ignore();         // avoid the collision to continue since this frame
            return(false);            // avoid the collision to continue since this frame
        }

        goomba.idle.setIdle(true);

        // if collides from top then kill the goomba
        if (GameObjectTools.isHitFromAbove(goomba.transform.position.y, shape2.body, arbiter))
        {
            goomba.die();
            // makes the player jumps a little upwards
            player.forceJump();
        }
        // kills Player
        else
        {
            arbiter.Ignore();                     // avoid the collision to continue since this frame
            LevelManager.Instance.loseGame(true); // force die animation
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(true);
    }
Ejemplo n.º 2
0
    public static bool presolveCollisionWithOneway(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        // if collision was from below then continue with oneway platform logic
        if (GameObjectTools.isHitFromBelow(arbiter))
        {
            arbiter.Ignore();
            return(false);
        }

        Player player = shape1.getOwnComponent <Player>();

        // if player wants to climb down (once it is over the platform) then disable the collision to start free fall
        if (player.GetComponent <ClimbDownFromPlatform>().isClimbingDown())
        {
            player.jump.reset();             // set state as if were jumping
            arbiter.Ignore();
            return(false);
        }

        // let the collision happens
        return(true);
    }
Ejemplo n.º 3
0
    public static bool beginCollisionWithAny(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        // change direction of movement whenever hit something like a wall
        if (GameObjectTools.isWallHit(arbiter))
        {
            Patrol p1 = shape1.GetComponent <Patrol>();
            if (p1 != null && p1.enabled)
            {
                p1.toogleDir();
            }
            Patrol p2 = shape2.GetComponent <Patrol>();
            if (p2 != null && p2.enabled)
            {
                p2.toogleDir();
            }
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next fixed step.
        return(true);
    }
Ejemplo n.º 4
0
    public static bool beginCollisionWithScenery(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        Jump jump = shape1.GetComponent <Jump>();

        // if is jumping and hits a wall then continue the collision

        /*if (jump != null && jump.isJumping && GameObjectTools.isWallHit(arbiter))
         *      return true;*/

        if (jump != null && GameObjectTools.isGrounded(arbiter))
        {
            if (jump.foreverJump)
            {
                jump.forceJump(jump.foreverJumpVel);
            }
            // if it was jumping then reset jump behavior
            else if (jump.isJumping)
            {
                jump.stop();
            }
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(true);
    }
Ejemplo n.º 5
0
    public static bool beginCollisionWithScenery(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        Player player = shape1.getOwnComponent <Player>();

        if (player.isDying())
        {
            return(false);            // stop collision with scenery since this frame
        }
        player.exitedFromScenery = false;

        // Avoid ground penetration (Y axis). Another way: see collisionBias and/or minPenetrationForPenalty config in CollisionManagerCP.
        // Currently is being addressed by AirGroundControlUpdater and in WalkAbs

        /*if (GameObjectTools.isGrounded(arbiter)) {
         *      Vector2 thePos = player.body.position;
         * float depth = arbiter.GetDepth(0);
         *      thePos.y -= depth;
         * player.body.position = thePos;
         * }*/

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next fixed step.
        return(true);
    }
Ejemplo n.º 6
0
    public static bool beginCollisionWithKoopaTroopa(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        KoopaTroopa koopa1    = shape1.GetComponent <KoopaTroopa>();
        KoopaTroopa koopa2    = shape2.GetComponent <KoopaTroopa>();
        bool        hidden1   = koopa1._hide.isHidden();
        bool        hidden2   = koopa2._hide.isHidden();
        bool        bouncing1 = koopa1.bounce.isBouncing();
        bool        bouncing2 = koopa2.bounce.isBouncing();

        // avoid koopa1 pushes hidden koopa2
        Chase chase = shape1.GetComponent <Chase>();

        if (chase != null && chase.isChasing())
        {
            chase.stopChasing();
            chase.enableOperateWhenOutOfSensor();
        }
        // avoid koopa2 pushes hidden koopa1
        chase = shape2.GetComponent <Chase>();
        if (chase != null && chase.isChasing())
        {
            chase.stopChasing();
            chase.enableOperateWhenOutOfSensor();
        }

        // is koopa above the other koopa?
        if (GameObjectTools.isGrounded(arbiter))
        {
            if (!hidden1)
            {
                koopa1.jump.forceJump(koopa1.jumpSpeed);
            }
            else
            {
                koopa2.jump.forceJump(koopa1.jumpSpeed);
            }
            // NOTE: I assume here the isGrounded() works as expected
            return(false);            // avoid the collision to continue since this frame
        }
        // kills koopa 2
        else if (bouncing1 && !hidden2 && !bouncing2)
        {
            //koopa2.die();
            koopa2.hide();
        }
        // kills koopa 1
        else if (bouncing2 && !hidden1 && !bouncing1)
        {
            //koopa1.die();
            koopa1.hide();
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(true);
    }
Ejemplo n.º 7
0
    public static bool beginCollisionWithPowerUp(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        KoopaTroopa koopa   = shape1.getOwnComponent <KoopaTroopa>();
        PowerUp     powerUp = shape2.getOwnComponent <PowerUp>();

        powerUp.Invoke("destroy", 0f);         // a replacement for Destroy
        koopa.stop();

        // hide or kill the koopa
        if (koopa._hide.isHidden())
        {
            koopa.die();
        }
        else
        {
            koopa.hide();
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next fixed step.
        return(false);
    }
Ejemplo n.º 8
0
    public static bool beginCollisionWithKoopaTroopa(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        KoopaTroopa koopa1    = shape1.getOwnComponent <KoopaTroopa>();
        KoopaTroopa koopa2    = shape2.getOwnComponent <KoopaTroopa>();
        bool        hidden1   = koopa1._hide.isHidden();
        bool        hidden2   = koopa2._hide.isHidden();
        bool        bouncing1 = koopa1.bounce.isBouncing();
        bool        bouncing2 = koopa2.bounce.isBouncing();

        // avoid koopa1 pushes hidden koopa2
        Chase chase1 = shape1.GetComponent <Chase>();

        if (chase1 != null && chase1.isChasing())
        {
            chase1.stop();
            chase1.enableOperateWhenOutOfSensor();
        }
        // avoid koopa2 pushes hidden koopa1
        Chase chase2 = shape2.GetComponent <Chase>();

        if (chase2 != null && chase2.isChasing())
        {
            chase2.stop();
            chase2.enableOperateWhenOutOfSensor();
        }

        // is koopa1 above the koopa2?
        if (GameObjectTools.isGrounded(arbiter))
        {
            if (!hidden1 && koopa1.jump.isJumping())
            {
                koopa1.jump.forceJump(koopa1.jumpSpeed);
            }
            else if (hidden1 && koopa2.jump.isJumping())
            {
                koopa2.jump.forceJump(koopa1.jumpSpeed);
            }
            return(false);            // avoid the collision since this frame
        }
        // hide koopa 2
        else if (bouncing1 && !hidden2 && !bouncing2)
        {
            koopa2.hide();
        }
        // hide koopa 1
        else if (bouncing2 && !hidden1 && !bouncing1)
        {
            //koopa1.die();
            koopa1.hide();
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next fixed step.
        return(true);
    }
Ejemplo n.º 9
0
 bool ChipmunkBegin_KoopaTroopa_KoopaTroopa(ChipmunkArbiter arbiter)
 {
     if (!KoopaTroopa.beginCollisionWithKoopaTroopa(arbiter))
     {
         return(false);
     }
     return(Patrol.beginCollision(arbiter));
 }
Ejemplo n.º 10
0
 //##################### Player #################
 bool ChipmunkBegin_Player_Scenery(ChipmunkArbiter arbiter)
 {
     if (!Player.beginCollisionWithScenery(arbiter))
     {
         return(false);
     }
     return(Jump.beginCollisionWithScenery(arbiter));
 }
Ejemplo n.º 11
0
 //##################### KoopaTroopa #################
 bool ChipmunkBegin_KoopaTroopa_Scenery(ChipmunkArbiter arbiter)
 {
     Chase.beginCollisionWithScenery(arbiter);
     if (!Patrol.beginCollision(arbiter))
     {
         return(false);
     }
     return(Jump.beginCollisionWithScenery(arbiter));
 }
    private void MarkCollision(ChipmunkArbiter arbiter)
    {
        ChipmunkShape a, b;

        arbiter.GetShapes(out a, out b);
        a.GetComponent <Ball>().parent = b.GetComponent <Ball>();

        Debug.DrawLine(a.transform.position, b.transform.position, Color.white);
    }
Ejemplo n.º 13
0
 bool ChipmunkBegin_Player_Oneway(ChipmunkArbiter arbiter)
 {
     // if condition for oneway platform was not met then proceed as a begin collision with Scenery
     if (!Player.beginCollisionWithOneway(arbiter))
     {
         return(ChipmunkBegin_Player_Scenery(arbiter));
     }
     return(true);
 }
Ejemplo n.º 14
0
    public static void endCollisionWithScenery(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        shape1.GetComponent <Player>().exitedFromScenery = true;
    }
Ejemplo n.º 15
0
    public static void endCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        shape1.getOwnComponent <Goal>().flagTargetOutside(shape1._handle.ToInt32());
    }
    protected bool ChipmunkBegin_player_pit(ChipmunkArbiter arbiter)
    {
        ChipmunkShape player, pit;

        arbiter.GetShapes(out player, out pit);

        player.SendMessage("OnFellInPit");

        return(true);
    }
Ejemplo n.º 17
0
    protected bool ChipmunkPreSolve_ball_oneway(ChipmunkArbiter arbiter)
    {
        if (arbiter.GetNormal(0).y > -0.7f)
        {
            arbiter.Ignore();
            return(false);
        }

        return(true);
    }
Ejemplo n.º 18
0
    public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        KoopaTroopa koopa  = shape1.getOwnComponent <KoopaTroopa>();
        Player      player = shape2.getOwnComponent <Player>();

        if (player.isDying())
        {
            arbiter.Ignore();         // avoid the collision to continue since this frame
            return(false);            // avoid the collision to continue since this frame
        }

        bool collisionFromAbove = GameObjectTools.isHitFromAbove(koopa.transform.position.y, shape2.body, arbiter);

        if (collisionFromAbove)
        {
            // if koopa was jumping then stop forever jumping
            if (koopa.jump.isJumping())
            {
                koopa.stopJumping();
            }
            // hide the koopa troopa or stop the bouncing of the hidden koopa
            else if (!koopa._hide.isHidden() || koopa.bounce.isBouncing())
            {
                koopa.hide();
            }
            // kills the koopa
            else
            {
                koopa.die();
            }
            // makes the player jumps a little upwards
            player.forceJump();
        }
        // koopa starts bouncing
        else if (koopa._hide.isHidden() && !koopa.bounce.isBouncing())
        {
            koopa.stop();
            koopa.bounce.bounce(Mathf.Sign(koopa.transform.position.x - player.transform.position.x));
        }
        // kills Player
        else
        {
            koopa.stop();
            arbiter.Ignore();                     // avoid the collision to continue since this frame
            LevelManager.Instance.loseGame(true); // force die animation
        }

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next fixed step.
        return(true);
    }
    protected bool ChipmunkBegin_player_bumpable(ChipmunkArbiter arbiter)
    {
        if (arbiter.GetNormal(0).y > 0.9f)
        {
            ChipmunkShape player, bonusBlock;
            arbiter.GetShapes(out player, out bonusBlock);

            bonusBlock.SendMessage("Bump");
        }

        return(true);
    }
Ejemplo n.º 20
0
    public static bool isCeiling(ChipmunkArbiter arbiter)
    {
        /// The collision normal is the direction of the surfaces where the two objects collided.
        /// Keep in mind that the normal points out of the first object and into the second.
        /// If you switch the order of your collision types in the method name, it will flip the normal around.

        if (-arbiter.GetNormal(0).y < -COS_45)
        {
            return(true);
        }
        return(false);
    }
Ejemplo n.º 21
0
    public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        LevelManager.Instance.updateLastSpawnPosition(shape2.GetComponent <SpawnPositionTrigger>().sps);

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(false);
    }
Ejemplo n.º 22
0
    public static bool isGrounded(ChipmunkArbiter arbiter)
    {
        /// The collision normal is the direction of the surfaces where the two objects collided.
        /// Keep in mind that the normal points out of the first object and into the second.
        /// If you switch the order of your collision types in the method name, it will flip the normal around.

        // if normal.y is near to 1 it means it's a hit from above
        if (Mathf.Abs(arbiter.GetNormal(0).y) > COS_45)
        {
            return(true);
        }
        return(false);
    }
Ejemplo n.º 23
0
    public static void endCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        Chase chase = shape1.GetComponent <Chase>();

        chase.stopChasing();
        chase.target = null;
        chase.enableOperate();
    }
Ejemplo n.º 24
0
    public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        shape1.getOwnComponent <Goal>().flagTargetInside(shape1._handle.ToInt32());

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next fixed step.
        return(false);
    }
Ejemplo n.º 25
0
    public static bool beginCollisionWithUnlockSensor(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        Player player = shape1.GetComponent <Player>();

        player.restoreWalkVel();

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(false);
    }
Ejemplo n.º 26
0
    public static bool beginCollisionWithPowerUp(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        Ghost   ghost   = shape1.GetComponent <Ghost>();
        PowerUp powerUp = shape2.GetComponent <PowerUp>();

        powerUp.Invoke("destroy", 0f);         // a replacement for Destroy
        ghost.die();

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(false);
    }
Ejemplo n.º 27
0
    public static void endCollisionWithOneway(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        Player player = shape1.getOwnComponent <Player>();

        //player.jump.resetStatus(); // set state as if were jumping
        player.exitedFromScenery = true;

        // If was traversing the platform from below then the player is over the platform.
        // Correct inner state is treated by the invoked method
        player.GetComponent <ClimbDownFromPlatform>().handleSeparation();
    }
    protected bool ChipmunkBegin_player_jumpshroom(ChipmunkArbiter arbiter)
    {
        ChipmunkShape player, shroom;

        arbiter.GetShapes(out player, out shroom);

        if (arbiter.GetNormal(0).y < -0.9f)
        {
            ChipmunkBody body = player.GetComponent <ChipmunkBody>();
            body.velocity = new Vector2(body.velocity.x, 50f);
            return(false);
        }
        else
        {
            return(true);
        }
    }
Ejemplo n.º 29
0
    public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        arbiter.GetShapes(out shape1, out shape2);

        Ghost ghost = shape1.GetComponent <Ghost>();

        ghost.stop();

        // kills player
        arbiter.Ignore();                     // avoid the collision to continue since this frame
        LevelManager.Instance.loseGame(true); // force die animation

        // Returning false from a begin callback means to ignore the collision response for these two colliding shapes
        // until they separate. Also for current frame. Ignore() does the same but next frame.
        return(false);
    }
    protected bool ChipmunkPreSolve_player_oneway(ChipmunkArbiter arbiter)
    {
        // If we're pressing the down arrow key.
        if (Input.GetAxis("Vertical") < -0.5f)
        {
            // Fall through the floor
            arbiter.Ignore();
            return(false);
        }


        if (arbiter.GetNormal(0).y > -0.7f)
        {
            arbiter.Ignore();
            return(false);
        }

        return(true);
    }