home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 1113.dms / 1113.adf / CRobots / sharpshooter.r < prev    next >
Text File  |  1993-03-02  |  2KB  |  103 lines

  1. Dark Unicorn
  2. Damascene Ind.
  3. /* SHARPSHOOTER
  4.  
  5.    Copyright (C) 1988 Dark Unicorn Publishing
  6.    A Product of Damascene Industries
  7.  
  8.    TIGER without movement.  SHARPSHOOTER is designed to lock onto and destroy
  9.    any robot it sees. */
  10.  
  11. int angle,range;
  12.  
  13. main()
  14. {
  15.   move (500,500);
  16.   while (1)
  17.     search();
  18. }
  19.  
  20. /* Search: SHARPSHOOTER uses a fast scan to detect targets, then guns it down
  21.     with auto-tracking. */
  22.  
  23. search()
  24. {
  25.   if (range = scan(angle += 130,10))
  26.     while (range = scan(angle = track(angle,10),10))
  27.       cannon(angle,range * 9 / 10);
  28. }
  29.  
  30. /* Track: pinpoints the enemy. */
  31.  
  32. track(d,r)
  33. int d,r;
  34. {
  35.   if (r > 0)
  36.     {
  37.       if (scan(d-r,r) > 0)
  38.         return(track(d-r,r/2));
  39.       else
  40.         if (scan(d+r,r) > 0)
  41.           return(track(d+r,r/2));
  42.         else
  43.           return(track(d,r/2));
  44.     }
  45.   else
  46.     return(d);
  47. }
  48.  
  49. /* Move: go to a specific location.  Shoot anything seen in SHARPSHOOTER's
  50.     path. */
  51.  
  52. move (dest_x, dest_y)
  53. int dest_x, dest_y;
  54. {
  55.   int course,range;
  56.  
  57.   course = plot_course(dest_x,dest_y);
  58.   while (distance(loc_x(),loc_y(),dest_x,dest_y) > 50)
  59.   {
  60.     drive (course,100);
  61.     if (range = scan(course,10))
  62.       cannon(course,range);
  63.   }
  64.   drive(course,0);
  65. }
  66.  
  67. /* Distance: calculates distance between two points. */
  68.  
  69. distance(x1,y1,x2,y2)
  70. int x1,y1,x2,y2;
  71. {
  72.   return(sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))));
  73. }
  74.  
  75. /* Plot Course: calculates the degree heading of a location. */
  76.  
  77. plot_course(xx,yy)
  78. int xx, yy;
  79. {
  80.   int d,
  81.       x,y;
  82.  
  83.   x = loc_x() - xx;
  84.   y = loc_y() - yy;
  85.  
  86.   if (x == 0) {
  87.     if (y > 0)
  88.       d = 90;
  89.     else
  90.       d = 270;
  91.   }
  92.   else {
  93.     d = atan((100000 * y) / x);
  94.     if (x >= 0)
  95.       d += 180;
  96.     else if ((y > 0) && (x < 0))
  97.       d += 360;
  98.   }
  99.   return (d % 360);
  100. }
  101.  
  102.  
  103.