Example #1
0
        public void Update(GameTime gameTime, Kinect kinectState, Ball ball)
        {
            //if (kinectState.Side == KinectSide.Left && Position.Y > 0)
            //{
            //    _direction = new Vector2(0, -1);
            //}
            //else if (kinectState.Side == KinectSide.Rigth && Position.Y + Texture.Height < 600)
            //{
            //    _direction = new Vector2(0, 1);
            //}
            //else
            //{
            //    _direction = Vector2.Zero;
            //}
            //Position += _direction * _velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            //Position = new Vector2(Position.X, kinectState.Posicao);

            float distance;
            if (side == 0)
            {
                distance = Position.Y - kinectState.PosicaoLeft;
            }
            else
            {
                distance = Position.Y - kinectState.PosicaoRigth;
            }
            if (distance < 0)
            {
                _direction = new Vector2(0, 1);
            }
            else
            {
                _direction = new Vector2(0, -1);
            }
            distance *= Math.Sign(distance);

            Position += _direction * (distance * 30) * (float)gameTime.ElapsedGameTime.TotalSeconds;

            UpdateBallState(ball);
        }
Example #2
0
        private void UpdateBallState(Ball ball)
        {
            BoundingBox bat = new BoundingBox(new Vector3(Position, 0),
                new Vector3(Position.X + Texture.Width, Position.Y + Texture.Height, 0));

            BoundingBox ballRec = new BoundingBox(new Vector3(ball.Position, 0),
                new Vector3(ball .Position.X + ball.Texture.Width, ball.Position.Y + ball.Texture.Height, 0));

            if (bat.Intersects(ballRec))
            {
                ball.Direction *= new Vector2(-1, 1);
            }
        }
Example #3
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.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            this.Services.AddService(typeof(SpriteBatch), spriteBatch);

            foreach (IObject item in this.objectsOnScreen)
            {
                item.LoadContent();
            }

            // TODO: use this.Content to load your game content here
            _background = this.Content.Load<Texture2D>(@"Texture\ping_pong");
            _ball = new Ball(this, new Vector2(386.0f, 310.0f));
            _bat1 = new Bat(this, new Vector2(10.0f, 290.0f), Keys.Up, Keys.Down, 0);
            _bat2 = new Bat(this, new Vector2(765.0f, 290.0f), Keys.W, Keys.S , 1);
        }