Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. foreach (GameObject ball in shipList)
  2.             {
  3.                 int MaxX = graphics.GraphicsDevice.Viewport.Width - ball.BoundingBox.Width;
  4.                 int MinX = 0;
  5.  
  6.                 int MaxY = graphics.GraphicsDevice.Viewport.Height - ball.BoundingBox.Height;
  7.                 int MinY = 0;
  8.  
  9.                 if (ball.Position.X > MaxX)
  10.                 {
  11.                     ball.Position.X = MaxX;
  12.                     ball.Velocity.X *= -1;
  13.                 }
  14.                 else if (ball.Position.X < MinX)
  15.                 {
  16.                     ball.Position.X = MinX;
  17.                     ball.Velocity.X *= -1;
  18.                 }
  19.  
  20.                 if (ball.Position.Y > MaxY)
  21.                 {
  22.                     ball.Position.Y = MaxY;
  23.                     ball.Velocity.Y *= -1;
  24.                 }
  25.                 else if (ball.Position.Y < MinY)
  26.                 {
  27.                     ball.Position.Y = MinY;
  28.                     ball.Velocity.Y *= -1;
  29.                 }
  30.  
  31.                 foreach (GameObject ball2 in shipList)
  32.                 {
  33.  
  34.                     if (ball != ball2)
  35.                     {
  36.                         if (ball.BoundingBox.Intersects(ball2.BoundingBox))
  37.                         {
  38.  
  39.                            
  40.                             ball.Velocity.X *= -1;
  41.                             ball.Velocity.Y *= -1;
  42.                             ball2.Velocity.X *= -1;
  43.                             ball2.Velocity.Y *= -1;
  44.                         }
  45.  
  46.                     }
  47.                 }
  48.  
  49.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement