示例#1
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            if (_attachedToPaddle != null)
                {
                    Location.X = _attachedToPaddle.Location.X + _attachedToPaddle.Width + 1f;
                    Location.Y = _attachedToPaddle.Location.Y + ((_attachedToPaddle.Height/2) - (Height/2));
                    hitCount = 0;
                    if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        launchBall();
                    }
                }
                else if (boundingBox.Intersects(gameObjects.PlayerPaddle.boundingBox))
                    {

                        Velocity = new Vector2(-Velocity.X, ((gameObjects.PlayerPaddle.Velocity.Y *.75f) + Velocity.Y * .5f));
                    }

                else if( boundingBox.Intersects(gameObjects.ComputerPaddle.boundingBox))
                       {

                           Velocity = new Vector2(-Velocity.X - hitCount, ((gameObjects.ComputerPaddle.Velocity.Y * .75f) + Velocity.Y * .5f));
                           hitCount = hitCount + 0.1f;
                    }
                base.Update(gameTime, gameObjects);
        }
示例#2
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            //if (gameObjects.Score.gameOver == false)
           // {
                if (playerType == PlayerTypes.Computer)
                {
                    //AI ...no robin williams
                    var random = new Random();
                    var reactionThreshold = random.Next(0, 25);


                    if ((gameObjects.Ball.Location.Y + gameObjects.Ball.Height / 2) == (Location.Y + Height / 2))
                    {
                        Velocity = Vector2.Zero;
                    }
                    else if (gameObjects.Ball.Location.Y + gameObjects.Ball.Height < Location.Y + reactionThreshold)
                    {
                        Velocity = new Vector2(0, -3f);
                    }
                    else if (gameObjects.Ball.Location.Y > Location.Y + Height + reactionThreshold)
                    {
                        Velocity = new Vector2(0, 3f);
                    }
                }
                if (playerType == PlayerTypes.Human)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Left))
                    {
                        var newVelocity = new Vector2(0, -3f);
                        Velocity = newVelocity;
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Right))
                    {
                        var newVelocity = new Vector2(0, 3f);
                        Velocity = newVelocity;
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Up) || Keyboard.GetState().IsKeyDown(Keys.Down))
                    {
                        var newVelocity = Vector2.Zero;
                        Velocity = newVelocity;
                    }
                    else if ((Location.Y == 0 || Location.Y == (gameBoundaries.Height - _texture.Height)))
                    {
                        if (Velocity != Vector2.Zero)
                        {
                            var newVelocity = Vector2.Zero;
                            Velocity = newVelocity;
                        }
                    }
                    //Zero Velocity if clipping screen 
                }
           // }
            base.Update(gameTime, gameObjects);
        }
示例#3
0
 public void Update(GameTime gameTime, GameObjects gameObjects)
 {
     if (gameObjects.Ball.Location.X + gameObjects.Ball.Width < 0)
     {
         ComputerScore++;
         gameObjects.Ball.AttachTo(gameObjects.PlayerPaddle);
     }
     else if (gameObjects.Ball.Location.X > gameBoundaries.Width)
     {
         PlayerScore++;
         gameObjects.Ball.AttachTo(gameObjects.PlayerPaddle);
     }
 }
示例#4
0
        protected override void LoadContent() //Load all Game Contenet
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height); 

            //Paddle creation
            var paddleTexture = Content.Load<Texture2D>("paddle");
            var personPaddleLocation = new Vector2(10f, gameBoundaries.Height / 2);
            var computerPaddleLocation = new Vector2(gameBoundaries.Width - paddleTexture.Width - 10, gameBoundaries.Height/2);
            playerPaddle = new Paddle(paddleTexture, personPaddleLocation, gameBoundaries, PlayerTypes.Human );
            computerPaddle = new Paddle(paddleTexture, computerPaddleLocation, gameBoundaries, PlayerTypes.Computer);
            //Ball creation
            _ball = new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameBoundaries);
            _ball.AttachTo(playerPaddle);

           // Score Creation
           SpriteFont sF = Content.Load<SpriteFont>("font"); 
           _score = new Score(sF, gameBoundaries );

           //Aggregate reference to all game objects
            gameObjects = new GameObjects { PlayerPaddle = playerPaddle, ComputerPaddle = computerPaddle, Ball = _ball ,Score = _score}; 
            
        }
示例#5
0
 public override void Update(GameTime gameTime, GameObjects gameObjects)
 {
     base.Update(gameTime, gameObjects);
 }
示例#6
0
 public virtual void Update(GameTime gameTime, GameObjects gameObjects)
 {
     Location += Velocity;
     CheckBounds();
 }
示例#7
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            if (playerType == PlayerTypes.Computer)
                {
                    //AI ...no robin williams
                    var random = new Random();
                    var reactionThreshold = random.Next(10, 50);//edit for computer difficulty

                    if ((gameObjects.Ball.Location.Y + gameObjects.Ball.Height / 2) == (Location.Y + Height / 2))
                    {
                        Velocity = Vector2.Zero;
                    }
                    else if (gameObjects.Ball.Location.Y + gameObjects.Ball.Height < Location.Y + reactionThreshold)
                    {
                        Velocity = new Vector2(0, -3f);
                    }
                    else if (gameObjects.Ball.Location.Y > Location.Y + Height + reactionThreshold)
                    {
                        Velocity = new Vector2(0, 3f);
                    }
                }
                if (playerType == PlayerTypes.Human)
                {
                    if ((Location.Y == 0 || Location.Y == (gameBoundaries.Height - _texture.Height)))
                    {
                        if (Velocity != Vector2.Zero)
                        {
                            var newVelocity = Vector2.Zero;
                            Velocity = newVelocity;
                            mouseMove = false;
                        }
                    }
                    var touchPoint = TouchPanel.GetState().FirstOrDefault();
                    if (touchPoint.State != TouchLocationState.Invalid)
                    {
                        mouseMove = true;
                        touchPosition = new Vector2(0f, touchPoint.Position.Y);
                    }
                    else if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                    {   // Add touch
                        //Mouse overrides keyboard input
                        //Mouse and Touch shoudl be handled as same event sort of so they don't compete
                        mouseMove = true;
                        touchPosition = new Vector2(0f, Mouse.GetState().Y);
                    }
                    if (mouseMove)
                    {
                        if ((touchPosition.Y < (Location.Y + Height / 2) + 10f) && (touchPosition.Y > (Location.Y + Height / 2) - 10f))
                        {
                            mouseMove = false;
                            Velocity = Vector2.Zero;

                        }
                        else if (touchPosition.Y > Location.Y + Height / 2)
                        {
                            var newVelocity = new Vector2(0, 3f);
                            Velocity = newVelocity;
                        }
                        else if (touchPosition.Y < Location.Y + Height / 2)
                        {
                            var newVelocity = new Vector2(0, -3f);
                            Velocity = newVelocity;
                        }
                    }

                    else if (Keyboard.GetState().IsKeyDown(Keys.Left))
                    {
                        var newVelocity = new Vector2(0, -3f);
                        Velocity = newVelocity;
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Right))
                    {
                        var newVelocity = new Vector2(0, 3f);
                        Velocity = newVelocity;
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Up) || Keyboard.GetState().IsKeyDown(Keys.Down))
                    {
                        var newVelocity = Vector2.Zero;
                        Velocity = newVelocity;
                    }
                }
                base.Update(gameTime, gameObjects);
        }