void giveNewPower(PaddleBase player) { float randFloat = Random.Range(1, (float)(powerTypes.POWER_COUNT)); int randInt = Mathf.FloorToInt(randFloat); string powerName = powerMapping[(powerTypes)randInt]; player.AddPower(powerName); Debug.Log("Power Granted: " + powerMapping[(powerTypes)randInt].ToString() + " to player " + ownerId); if (NetworkManager.singleton.isNetworkActive) { PaddleNetworking pNet = player.gameObject.GetComponent <PaddleNetworking>(); pNet.RpcSetCurrentPower(powerName); } }
public void OnColliderCollision(IBoxCollider otherCollider, Vector2 intersection) { PaddleBase paddle = otherCollider as PaddleBase; if (paddle == null) { return; // Only check collisions with paddles } if (paddle.PaddleSide == PaddleSide.Left && (Angle.IsBetween(270, 360, true) || Angle.IsBetween(0, 90, true))) { return; // Ignore a left paddle collision if the ball is already facing right } if (paddle.PaddleSide == PaddleSide.Right && (Angle.IsBetween(90, 270, true))) { return; // Ignore a right paddle collision if the ball is already facing left } /* * When the ball hit a player paddle we need to bounce it back based on the location of the paddle. * The further the Y center of the ball is to the Y center of the paddle, the larger the angle will be. * * For example: * If the ball's Y center is above the paddle's, it will bounce towards the top of the screen. * If it's below, it will bounce towards the bottom of the screen. */ float degreesPerPixel = SettingsConstants.BallAngleRange / otherCollider.Hitbox.Height; // Left paddle collision if (paddle.PaddleSide == PaddleSide.Left) { // Adjust the angle const float startAngle = SettingsConstants.BallRightDirectionAngleStart + (SettingsConstants.BallAngleRange / 2F); Angle = startAngle + (Hitbox.Center.Y - otherCollider.Hitbox.Center.Y) * degreesPerPixel; } // Right paddle collision else { // Adjust the angle const float startAngle = SettingsConstants.BallLeftDirectionAngleStart + (SettingsConstants.BallAngleRange / 2F); Angle = startAngle + (otherCollider.Hitbox.Center.Y - Hitbox.Center.Y) * degreesPerPixel; } _audioManager.PlaySfx("BallPaddleHit"); }
// Clear old actors and create new ones based on the settings private void CreateActors() { _actorRegistry.Clear(); PaddleBase leftPaddle = _paddleFactory.CreatePaddle(_settingsManager.Settings.Gameplay.LeftPaddleType, PaddleSide.Left); PaddleBase rightPaddle = _paddleFactory.CreatePaddle(_settingsManager.Settings.Gameplay.RightPaddleType, PaddleSide.Right); _actorRegistry.AddRange(leftPaddle, rightPaddle); IActor[] balls = new IActor[_settingsManager.Settings.Gameplay.BallCount]; for (int i = 0; i < balls.Length; i++) { balls[i] = _ballFactory.CreateBall(); } _actorRegistry.AddRange(balls); }