public AIInput(Ball theBall, Paddle thePaddle, Viewport theViewport) : base(PlayerIndex.One) { mBall = theBall; mPaddle = thePaddle; mViewport = theViewport; }
public void CheckCollision(Paddle thePaddle) { if (thePaddle.CollisionRectangle.Intersects(CollisionRectangle)) { bool aMovingRight = (mMovement.X > 0); bool aMovingLeft = (mMovement.X < 0); bool aLeftOfPaddle = (Position.X < thePaddle.Position.X); bool aRightOfPaddle = (Position.X > thePaddle.Position.X); if (( aMovingRight && aLeftOfPaddle ) || (aMovingLeft && aRightOfPaddle)) { mMovement.X *= -1; mHit.Play(); } } }
public void Update(GameTime theGametime, Paddle thePaddleOne, Paddle thePaddleTwo) { Move(mMovement); switch (BoundaryCollisionCheck(true)) { case Direction.Left: { OutOfBounds = Direction.Left; Reset(); break; } case Direction.Right: { OutOfBounds = Direction.Right; Reset(); break; } case Direction.Top: { mMovement.Y *= -1; mHit.Play(); break; } case Direction.Bottom: { mMovement.Y *= -1; mHit.Play(); break; } } CheckCollision(thePaddleOne); CheckCollision(thePaddleTwo); }
public void StartTwoPlayerGame(PlayerIndex thePlayerOne, PlayerIndex thePlayerTwo) { mPlayerOnePaddle = new Paddle(mContent, "Sprites/Square", new Input(thePlayerOne), Paddle.PaddlePosition.Left); mPlayerTwoPaddle = new Paddle(mContent, "Sprites/Square", new Input(thePlayerTwo), Paddle.PaddlePosition.Right); }
public void StartOnePlayerGame(PlayerIndex thePlayerOne) { mPlayerOnePaddle = new Paddle(mContent, "Sprites/Square", new Input(thePlayerOne), Paddle.PaddlePosition.Left); mPlayerTwoPaddle = new Paddle(mContent, "Sprites/Square", new Input(thePlayerOne), Paddle.PaddlePosition.Right); mPlayerTwoPaddle.mInput = new AIInput(mBall, mPlayerTwoPaddle, mViewport); }