Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ball
- {
- ....
- private Rectangle ballRect;
- ....
- public Ball(args)
- {
- ....
- ballRect = new Rectangle(0, 0, texture.Width, texture.Height);
- ....
- }
- /// <summary>
- /// Updates position of the ball. Used in Update() for GameplayScreen.
- /// </summary>
- public void UpdatePosition(GameTime gameTime)
- {
- ballRect.X = (int)ballPosition.X;
- ballRect.Y = (int)ballPosition.Y;
- oldBallPos.X = ballPosition.X;
- oldBallPos.Y = ballPosition.Y;
- ballPosition.X += speed * ((float)Math.Cos(direction));
- ballPosition.Y += speed * ((float)Math.Sin(direction));
- bool collided = CheckWallHit();
- // Stops the issue where ball was oscillating on the ceiling or floor
- if (collided)
- {
- ballPosition.X = oldBallPos.X + speed * (float)Math.Cos(direction);
- ballPosition.Y = oldBallPos.Y + speed * (float)Math.Sin(direction);
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////////
- public class bat
- {
- ....
- public Rectangle batRect;
- ....
- public bat(args)
- {
- ....
- batRect = new Rectangle(0, 0, leftBat.Width, leftBat.Height);
- ....
- }
- /// <summary>
- /// Updates the position of the AI bat, in order to track the ball
- /// </summary>
- public virtual void UpdatePosition(Ball ball, GameTime gameTime)
- {
- ...
- batRect.X = (int)BatPosition.X;
- batRect.Y = (int)BatPosition.Y;
- ....
- }
- }
RAW Paste Data