15 lines
1.2 KiB
Plaintext
15 lines
1.2 KiB
Plaintext
\b;Objective
|
|
Move towards the spiders that are out of shooting range.
|
|
|
|
\t;Program
|
|
The program will look like the previous one, but before you shoot, use the instruction \c;\l;move\u cbot\move;();\n; in order to get close enough.
|
|
|
|
The question is just how many meters the bot must move. The instruction \c;\l;distance\u cbot\dist;( , )\n; calculates the distance between two positions. In this case, we need to know the distance between the bot and the target. The position of the target is given by \c;item.position\n;, the position of the bot is give by \c;position\n;. The distance between the bot and the target is given by \c;\l;distance\u cbot\dist;(position, item.position)\n;. The range of a fireball cannon is 40 meters. In order to get close enough, the bot must move forward \c;\l;distance\u cbot\dist;(position, item.position)-40\n; meters. The following line will do this:
|
|
\c;
|
|
\s; \l;move\u cbot\move;(\l;distance\u cbot\dist;(position, item.position)-40);
|
|
\n;
|
|
Just insert this line into the program before the instruction \c;fire(1);\n;, and the bot will start to move.
|
|
|
|
\t;See also
|
|
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|