Advertisement
PsyOps

Collision Maths

Nov 14th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1.         /// <summary>
  2.         /// This will configure your weapon for storing.
  3.         /// </summary>
  4.         public string Configure(ushort[] Target, PlayerPositionEvent p)
  5.         {
  6.             position = Target;
  7.  
  8.             int bombXVel, bombYVel;
  9.             int playerXVel, playerYVel;
  10.  
  11.             // If the player being tracked has fired a bomb
  12.             // Save the spot where the bomb was fired
  13.             bombStart = new ushort[2] { p.MapPositionX, p.MapPositionY };
  14.  
  15.             // Compute the velocity of the bomb
  16.             bombXVel = (int)(-xChange[p.ShipRotation] * 2000);
  17.             bombYVel = (int)(-yChange[p.ShipRotation] * 2000);
  18.  
  19.  
  20.             // Convert the player's velocity out of ss format
  21.             playerXVel = (int)(p.VelocityX);
  22.             if (playerXVel > (ushort.MaxValue / 2))
  23.                 playerXVel = playerXVel - ushort.MaxValue;
  24.  
  25.             playerYVel = (int)(p.VelocityY);
  26.             if (playerYVel > (ushort.MaxValue / 2))
  27.                 playerYVel = playerYVel - ushort.MaxValue;
  28.  
  29.  
  30.             // Add the reformatted velocity to the bomb velocity
  31.             bombXVel = bombXVel + playerXVel;
  32.             if (bombXVel > (ushort.MaxValue / 2))
  33.                 bombXVel = bombXVel - ushort.MaxValue;
  34.  
  35.             bombYVel = bombYVel + playerYVel;
  36.             if (bombYVel > (ushort.MaxValue / 2))
  37.                 bombYVel = bombYVel - ushort.MaxValue;
  38.  
  39.             bombForce = (int)(Math.Sqrt(bombXVel * bombXVel + bombYVel * bombYVel));
  40.             bombVel = new int[2] { bombXVel, bombYVel };
  41.             playerVel = new int[2] { playerXVel, playerYVel };
  42.  
  43.             string result = CalculateHit();
  44.  
  45.             if (result == "~miss")
  46.                 return result;
  47.             else return result;
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement