Esempio n. 1
0
 // Gives the ability to run if the player has enough money and doesn't already own this power up.
 public static void BuyRun()
 {
     if (Score.score >= PowerUps.runPrice)
     {
         Score.score -= PowerUps.runPrice;
         PowerUps.ActivatePowerUp("run");
         runPriceText.text = " Buy run \t\t\t" + PowerUps.runPrice;
         outputText.text   = "You can now run! Hold shift while playing to go faster.";
     }
     else
     {
         outputText.text = "You can't afford that!";
     }
 }
Esempio n. 2
0
 // Gives the player and extra life if you can afford it and removes the price from the player's score
 public static void BuyLife()
 {
     if (Score.score >= PowerUps.healthPrice)
     {
         Score.score -= PowerUps.healthPrice;
         PowerUps.ActivatePowerUp("bonusHealth");
         lifePriceText.text = " Buy extra life \t\t" + PowerUps.healthPrice;
         outputText.text    = "You received an extra life! You can now take more damage without restarting.";
     }
     else
     {
         outputText.text = "You can't afford that!";
     }
 }
Esempio n. 3
0
 // Gives the ability to double jump if the player has enough money and doesn't already own this power up.
 public static void BuyJump()
 {
     if (Score.score >= PowerUps.jumpPrice)
     {
         Score.score -= PowerUps.jumpPrice;
         PowerUps.ActivatePowerUp("doubleJump");
         jumpPriceText.text = " Buy double jump \t" + PowerUps.jumpPrice;
         outputText.text    = "You can now jump " + PowerUps.doubleJump + " times without touching the ground!";
     }
     else
     {
         outputText.text = "You can't afford that!";
     }
 }
Esempio n. 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "F*g")
        {
            if (PlayerPrefs.GetString("audio") != "off")
            {
                AudioSource.PlayClipAtPoint(audioClip, Camera.main.transform.position);
            }
            powerUps.ActivatePowerUp(powerUpType);
            Destroy(gameObject);
        }

        if (collision.tag == "BottomWall")
        {
            Destroy(gameObject);
        }
    }
Esempio n. 5
0
        // Constantly running
        void Update()
        {
            // Check any x-axis movement. If not detected, let player speed slow down.
            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow))
            {
                if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
                {
                    if (playerSpeed > -maxSpeed)
                    {
                        playerRigidBody.velocity = new Vector2(playerSpeed, jumpHeight);
                        playerSpeed -= 0.4f;
                    }
                    else
                    {
                        playerRigidBody.velocity = new Vector2(playerSpeed, jumpHeight);
                    }
                }
                else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
                {
                    if (playerSpeed < maxSpeed)
                    {
                        playerRigidBody.velocity = new Vector2(playerSpeed, jumpHeight);
                        playerSpeed += 0.4f;
                    }
                    else
                    {
                        playerRigidBody.velocity = new Vector2(playerSpeed, jumpHeight);
                    }
                }
            }

            // Slows the player down by constantly decreasing the current speed.
            else
            {
                playerSpeed -= playerSpeed / 32;
                playerRigidBody.velocity = new Vector2(playerSpeed, jumpHeight);
            }

            // The jump script.
            if (Input.GetKeyDown(KeyCode.Space) && (collisionCheck == true || doubleJump > 0) && disableJump == false)
            {
                if (collisionCheck == true)
                {
                    jumpHeight = 8;
                    jumpSound.Play();
                }
                else if (doubleJump > 0)
                {
                    doubleJump--;
                    jumpHeight = 8;
                    jumpSound.Play();
                }
            }


            // "Gravity" makes the player fall until a collision is detected.
            if (jumpHeight > -14 && collisionCheck == false)
            {
                if (jumpHeight > -14)
                {
                    jumpHeight -= 0.4f;
                }
            }
            // Prevents autojumping by resetting the jumpheight after space is not pressed anymore.
            else if (collisionCheck == true && !(Input.GetKey(KeyCode.Space)))
            {
                jumpHeight = 0;
                doubleJump = PowerUps.doubleJump;
            }

            // Run
            if (Input.GetKey(KeyCode.LeftShift) && run > 0)
            {
                maxSpeed = 7 + PowerUps.run * 2;
            }
            else
            {
                maxSpeed = 7;
            }

            // Manual restart
            if (Input.GetKeyDown(KeyCode.R))
            {
                ChangeScene.Restart();
            }

            // Cheats
            if (Input.GetKeyDown(KeyCode.Tab) && Input.GetKey(KeyCode.P))
            {
                Debug.Log("Cheats activated! and bonushealt = " + PowerUps.bonusHealth);
                PowerUps.ActivatePowerUp("run");
                PowerUps.ActivatePowerUp("doubleJump");
                PowerUps.ActivatePowerUp("bonusHealth");
            }

            // Restart level when player falls off map.
            if (transform.position.y < -6)
            {
                ChangeScene.Restart();
            }
        }