public bool HandleGetCoin(Coin.CoinColor color) { if (feeling == BoxyFeeling.TooCool || feeling == BoxyFeeling.Dead) { return(false); //don't get no mo coins } if (firstColor == Coin.CoinColor.None) { firstColor = color; coinsNeeded = getCoinsInLevel(color); } if (firstColor == color) { numCoins++; if (numCoins == coinsNeeded) { PlayClip(lastCoinSfx); feeling = BoxyFeeling.TooCool; Invoke("LoadNextLevel", tooCoolLength); } else { PlayClip(coinSfx); } } else { Die(CauseOfDeath.HadTwo); } return(true); }
public void Die(CauseOfDeath cause = CauseOfDeath.Fell) { if (feeling == BoxyFeeling.Dead) { return; } feeling = BoxyFeeling.Dead; PlayerPrefs.SetInt("CauseOfDeath", (int)cause); RagDollMe(); restartedSinceLastDeath = false; if (PlayerPrefs.GetInt("HasDiedByHavingTwo") == 1) { Invoke("RestartLevel", 1f); } else if (cause == CauseOfDeath.HadTwo) { // allow text animation to play before resetting Invoke("SetDiedFlag", maxTextAnimTime); } else // cause == CauseOfDeath.Fell { Invoke("RestartLevel", 1f); // simple restart, like the first condition } PlayClip(deathSfx); }
void Update() { if (feeling == BoxyFeeling.Dead && PlayerPrefs.GetInt("HasDiedByHavingTwo") == 0) { textAnimTimeAcc += Time.deltaTime; } // The player is grounded if a linecast to the groundcheck position hits anything on the ground layer. grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")); jumpedOffSlope = grounded ? false : jumpedOffSlope; // clear jumpedOffSlope everytime we get grounded //Player is stuck on his side if (State == PlayerState.StuckOnSide) { //Check to see if a miracle happened and the player got up. if (!IsRotated(transform.rotation.eulerAngles.z) && grounded) { PreviousState = State; State = PlayerState.Walking; feeling = BoxyFeeling.Normal; } } else if (IsRotated(transform.rotation.eulerAngles.z) && rigidbody2D.velocity.y == 0) { PreviousState = State; State = PlayerState.StuckOnSide; if (feeling != BoxyFeeling.Dead) //LOL WHAT IS THIS MADNESS. IS THIS REALITY. { feeling = BoxyFeeling.Horrified; } rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y); } // restart level if dead if (Input.GetButtonDown("Jump") && feeling == BoxyFeeling.Dead) { RestartLevel(); } SpriteRenderer renderer = GetComponent <SpriteRenderer> (); // update sprite to reflect state switch (feeling) { case BoxyFeeling.Dead: renderer.sprite = deadSprite; break; case BoxyFeeling.Normal: renderer.sprite = normalSprite; break; case BoxyFeeling.TooCool: renderer.sprite = coolSprite; break; case BoxyFeeling.Horrified: renderer.sprite = horrifiedSprite; break; default: renderer.sprite = normalSprite; break; } if (Input.GetButtonDown("Jump")) { if (State == PlayerState.StuckOnSide) { rigidbody2D.AddTorque(GetAmountToFlip(transform.rotation.eulerAngles.z)); PreviousState = State; State = PlayerState.Walking; feeling = BoxyFeeling.Normal; } else if (grounded) { PreviousState = State; State = PlayerState.Jumping; float rotation = transform.rotation.eulerAngles.z; if (rotation > 15 && rotation < 345) // if on slope, set flag so we can use it while moving in midair { jumpedOffSlope = true; } } } }