Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 bool ChipmunkBegin_KoopaTroopa_KoopaTroopa(ChipmunkArbiter arbiter)
 {
     if (!KoopaTroopa.beginCollisionWithKoopaTroopa(arbiter))
     {
         return(false);
     }
     return(Patrol.beginCollision(arbiter));
 }
Ejemplo n.º 5
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);
    }
Ejemplo n.º 6
0
 bool ChipmunkBegin_KoopaTroopa_Player(ChipmunkArbiter arbiter)
 {
     return(KoopaTroopa.beginCollisionWithPlayer(arbiter));
 }
Ejemplo n.º 7
0
 bool ChipmunkBegin_KoopaTroopa_PowerUp(ChipmunkArbiter arbiter)
 {
     return(KoopaTroopa.beginCollisionWithPowerUp(arbiter));
 }
Ejemplo n.º 8
0
    private void specialPlacementLogic(GameObject g, GameObject sg = null, GameObject oldG = null)
    {
        if (sg != null)
        {
            // Special behaviour for Resize component
            Resize r = sg.GetComponent <Resize>();
            if (r != null)
            {
                r.nonStatic = g;
            }
        }

        // Special behaviour for CollideTrigger component
        CollideTrigger ct = g.GetComponent <CollideTrigger>();

        if (ct != null)
        {
            ct.initialize();
        }

        if (oldG != null)
        {
            Transfigure oldT = oldG.GetComponent <Transfigure>();
            if (oldT != null)
            {
                Transfigure t = g.GetComponent <Transfigure>();
                t.targetAndTags.Clear();
                foreach (TargetAnimControllerAndTags tar in oldT.targetAndTags)
                {
                    TargetAnimControllerAndTags newTar = new TargetAnimControllerAndTags();
                    newTar.targetAnimController = tar.targetAnimController;
                    newTar.includedTags         = new List <string>(tar.includedTags);
                    newTar.excludedTags         = new List <string>(tar.excludedTags);
                    newTar.repeatable           = tar.repeatable;
                    newTar.id   = tar.id;
                    newTar.done = false;
                    t.targetAndTags.Add(newTar);
                }
            }
        }

        TimeTrigger tt = g.GetComponent <TimeTrigger>();

        if (tt != null)
        {
            tt.initialize();
        }

        MoveHorizontalUntilCollision mh = g.GetComponent <MoveHorizontalUntilCollision>();

        if (mh != null)
        {
            mh.run();
        }

        KoopaTroopa kt = g.GetComponent <KoopaTroopa>();

        if (kt != null)
        {
            addResetListener(kt);
        }

        FirePower fp = g.GetComponent <FirePower>();

        if (fp != null)
        {
            addResetListener(fp);
        }

        Invisible i = g.GetComponent <Invisible>();

        if (i != null)
        {
            addResetListener(i);
        }
    }