Example #1
0
        public void Update(FrameEventArgs e)
        {
            // Set the title of the window

            sceneManager.Title = "Pong - Player Score: " + scorePlayer + " - AI Score: " + scoreAI;


            paddleAI.Move(ball.Position);

            ball.Update((float)e.Time);
            paddleAI.Update((float)e.Time);

            CollisionDetection();

            if (GoalDetection())
            {
                ResetGame();
            }
            if (scoreAI == 2)
            {
                NewGame();
            }
        }
        public void Update(FrameEventArgs e)
        {
            if (GamerOver == false)
            {
                Console.WriteLine("X: {0} Y: {1}", ball.Velocity.X, ball.Velocity.Y);
                Timer -= 1;

                if (Timer <= 0)
                {
                    Timer = 60;
                    clock--;
                    if (powerUpSpawned == false)
                    {
                        rInt  = r.Next(0, 5); //for ints
                        lInt  = r.Next(3, 9); //for ints
                        lintF = (float)lInt / 10;
                        if (rInt == 3)
                        {
                            powerUpSpawned        = true;
                            speedPowerUp.Position = new Vector2((int)(SceneManager.WindowWidth * lintF), (int)(SceneManager.WindowHeight * lintF));
                        }
                        else if (rInt == 2)
                        {
                            powerUpSpawned         = true;
                            lengthPowerUp.Position = new Vector2((int)(SceneManager.WindowWidth * lintF), (int)(SceneManager.WindowHeight * lintF));
                        }
                    }
                }
                if (clock <= 0)
                {
                    GamerOver = true;
                    clock     = 3;
                    Timer     = 60;
                }
                //Console.WriteLine("Timer:" + clock);

                // Set the title of the window
                sceneManager.Title = "Pong - Player Score: " + scorePlayer + " - AI Score: " + scoreAI;
                KeyboardState KeyStates = Keyboard.GetState();
                if (KeyStates.IsKeyDown(Key.Down))
                {
                    if (DebugMode == true)
                    {
                        ball.Position = new Vector2(ball.Position.X, ball.Position.Y - 5);
                    }
                    else
                    {
                        if (player1SpeedEnabled == true)
                        {
                            paddlePlayer.Move(-15);
                        }
                        else
                        {
                            paddlePlayer.Move(-8);
                        }
                    }
                }
                else if (KeyStates.IsKeyDown(Key.Up))
                {
                    if (DebugMode == true)
                    {
                        ball.Position = new Vector2(ball.Position.X, ball.Position.Y + 5);
                    }
                    else
                    {
                        if (player1SpeedEnabled == true)
                        {
                            paddlePlayer.Move(15);
                        }
                        else
                        {
                            paddlePlayer.Move(8);
                        }
                    }
                }
                if (DebugMode == true)
                {
                    if (KeyStates.IsKeyDown(Key.Left))
                    {
                        ball.Position = new Vector2(ball.Position.X - 5, ball.Position.Y);
                    }
                    else if (KeyStates.IsKeyDown(Key.Right))
                    {
                        ball.Position = new Vector2(ball.Position.X + 5, ball.Position.Y);
                    }
                }
                else
                {
                    paddlePlayer.Move(0);
                }
                paddleAI.Move(ball.Position, player2SpeedEnabled);

                if (DebugMode == false)
                {
                    ball.Update((float)e.Time);
                }
                paddleAI.Update((float)e.Time);

                CollisionDetection();
                if (GoalDetection())
                {
                    ResetGame();
                }
            }
            else
            {
                Timer -= 1;

                if (Timer <= 0)
                {
                    Timer = 60;
                    clock--;
                }
                if (clock <= 0)
                {
                    sceneManager.OpenSingleLeaderboard(true, scorePlayer);
                }
            }
        }