Guest User

Untitled

a guest
Feb 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 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. //This is in the ball.cs, ball extends sprite.cs
  31.  
  32. //Here it is passed the paddle object:
  33.  
  34. public ball(Texture2D texture, Vector2 position, Color colour, sprite Paddle)
  35. :base(texture, position, colour)
  36. {
  37. _position.X = 200;
  38. _position.Y = 100;
  39. _colour = Color.Red;
  40. thisPaddle = (paddle)Paddle;
  41. }
  42.  
  43. //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.
  44.  
  45. public bool paddleCollision()
  46. {
  47. if (thisPaddle.Rect.Intersects(_rect)){
  48. return true;
  49. }else{
  50. return false;
  51. }
  52. }
  53.  
  54. //This is just the update code, to occur each "tick"
  55. public override void update(KeyboardState state)
  56. {
  57. if (paddleCollision())
  58. {
  59. _moveSpeed = base.Collision(1, new Vector2(_moveSpeed.X, _moveSpeed.Y));
  60. }
  61. _position += _moveSpeed;
  62. }
  63. }
  64.  
  65.  
  66. }
  67. _position += _moveSpeed;
  68. }
  69. }
Add Comment
Please, Sign In to add comment