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); }
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); }
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); }
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); }