Пример #1
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            if (playerType == PlayerTypes.Computer)
            {
                var random = new Random();
                var reactionTreshold = random.Next(30, 130);

                if(gameObjects.Ball.Location.Y + gameObjects.Ball.Height < Location.Y + reactionTreshold)
                    Velocity = new Vector2(0, -3.5f);
                if (gameObjects.Ball.Location.Y  > Location.Y + Height + reactionTreshold)
                    Velocity = new Vector2(0, 3.5f);
            }

            if (playerType == PlayerTypes.Human)
            {
                // move paddle up
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                    Velocity = new Vector2(0, -3.5f);

                // move paddle down
                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                    Velocity = new Vector2(0, 3.5f);
            }
            base.Update(gameTime, gameObjects);
        }
Пример #2
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            if(Keyboard.GetState().IsKeyDown(Keys.Space) && attachedToPaddle != null)
            {
                var newVelocity = new Vector2(5.0f, attachedToPaddle.Velocity.Y * 0.65f);
                Velocity = newVelocity;
                attachedToPaddle = null;
            }

            if(attachedToPaddle != null)
            {
                Location.X = attachedToPaddle.Location.X + attachedToPaddle.Width;
                Location.Y = attachedToPaddle.Location.Y;
            }
            else
            {
                if (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox) ||
                    BoundingBox.Intersects(gameObjects.ComputerPaddle.BoundingBox))
                {
                    Velocity = new Vector2(-Velocity.X, Velocity.Y);
                }

            }

            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);
            }

            if (gameObjects.Ball.Location.X > gameBoundaries.Width)
            {
                PlayerScore++;
                gameObjects.Ball.AttachTo(gameObjects.PlayerPaddle);
            }
        }
Пример #4
0
        public void Update(GameTime gameTime, GameObjects 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);
            }
        }
Пример #5
0
        public virtual void Update(GameTime gameTime, GameObjects gameObjects)
        {
            Location = Location + Velocity;

            checkBounds();
        }
Пример #6
0
        public virtual void Update(GameTime gameTime, GameObjects gameObjects)
        {
            Location = Location + Velocity;

            checkBounds();
        }