Example #1
0
    // sends player off a planet and blows it up
    public void LeavePlanet(float chargeTime)
    {
        // make sure there is a currentplanet and the player can jump off it
        if (isLanded && currentPlanet != null && canJump)
        {
            isLanded         = false;
            transform.parent = null;
            canJump          = false;
            playerAudio.PlayLeavingSound();

            Vector2 leavingAngle = new Vector2(transform.position.x - currentPlanet.transform.position.x,
                                               transform.position.y - currentPlanet.transform.position.y).normalized;
            // TODO: check if applyForce is better
            float leavingSpeed = maxChargeSpeed / 2f;
            if (chargeTime >= maxChargeTime)
            {
                leavingSpeed = maxChargeSpeed;
            }
            if (activatedPowerup == PowerupScript.PowerupType.lighting)
            {
                leavingSpeed *= powerupSpeed;
            }
            GetComponent <Rigidbody2D>().velocity       = leavingAngle * leavingSpeed;
            GetComponent <Rigidbody2D>().freezeRotation = false;

            // consume powerLevel
            //powerLevel -= powerLevelUsedOnJump;

            // kills the other player if they're on this planet and it will explode
            if (otherPlayer.isDead == false && otherPlayer.currentPlanet != null &&
                otherPlayer.currentPlanet.gameObject == this.currentPlanet.gameObject &&
                currentPlanet.WillExplodeNext())
            {
                otherPlayer.Suicide();
            }

            // if the planet will explode, get points
            if (currentPlanet.WillExplodeNext())
            {
                AcquirePoints(currentPlanet.GetPointValue(), this.transform.position);
            }


            nearbyPlanets.Remove(currentPlanet.gameObject);
            currentPlanet.SelfDestruct();
            currentPlanet = null;
        }
    }