Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class GameplayScreen
- {
- public Update ()
- {
- .........
- // Checking for collision of the bats
- if (ball.GetDirection() > 1.5f * Math.PI || ball.GetDirection() < 0.5f * Math.PI)
- {
- if (rightBat.GetSize().Intersects(ball.GetSize()))
- {
- ball.BatHit(CheckHitLocation(rightBat));
- }
- }
- else if (leftBat.GetSize().Intersects(ball.GetSize()))
- {
- ball.BatHit(CheckHitLocation(leftBat));
- }
- ......................
- }
- }
- ////////////////////////////////////
- /// <summary>
- /// Checking for bat collision & instructs the ball where to deflect to
- /// </summary>
- private int CheckHitLocation(Bat bat)
- {
- int block = 0;
- if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 20)
- {
- block = 1;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 2)
- {
- block = 2;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 3)
- {
- block = 3;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 4)
- {
- block = 4;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 5)
- {
- block = 5;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 6)
- {
- block = 6;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 7)
- {
- block = 7;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 8)
- {
- block = 8;
- }
- else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 20 * 19)
- {
- block = 9;
- }
- else
- {
- block = 10;
- }
- return block;
- }
RAW Paste Data