little help
The highlighted comment was created in this revision.
Hi mate. You can change the color with:
public void run() {
// all the same color
setAllColors(Color.RED);
// or different for body , gun , radar
setRadarColor(Color.GREEN);
setGunColor(Color.BLUE);
setBodyColor(Color.BLACK);
...
}
You can make a bookmark to the robocode api Robocode API and there you find all the functions you can use. It looks a bit complicated if you are not familiar whit this kind of documentation but with a little help you get used to it very quickly.
For example if you look for the color. Hit the "AdvancedRobot" in the left frame "All Classes" and search just for "Color" in the right frame. Every function has a short description so just poke around a little.
And don't be shy just ask whatever you wan't to know.
take care
The API is your best friend. I also suggest you bookmark the Java API. The API documentation is a very useful set of documents.
For your purposes, java.lang.Math which has math methods, java.awt.geom which has geometry, and java.util which holds most generic data structures (maps, lists, sets, etc) are the packages you will likely use the most.
Within the robocode API, AdvancedRobot is a big bit of useful reference.
Whenever I try to change the colour it comes up with this error message
Compiling... BOSSSSS.java:15: cannot find symbol symbol : variable Colour location: class b.BOSSSSS
setallcolours(Colour.RED); ^
1 error Compile Failed (1)
Im a complete newby so I don't know what to do. Anyone Help?
Two things:
- The caps and (non-British) spelling matter:
setAllColors(Color.RED);
- You might need to import the Color class at the top of your file:
import java.awt.Color;
Nope, you can only fire one bullet at a time, and you have to wait 11-16 ticks before firing another one, depending on the bullet power you use. A lot information about the basic rules / physics of Robocode can be found at Robocode/FAQ.
You can adjust the gun cooling rate if you want to do it just for fun, but under the normal rules everyone else (and the RoboRumble) uses, no you can't. I think the gun cooling rate can be adjusted in settings, but it might be something directly in robocode.properties, I'm not sure...
hi i've tried radial targeting but I kepp getting a error message. Could you guys just check my code.
package argeaer;
import robocode.*;
//import java.awt.Color;
/**
* Arg - a robot by (your name here)
*/
public class Arg extends Robot
{
/**
* run: Arg's default behavior
*/
public void run() {
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
//setColors(Color.red,Color.blue,Color.green);
while(true) {
// Replace the next 4 lines with any behavior you would like
ahead(100);
turnGunRight(360);
back(100);
turnGunRight(360);
}
}
/**
* onScannedRobot: What to do when you see another robot
*/
/**This function predicts the time of the intersection between the
bullet and the target based on a simple iteration. It then moves
the gun to the correct angle to fire on the target.**/
void doGun() {
long time;
long nextTime;
Point2D.Double p;
p = new Point2D.Double(target.x, target.y);
for (int i = 0; i < 10; i++){
nextTime =
(intMath.round((getRange(getX(),getY(),p.x,p.y)/(20-(3*firePower))));
time = getTime() + nextTime;
p = target.guessPosition(time);
}
/**Turn the gun to the correct angle**/
double gunOffset = getGunHeadingRadians() -
(Math.PI/2 - Math.atan2(p.y - getY(), p.x - getX()));
setTurnGunLeftRadians(normaliseBearing(gunOffset));
}
double normaliseBearing(double ang) {
if (ang > Math.PI)
ang -= 2*PI;
if (ang < -Math.PI)
ang += 2*Math.PI;
return ang;
}
public double getrange(double x1,double y1, double x2,double y2) {
double x = x2-x1;
double y = y2-y1;
double h = Math.sqrt( x*x + y*y );
return h;
}
/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
turnLeft(90 - e.getBearing());
}
}
Please, format yours code and in future use tag <syntaxhighlight>. What kind of error message you get?
Can you post the error message? Looks like you missed the onScannedRobot(ScannedRobotEvent e) Method.