public void activatePowerUp(string type) { // play a sound effect AudioEffects.play("powerup"); // Only add a certain powerup once if (isPowerUpOn(type)) { return; } if (type == "KillIrishCoffee") { removePowerUp("IrishCoffee"); } else { powerUps.Add(type); } }
/** * @params * - deltaX = 0..1 * - deltaY = 0..1 * * Required that deltaX^2 + deltaY^2 <= 1 */ public void move(float deltaX, float deltaY) { { // Some magic code... float tempX = Mathf.Sqrt(Mathf.Abs(deltaX)); float tempY = Mathf.Sqrt(Mathf.Abs(deltaY)); if (deltaX < 0) { deltaX = tempX * (-1); } else { deltaX = tempX; } if (deltaY < 0) { deltaY = tempY * (-1); } else { deltaY = tempY; } } if (powerUpStateHandler.isPowerUpOn("IrishCoffee")) { // Don't allow player controls because the player might end up in wrong places return; } deltaMove = new Vector3(0, 0, 0); if (isOnGround() || doubleJumpActive()) { // Player is on the ground. Normal controls deltaMove.x = deltaX * multiplierX * maxSpeedX; deltaMove.y = deltaY * multiplierY * maxSpeedY; // If the player wants to jump to complete new direction, // then make it easier /*if ( Mathf.Abs(deltaY) > 0.001 && wantsToChangeDirection() ) { * player.velocity = new Vector3(0, player.velocity.y, 0); * }*/ if (deltaMove.y > 0) { AudioEffects.play("jump"); } else { AudioEffects.play("move"); } } else if (isTryingToReduceSpeed(deltaX)) { deltaMove.x = deltaX * airMovementFactor * multiplierX * maxSpeedX; } checkMovementBoundaries(); // To normalize with time player.AddForce(deltaMove); }