home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 51 / PCGamer51_17Demos.iso / games / colobotdemo / colobotdemo10e.exe / script / shield03.txt < prev    next >
Text File  |  2001-06-17  |  1KB  |  34 lines

  1. extern void object::FollowPhazer()
  2. {
  3.     object    item;              // info. about phazer
  4.     point     dest;              // position where to go
  5.     float     dist;              // distance to phazer
  6.  
  7.     item = radar(PhazerShooter);
  8.     if ( item == null )
  9.     {
  10.         message("No phazer found");
  11.         return;                  // stops the program
  12.     }
  13.     shield(1, 25);               // activates the shield
  14.     
  15.     while ( true )               // always repeats:
  16.     {
  17.         item = radar(PhazerShooter);// looks for phazer
  18.         if ( item == null )  break;
  19.  
  20.         dist = distance(item.position, position);
  21.         if ( dist < 5 )
  22.         {                        // if closer than 5 m:
  23.             wait(1);             // waits
  24.         }
  25.         else                     // otherwise:
  26.         {    // Calculates a position 5 m before the phazer
  27.             dest.x = (item.position.x-position.x)*((dist-5)/dist)+position.x;
  28.             dest.y = (item.position.y-position.y)*((dist-5)/dist)+position.y;
  29.             dest.z = (item.position.z-position.z)*((dist-5)/dist)+position.z;
  30.             goto(dest, 0, 1, 1); // and goes there
  31.         }
  32.     }
  33. }
  34.