private void ResetGame() { paddlePlayer = new PlayerPaddle(40, (int)(SceneManager.WindowHeight * 0.5)); paddlePlayer.Init(); paddleAI = new AIPaddle(SceneManager.WindowWidth - 40, (int)(SceneManager.WindowHeight * 0.5)); paddleAI.Init(); ball = new Ball((int)(SceneManager.WindowWidth * 0.5), (int)(SceneManager.WindowHeight * 0.5)); ball.Init(); }
private void ResetGame() { paddlePlayer = new PlayerPaddle(40, (int)(SceneManager.WindowHeight * 0.5), 0, 43, 255); paddlePlayer.Init(false); paddleAI = new AIPaddle(SceneManager.WindowWidth - 40, (int)(SceneManager.WindowHeight * 0.5), 255, 0, 0); paddleAI.Init(false); ball = new Ball((int)(SceneManager.WindowWidth * 0.5), (int)(SceneManager.WindowHeight * 0.5)); ball.Init(); speedPowerUp = new SpeedPowerUp(-180, -180, 255, 255, 0); speedPowerUp.Init(); lengthPowerUp = new LengthPowerUp(-180, -180, 0, 255, 0); lengthPowerUp.Init(); powerUpSpawned = false; player1SpeedEnabled = false; player2SpeedEnabled = false; player1LengthEnabled = false; player2LengthEnabled = false; }
private void CollisionDetection() { // AI if (player2LengthEnabled == false) { if ((paddleAI.Position.X - ball.Position.X) < ball.Radius && ball.Position.Y > (paddleAI.Position.Y - normalPaddle) && ball.Position.Y < (paddleAI.Position.Y + normalPaddle)) { ball.Position = new Vector2(paddleAI.Position.X - ball.Radius, ball.Position.Y); ball.Velocity = new Vector2(ball.Velocity.X * -1.0f, ball.Velocity.Y) * 2.0f; Player1lastHit = false; } } else { if ((paddleAI.Position.X - ball.Position.X) < ball.Radius && ball.Position.Y > (paddleAI.Position.Y - superPaddle) && ball.Position.Y < (paddleAI.Position.Y + superPaddle)) { ball.Position = new Vector2(paddleAI.Position.X - ball.Radius, ball.Position.Y); ball.Velocity = new Vector2(ball.Velocity.X * -1.0f, ball.Velocity.Y) * 2.0f; Player1lastHit = false; } } // Speed Powerup if ((speedPowerUp.Position.X - ball.Position.X) < (ball.Radius + 55.0f) && (ball.Radius - 55.0f) < (speedPowerUp.Position.X - ball.Position.X) && ball.Position.Y > (speedPowerUp.Position.Y - 55.0f) && ball.Position.Y < (speedPowerUp.Position.Y + 55.0f)) { speedPowerUp.Position = new Vector2(-180, -180); powerUpSpawned = false; if (Player1lastHit == true) { player1SpeedEnabled = true; } else { player2SpeedEnabled = true; } } // Length PowerUp if ((lengthPowerUp.Position.X - ball.Position.X) < (ball.Radius + 55.0f) && (ball.Radius - 55.0f) < (lengthPowerUp.Position.X - ball.Position.X) && ball.Position.Y > (lengthPowerUp.Position.Y - 55.0f) && ball.Position.Y < (lengthPowerUp.Position.Y + 55.0f)) { lengthPowerUp.Position = new Vector2(-180, -180); powerUpSpawned = false; if (Player1lastHit == true) { player1LengthEnabled = true; paddlePlayer.Init(true); } else { player2LengthEnabled = true; paddleAI.Init(true); } } // Player if (player1LengthEnabled == false) { if ((ball.Position.X - paddlePlayer.Position.X) < ball.Radius && ball.Position.Y > (paddlePlayer.Position.Y - normalPaddle) && ball.Position.Y < (paddlePlayer.Position.Y + normalPaddle)) { ball.Position = new Vector2(paddlePlayer.Position.X + ball.Radius, ball.Position.Y); ball.Velocity = new Vector2(ball.Velocity.X * -1.0f, ball.Velocity.Y) * 2.0f; Player1lastHit = true; } } else { if ((ball.Position.X - paddlePlayer.Position.X) < ball.Radius && ball.Position.Y > (paddlePlayer.Position.Y - superPaddle) && ball.Position.Y < (paddlePlayer.Position.Y + superPaddle)) { ball.Position = new Vector2(paddlePlayer.Position.X + ball.Radius, ball.Position.Y); ball.Velocity = new Vector2(ball.Velocity.X * -1.0f, ball.Velocity.Y) * 2.0f; Player1lastHit = true; } } }