Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TankFireTest
  4. {
  5. public class Vector3
  6. {
  7. public Vector3(float ix, float iy, float iz)
  8. {
  9. X = ix;
  10. Y = iy;
  11. Z = iz;
  12. }
  13.  
  14. public float X { get; set; }
  15. public float Y { get; set; }
  16. public float Z { get; set; }
  17.  
  18. public static float DotProduct(Vector3 a, Vector3 b)
  19. {
  20. return (a.X * b.X) + (a.Y * b.Y) + (a.Z * b.Z);
  21. }
  22. public static float GetLength(Vector3 v)
  23. {
  24. float len2 = (v.X * v.X) + (v.Y * v.Y) + (v.Z * v.Z);
  25. return (float)Math.Sqrt(len2);
  26. }
  27. }
  28.  
  29. class Program
  30. {
  31. bool TankCanFire( playerRange, enemyPosition )
  32. {
  33. if (playerRange <= enemyTankPosition )
  34. {
  35. return true;
  36. }
  37. return false;
  38.  
  39. }
  40.  
  41. static void Main(string[] args)
  42. {
  43. Vector3 playerPosition = new Vector3( 10, 15, 10 );
  44. Vector3 playerFacing = new Vector3(0.0f, 0.0f, 1.0f);
  45. float playerRange = 100.0f;
  46.  
  47. Vector3 enemyTankPosition = new Vector3( -15, 10, 25 );
  48. Vector3 enemyFacing = new Vector3(0.0f, 0.0f, 1.0f);
  49.  
  50. if (TankCanFire(playerRange,enemyPosition)== true)
  51. {
  52. Console.WriteLine("Firing!");
  53. }
  54. else
  55. {
  56. Console.WriteLine("Cannot fire");
  57. }
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment