Guest User

Untitled

a guest
Feb 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. This is in the ball.cs, ball extends sprite.cs
  2.  
  3. Here it is passed the paddle object:
  4.  
  5.         public ball(Texture2D texture, Vector2 position, Color colour, sprite Paddle)
  6.             :base(texture, position, colour)
  7.         {
  8.             _position.X = 200;
  9.             _position.Y = 100;
  10.             _colour = Color.Red;
  11.             thisPaddle = (paddle)Paddle;
  12.         }
  13.  
  14. This checks for a collision. Rect being the accessor to the paddles bounding Box. _rect being the inherited class member for the balls bounding box.
  15.  
  16.         public bool paddleCollision()
  17.         {
  18.             if (thisPaddle.Rect.Intersects(_rect)){
  19.                 return true;
  20.             }else{
  21.                 return false;
  22.             }
  23.         }
  24.        
  25. This is just the update code, to occur each "tick"
  26.         public override void update(KeyboardState state)
  27.         {
  28.             if (paddleCollision())
  29.             {
  30.                 _moveSpeed.Y = -_moveSpeed.Y;
  31.                 _moveSpeed.X = _moveSpeed.X += thisPaddle.speedReturn() * 0.1f;
  32.             }
  33.             _position += _moveSpeed;
  34.         }
  35.     }
Add Comment
Please, Sign In to add comment