예제 #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();
        }