示例#1
0
        public override void Update(GameTime gameTime, GamesObjects gameObjects)
        {
            if (_playertype == PlayerTypes.Human)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                    Velocity = new Vector2(0, -paddleSpeed);
                // Move paddle up

                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                    Velocity = new Vector2(0, paddleSpeed);
                // Move paddle down
            }

            if (_playertype == PlayerTypes.Computer)
            {
                //Stuff
                var random = new Random();
                var reactionThreshold = random.Next(30, 130);


                if (gameObjects.Ball.Location.Y + gameObjects.Ball.Height < Location.Y + reactionThreshold)
                {
                    Velocity = new Vector2(0, -paddleSpeed);
                }
                if (gameObjects.Ball.Location.Y > Location.Y + Height + reactionThreshold)
                {
                    Velocity = new Vector2(0, paddleSpeed);
                }
            }


                base.Update(gameTime, gameObjects);
        }
示例#2
0
 public void Update(GameTime gameTime, GamesObjects gameobjects)
 {
     if (gameobjects.Ball.Location.X + gameobjects.Ball.Width < 0)
     {
         ComputerScore++;
         gameobjects.Ball.AttachTo(gameobjects.PlayerPaddle);
     }
     if (gameobjects.Ball.Location.X > gameBoundaries.Width)
     {
         PlayerScore++;
         gameobjects.Ball.AttachTo(gameobjects.PlayerPaddle);
     }
 }
示例#3
0
 public void Update(GameTime gameTime, GamesObjects gameobjects)
 {
     if (gameobjects.Ball.Location.X + gameobjects.Ball.Width < 0)
     {
         ComputerScore++;
         gameobjects.Ball.AttachTo(gameobjects.PlayerPaddle);
     }
     if (gameobjects.Ball.Location.X > gameBoundaries.Width)
     {
         PlayerScore++;
         gameobjects.Ball.AttachTo(gameobjects.PlayerPaddle);
     }
 }
示例#4
0
        public override void Update(GameTime gameTime, GamesObjects gameObjects)
        {
            ballspeed = 2.0f;
            bool collision;

            collision = false;
            if
            (
                Keyboard.GetState().IsKeyDown(Keys.Space) && _attachedToPaddle != null
            )
            {
                while (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox))
                {
                    Location = new Vector2(Location.X + 1, Location.Y);
                }

                while (BoundingBox.Intersects(gameObjects.Computeraddle.BoundingBox))
                {
                    Location = new Vector2(Location.X - 1, Location.Y);
                }


                var newVelocity = new Vector2(ballspeed, _attachedToPaddle.Velocity.Y * 0.9f);
                Velocity          = newVelocity;
                _attachedToPaddle = null;
            }
            if (_attachedToPaddle != null)
            {
                Location.X = _attachedToPaddle.Location.X + _attachedToPaddle.Width;
                Location.Y = _attachedToPaddle.Location.Y;
                collision  = false;
            }
            else
            {
                if (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox) || BoundingBox.Intersects(gameObjects.Computeraddle.BoundingBox))
                {
                    Velocity  = new Vector2(-Velocity.X, Velocity.Y);
                    collision = true;
                }
            }

            base.Update(gameTime, gameObjects);
        }
示例#5
0
        public override void Update(GameTime gameTime, GamesObjects gameObjects)
        {
            ballspeed = 2.0f;
            bool collision;
            collision = false;
            if
                (
                Keyboard.GetState().IsKeyDown(Keys.Space) && _attachedToPaddle != null
                )
            {
                while (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox))
                {
                    Location = new Vector2(Location.X + 1, Location.Y);
                }

                while (BoundingBox.Intersects(gameObjects.Computeraddle.BoundingBox))
                {
                    Location = new Vector2(Location.X - 1, Location.Y);
                }

                var newVelocity = new Vector2(ballspeed,_attachedToPaddle.Velocity.Y * 0.9f);
                Velocity = newVelocity;
                _attachedToPaddle = null;

            }
            if (_attachedToPaddle != null)
            {
                Location.X = _attachedToPaddle.Location.X + _attachedToPaddle.Width;
                Location.Y = _attachedToPaddle.Location.Y;
                collision = false;
            }
            else
            {
                if(BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox) || BoundingBox.Intersects(gameObjects.Computeraddle.BoundingBox))
                {
                    Velocity = new Vector2(-Velocity.X, Velocity.Y);
                    collision = true;
                }
            }

            base.Update(gameTime, gameObjects);
        }
示例#6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            var gameboundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
            var paddleTexture  = Content.Load <Texture2D>("Paddle");


            _spriteBatch  = new SpriteBatch(GraphicsDevice);
            _playerPaddle = new Paddle(Content.Load <Texture2D>("Paddle"), Vector2.Zero, gameboundaries, PlayerTypes.Human);

            var computerPaddleLocation = new Vector2(Window.ClientBounds.Width - paddleTexture.Width, 0);

            _computerPaddle = new Paddle(Content.Load <Texture2D>("Paddle"), computerPaddleLocation, gameboundaries, PlayerTypes.Computer);
            _ball           = new Ball(Content.Load <Texture2D>("Ball"), Vector2.Zero, gameboundaries);
            _ball.AttachTo(_playerPaddle);
            Score = new Score(Content.Load <SpriteFont>("NewSpriteFont"), gameboundaries);

            GameObjects = new GamesObjects {
                PlayerPaddle = _playerPaddle, Computeraddle = _computerPaddle, Ball = _ball, Score = Score
            };
            // TODO: use this.Content to load your game content here
        }
示例#7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            var gameboundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
            var paddleTexture = Content.Load<Texture2D>("Paddle");

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _playerPaddle = new Paddle(Content.Load<Texture2D>("Paddle"), Vector2.Zero, gameboundaries, PlayerTypes.Human);

            var computerPaddleLocation = new Vector2(Window.ClientBounds.Width - paddleTexture.Width, 0);
            _computerPaddle = new Paddle(Content.Load<Texture2D>("Paddle"), computerPaddleLocation , gameboundaries, PlayerTypes.Computer);
            _ball = new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameboundaries);
            _ball.AttachTo(_playerPaddle);
            Score = new Score(Content.Load<SpriteFont>("NewSpriteFont"),gameboundaries);

            GameObjects = new GamesObjects { PlayerPaddle = _playerPaddle, Computeraddle = _computerPaddle, Ball = _ball, Score = Score};
            // TODO: use this.Content to load your game content here
        }
示例#8
0
        public virtual void Update(GameTime gameTime, GamesObjects gameObjects)
        {
            Location += Velocity;

            CheckBounds();
        }
示例#9
0
        public virtual void Update(GameTime gameTime, GamesObjects gameObjects)
        {
            Location += Velocity;

            CheckBounds();
        }