Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            //Movement from controller
            controller.HandleInput(gameTime);
            this.Direction = controller.Direction;

            //Collision Rect
            top = new Rectangle((int)this.Location.X, (int)this.Location.Y, this.spriteTexture.Width, 1);

            if (ball.State == BallState.OnPaddle)
            {
                //Move the ball with the paddle until launch
                ball.Speed     = 0;
                ball.Direction = Vector2.Zero;
                ball.Location  = new Vector2(this.Location.X + this.LocationRect.Width / 2, this.Location.Y - ball.SpriteTexture.Height);
            }
            else
            {
                //Ball Collsion
                //Very simple collision with ball only uses rectangles
                if (top.Intersects(ball.LocationRect))
                {
                    //TODO Change angle based on location of collision or direction of paddle
                    ball.Direction.Y *= -1;
                    console.GameConsoleWrite("Paddle collision ballLoc:" + ball.Location + " paddleLoc:" + this.Location.ToString());
                }
            }

            this.Location += this.Direction * (this.Speed * gameTime.ElapsedGameTime.Milliseconds / 1000);
            KeepPaddleOnScreen();
            base.Update(gameTime);
        }
Esempio n. 2
0
        Rectangle collisionRectangle;  //Rectangle for paddle collision uses just the top of the paddle instead of the whole sprite

        public override void Update(GameTime gameTime)
        {
            //Update Collision Rect
            collisionRectangle = new Rectangle((int)this.Location.X, (int)this.Location.Y, this.spriteTexture.Width, 1);

            //Deal with ball state
            switch (ball.State)
            {
            case BallState.OnPaddleStart:
                //Move the ball with the paddle until launch
                UpdateMoveBallWithPaddle();
                break;

            case BallState.Playing:
                UpdateCheckBallCollision();
                break;
            }

            //Movement from controller
            controller.HandleInput(gameTime);

            this.Direction = controller.Direction;
            this.Location += this.Direction * (this.Speed * gameTime.ElapsedGameTime.Milliseconds / 1000);

            KeepPaddleOnScreen();
            base.Update(gameTime);
        }