colobot-data/help/tremova2.txt

36 lines
1.9 KiB
Plaintext

\b;Exercise
This exercise is very similar to the previous one. There are now three \l;titanium cubes\u object\titan; that you must move to 3 finishing pads. Here are the coordinates of the finishing pads:
\c;
x=10, y=-60
x=10, y=-65
x=10, y=-70
\n;
\b;General principle
Repeat 3 times:
o Look for the most distant titanium cube with \c;\l;radar\u cbot\radar;\n;.
o Pick it up with \c;\l;grab\u cbot\grab;\n;.
o Go to one of the pads with \c;\l;goto\u cbot\goto;\n;.
o Drop the titanium with \c;\l;drop\u cbot\drop;\n;.
If you look for the nearest titanium cube, the radar would find one that you already retrieved and dropped on a pad. Therefore you must look for the most distant titanium cube.
\b;The program
Use a \c;\l;for\u cbot\for;\n; loop in order to repeat 3 times all the instructions necessary to retrieve the titanium cube. Inside the loop, in order to find the most distant titanium cube, use the instruction \c;\l;radar\u cbot\radar;(Titanium, 0, 360, 0, 1000, -1);\n;. The last value \c;-1\n; means that instead of looking for the closest item, the radar will return the most distant that it can find.
\c;
\s;object metal;
\s;metal = radar(Titanium, 0, 360, 0, 1000, -1);
\s;if ( metal == null ) return;
\s;goto(metal.position);
\n;
The variable \c;metal\n; if of type \c;\l;object\u cbot\object;\n;. In order to know the position of the object described by the variable, you must write \c;metal.position\n;.
The \c;x\n; coordinates of the 3 pads are all equal to 10. The \c;y\n; coordinates are respectively -60, -65 and -70. The most efficient way to get the coordinates of the pads is to use the value of \c;i\n; of the \c;for\n; loop that will take successively the values 0, 1 and 2:
\c;
\s;dest.x = 10;
\s;dest.y = -60-5*i;
\n;
It is up to you now to finish the program.
\t;See also
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.