home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 51 / PCGamer51_17Demos.iso / games / colobotdemo / colobotdemo10e.exe / help / Tant2.TXT < prev    next >
Encoding:
Text File  |  2001-07-03  |  2.2 KB  |  34 lines

  1. \b;Objective
  2. As a defense against ants attacking from all sides, adapt the program \c;Spider2\n; in order to fly at a given altitude.
  3.  
  4. \t;Program
  5. The program necessary for this task is somewhat similar to the program \c;Spider2\n; that looks for the closest ant, turns toward it and fires:
  6. \c;
  7. \s;extern void object::Spider2()
  8. \s;{    
  9. \s;    object    item;
  10. \s;    
  11. \s;    while (true)
  12. \s;    {
  13. \s;        item = radar(AlienSpider);
  14. \s;        turn(direction(item.position));
  15. \s;        fire(1);
  16. \s;    }
  17. \s;}
  18. \n;
  19. You can copy-paste it to the editor, and adapt it. Replace \c;radar(AlienSpider);\n; by \c;radar(AlienAnt);\n;, and write before the \c;while\n; loop another loop that activates the jet beneath the \l;winged shooter\u object\botfj; until the bot reaches an altitude of 20 meters.
  20.  
  21. The instruction \c;\l;jet\u cbot\jet;()\n; controls the jet beneath winged bots. The number in brackets must range between \c;-1\n; and \c;1\n;.\c; jet(1);\n; moves the bot upward with maximum speed.\c; jet(-1);\n; moves the bot downward with maximum speed, and \c;jet(0);\n; stabilizes the altitude. As the bot must reach a precise altitude, move it upward slowly with \c;jet(0.2);\n;, wait until it has reached the desired height, then stabilize the altitude with \c;jet(0);\n;.
  22.  
  23. In order to "wait until it has reached the desired height", we need a conditional loop: the instructions inside the loop will be repeated only as long as a certain condition is true. The altitude of the bot is given by \c;position.z\n;. We already saw that \c;position\n; gives the position of the bot. And a position is given by the three coordinates x, y and z: the x-axis is the axis west-east, the y-axis is the axis south-north, and the z-axis is the vertical axis. Therefore we must wait while \c;position.z\n; is smaller than 20:
  24. \c;
  25. \s;    while (position.z < 20)
  26. \s;    {
  27. \s;        wait(0.2);
  28. \s;    }
  29. \n;
  30. After waiting 0.2 seconds, the program will check if the altitude is still below 20 meters. If this is the case, it will wait a little more, if not, the program continues after the loop, i.e. after the closing brace \c;}\n;. Do not forget after the loop to stabilize the altitude with \c;jet(0);\n;.
  31.  
  32. \t;See also
  33. \l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
  34.