Example #1
0
 public bool PowerUpCollides(clsPowerUp powerUp)
 {
     return(this.position.X + this.size.X >= powerUp.position.X &&
            this.position.X <= powerUp.position.X + powerUp.size.X &&
            this.position.Y + this.size.Y >= powerUp.position.Y &&
            this.position.Y <= powerUp.position.Y + powerUp.size.Y);
 }
Example #2
0
        /// <summary>
        /// Initializes Games based off of Game Type
        /// </summary>
        /// <param name="playerOneTexture">Player One Paddle</param>
        /// <param name="playerTwoTexture">Player Two Paddle</param>
        /// <param name="barrierTexture">Barrier Paddle</param>
        /// <param name="gameBallTexture">Gameball</param>
        /// <param name="ballSpeedUpTexure">PowerUp_BallSpeedInc</param>
        /// <param name="ballSpeedDownTexture">PowerUp_BallSpeedDec</param>
        /// <param name="barrierSpeedUpTexture">PowerUp_BarrierSpeedInc</param>
        /// <param name="barrierSpeedDownTexture">PowerUp_BarrierSpeedDec</param>
        /// <param name="graphics">Used for getting screen width and height</param>
        /// <param name="numOfUsers">Determines game type</param>
        public PongGame(Texture2D playerOneTexture, Texture2D playerTwoTexture, Texture2D barrierTexture,
                        Texture2D gameBallTexture, Texture2D ballSpeedUpTexture, Texture2D ballSpeedDownTexture,
                        Texture2D barrierSpeedUpTexture, Texture2D barrierSpeedDownTexture, GraphicsDeviceManager graphics, int numOfUsers)
        {
            // Sound Effects Initialization
            #region Sound Effects
            audioEngine = new AudioEngine("Content\\Lab4Sounds.xgs");
            ballHit     = new WaveBank(audioEngine, "Content\\Sounds.xwb");
            score       = new WaveBank(audioEngine, "Content\\Sounds.xwb");
            soundsBank  = new SoundBank(audioEngine, "Content\\SoundsBank.xsb");
            ballCue     = soundsBank.GetCue("BallHit");
            scoreCue    = soundsBank.GetCue("Score");

            #endregion
            gameActive   = true;
            winningScore = 5;
            #region Single Player
            if (numOfUsers == 1)
            {
                #region Paddles
                P1 = new clsPlayer(playerOneTexture, PlayerType.PlayerOne, new Vector2(graphics.PreferredBackBufferWidth - 51, (graphics.PreferredBackBufferHeight / 2) - 75), new Vector2(51, 235), new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
                P2 = new clsPlayer(playerTwoTexture, PlayerType.CPU, new Vector2(0, (graphics.PreferredBackBufferHeight / 2) - 75), new Vector2(51, 235), new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
                P1.paddle.velocity = new Vector2(0, 0);
                P2.paddle.velocity = new Vector2(0, -5);
                #endregion
                #region Barriers
                if (Game1.gameSettings.barriers == true)
                {
                    topBarrier          = new clsSprite(barrierTexture, new Vector2((graphics.PreferredBackBufferWidth / 2) - 25.5f, 0), new Vector2(51, 167), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                    topBarrier.velocity = new Vector2(0f, 5f);
                    botBarrier          = new clsSprite(barrierTexture, new Vector2((graphics.PreferredBackBufferWidth / 2) - 25.5f, graphics.PreferredBackBufferHeight - 167), new Vector2(51, 167), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                    botBarrier.velocity = new Vector2(0f, -5f);
                }
                #endregion
                #region Game Ball
                gameBall          = new clsSprite(gameBallTexture, new Vector2((graphics.PreferredBackBufferWidth / 2) - 18, (graphics.PreferredBackBufferHeight / 2) - 18), new Vector2(36, 36), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                gameBall.velocity = new Vector2(randPowerUp.Next(5, 7), randPowerUp.Next(-2, 3));
                if (gameBall.velocity.Y == 0)
                {
                    gameBall.velocity = new Vector2(gameBall.velocity.X, randPowerUp.Next(-3, -1));
                }
                #endregion
                #region PowerUps
                if (Game1.gameSettings.powerUps == true)
                {
                    ballSpeedUp      = new clsPowerUp(ballSpeedUpTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(36, 36), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BallSpeedUp);
                    ballSpeedDown    = new clsPowerUp(ballSpeedDownTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(36, 36), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BallSpeedDown);
                    barrierSpeedUp   = new clsPowerUp(barrierSpeedUpTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(87, 78), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BarrierSpeedUp);
                    barrierSpeedDown = new clsPowerUp(barrierSpeedDownTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(72, 63), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BarrierSpeedDown);
                    if (Game1.gameSettings.barriers)
                    {
                        barrierSpeedDown.active = true;
                        barrierSpeedUp.active   = true;
                    }
                    ballSpeedUp.active   = true;
                    ballSpeedDown.active = true;
                }
                #endregion
            }
            #endregion
            #region Two Player
            else
            {
                #region Paddles
                P1 = new clsPlayer(playerOneTexture, PlayerType.PlayerOne, new Vector2(graphics.PreferredBackBufferWidth - 51, (graphics.PreferredBackBufferHeight / 2) - 75), new Vector2(51, 235), new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
                P2 = new clsPlayer(playerTwoTexture, PlayerType.PlayerTwo, new Vector2(0, (graphics.PreferredBackBufferHeight / 2) - 75), new Vector2(51, 235), new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
                P1.paddle.velocity = new Vector2(0, 0);
                P2.paddle.velocity = new Vector2(0, 0);
                #endregion
                #region Barriers
                if (Game1.gameSettings.barriers == true)
                {
                    topBarrier          = new clsSprite(barrierTexture, new Vector2((graphics.PreferredBackBufferWidth / 2) - 25.5f, 0), new Vector2(51, 167), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                    topBarrier.velocity = new Vector2(0f, 5f);
                    botBarrier          = new clsSprite(barrierTexture, new Vector2((graphics.PreferredBackBufferWidth / 2) - 25.5f, graphics.PreferredBackBufferHeight - 167), new Vector2(51, 167), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                    botBarrier.velocity = new Vector2(0f, -5f);
                }
                #endregion
                #region Game Ball
                gameBall          = new clsSprite(gameBallTexture, new Vector2((graphics.PreferredBackBufferWidth / 2) - 18, (graphics.PreferredBackBufferHeight / 2) - 18), new Vector2(36, 36), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
                gameBall.velocity = new Vector2(randPowerUp.Next(5, 7), randPowerUp.Next(-2, 3));
                if (gameBall.velocity.Y == 0)
                {
                    gameBall.velocity = new Vector2(gameBall.velocity.X, randPowerUp.Next(-3, -1));
                }
                #endregion
                #region PowerUps
                if (Game1.gameSettings.powerUps == true)
                {
                    ballSpeedUp      = new clsPowerUp(ballSpeedUpTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(36, 36), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BallSpeedUp);
                    ballSpeedDown    = new clsPowerUp(ballSpeedDownTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(36, 36), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BallSpeedUp);
                    barrierSpeedUp   = new clsPowerUp(barrierSpeedUpTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(87, 78), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BallSpeedUp);
                    barrierSpeedDown = new clsPowerUp(barrierSpeedDownTexture, new Vector2(graphics.PreferredBackBufferWidth + 200, graphics.PreferredBackBufferHeight + 200), new Vector2(72, 63), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, clsPowerUp.PowerUpType.BallSpeedUp);

                    if (Game1.gameSettings.barriers)
                    {
                        barrierSpeedDown.active = true;
                        barrierSpeedDown.active = true;
                    }
                    ballSpeedUp.active   = true;
                    ballSpeedDown.active = true;
                }
                #endregion
            }
            #endregion
        }