Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is in the ball.cs, ball extends sprite.cs
- Here it is passed the paddle object:
- public ball(Texture2D texture, Vector2 position, Color colour, sprite Paddle)
- :base(texture, position, colour)
- {
- _position.X = 200;
- _position.Y = 100;
- _colour = Color.Red;
- thisPaddle = (paddle)Paddle;
- }
- 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.
- public bool paddleCollision()
- {
- if (thisPaddle.Rect.Intersects(_rect)){
- return true;
- }else{
- return false;
- }
- }
- This is just the update code, to occur each "tick"
- public override void update(KeyboardState state)
- {
- if (paddleCollision())
- {
- _moveSpeed.Y = -_moveSpeed.Y;
- _moveSpeed.X = _moveSpeed.X += thisPaddle.speedReturn() * 0.1f;
- }
- _position += _moveSpeed;
- }
- }
Add Comment
Please, Sign In to add comment