home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2001 November / Gamestar_34_2001-11_cd1.bin / DEMA / colobotdemoe.exe / script / shield03.txt < prev    next >
Text File  |  2001-07-27  |  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;                  // stop the program
  12.     }
  13.     shield(1, 25);               // activate the shield
  14.     
  15.     while ( true )               // repeat forever
  16.     {
  17.         item = radar(PhazerShooter);// look 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);             // wait
  24.         }
  25.         else                     // otherwise:
  26.         {    // Calculate 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 go there
  31.         }
  32.     }
  33. }
  34.