|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrobocode._Robot
robocode.Robot
public class Robot
The basic robot class that you will extend to create your own robots.
Please note the following standards will be used:
heading - absolute angle in degrees with 0 facing up the screen,
positive clockwise. 0 <= heading < 360.
bearing - relative angle to some object from your robot's heading,
positive clockwise. -180 < bearing <= 180
All coordinates are expressed as (x,y).
All coordinates are positive.
The origin (0,0) is at the bottom left of the screen.
Positive x is right.
Positive y is up.
Field Summary | |
---|---|
java.io.PrintStream |
out
The output stream your robot should use to print. |
Constructor Summary | |
---|---|
Robot()
Constructs a new robot. |
Method Summary | |
---|---|
void |
ahead(double distance)
Immediately moves your robot ahead (forward) by distance measured in pixels. |
void |
back(double distance)
Immediately moves your robot backward by distance measured in pixels. |
void |
doNothing()
Do nothing this turn, meaning that the robot will skip it's turn. |
void |
finalize()
Called by the system to 'clean up' after your robot. |
void |
fire(double power)
Immediately fires a bullet. |
Bullet |
fireBullet(double power)
Immediately fires a bullet. |
double |
getBattleFieldHeight()
Returns the height of the current battlefield measured in pixels. |
double |
getBattleFieldWidth()
Returns the width of the current battlefield measured in pixels. |
double |
getEnergy()
Returns the robot's current energy. |
double |
getGunCoolingRate()
Returns the rate at which the gun will cool down, i.e. the amount of heat the gun heat will drop per turn. |
double |
getGunHeading()
Returns the direction that the robot's gun is facing, in degrees. |
double |
getGunHeat()
Returns the current heat of the gun. |
double |
getHeading()
Returns the direction that the robot's body is facing, in degrees. |
double |
getHeight()
Returns the height of the robot measured in pixels. |
java.lang.String |
getName()
Returns the robot's name |
int |
getNumRounds()
Returns the number of rounds in the current battle. |
int |
getOthers()
Returns how many opponents are left in the current round. |
double |
getRadarHeading()
Returns the direction that the robot's radar is facing, in degrees. |
int |
getRoundNum()
Returns the number of the current round (0 to getNumRounds() - 1)
in the battle. |
long |
getTime()
Returns the game time of the current round, where the time is equal to the current turn in the round. |
double |
getVelocity()
Returns the velocity of the robot measured in pixels/turn. |
double |
getWidth()
Returns the width of the robot measured in pixels. |
double |
getX()
Returns the X position of the robot. (0,0) is at the bottom left of the battlefield. |
double |
getY()
Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield. |
void |
onBulletHit(BulletHitEvent event)
This method is called when one of your bullets hits another robot. |
void |
onBulletHitBullet(BulletHitBulletEvent event)
This method is called when one of your bullets hits another bullet. |
void |
onBulletMissed(BulletMissedEvent event)
This method is called when one of your bullets misses, i.e. hits a wall. |
void |
onDeath(DeathEvent event)
This method is called if your robot dies. |
void |
onHitByBullet(HitByBulletEvent event)
This method is called when your robot is hit by a bullet. |
void |
onHitRobot(HitRobotEvent event)
This method is called when your robot collides with another robot. |
void |
onHitWall(HitWallEvent event)
This method is called when your robot collides with a wall. |
void |
onPaint(java.awt.Graphics2D g)
This method is called every time the robot is painted. |
void |
onRobotDeath(RobotDeathEvent event)
This method is called when another robot dies. |
void |
onScannedRobot(ScannedRobotEvent event)
This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot. |
void |
onWin(WinEvent event)
This method is called if your robot wins a battle. |
void |
resume()
Immediately resumes the movement you stopped by stop(), if any. |
void |
run()
The main method in every robot. |
void |
scan()
Scans for other robots. |
void |
setAdjustGunForRobotTurn(boolean independent)
Sets the gun to turn independent from the robot's turn. |
void |
setAdjustRadarForGunTurn(boolean independent)
Sets the radar to turn independent from the gun's turn. |
void |
setAdjustRadarForRobotTurn(boolean independent)
Sets the radar to turn independent from the robot's turn. |
void |
setAllColors(java.awt.Color color)
Sets all the robot's color to the same color in the same time, i.e. the color of the body, gun, radar, bullet, and scan arc. |
void |
setBodyColor(java.awt.Color color)
Sets the color of the robot's body. |
void |
setBulletColor(java.awt.Color color)
Sets the color of the robot's bullets. |
void |
setColors(java.awt.Color bodyColor,
java.awt.Color gunColor,
java.awt.Color radarColor)
Sets the color of the robot's body, gun, and radar in the same time. |
void |
setColors(java.awt.Color bodyColor,
java.awt.Color gunColor,
java.awt.Color radarColor,
java.awt.Color bulletColor,
java.awt.Color scanColor)
Sets the color of the robot's body, gun, radar, bullet, and scan arc in the same time. |
void |
setGunColor(java.awt.Color color)
Sets the color of the robot's gun. |
void |
setRadarColor(java.awt.Color color)
Sets the color of the robot's radar. |
void |
setScanColor(java.awt.Color color)
Sets the color of the robot's scan arc. |
void |
stop()
Immediately stops all movement, and saves it for a call to resume(). |
void |
stop(boolean overwrite)
Immediately stops all movement, and saves it for a call to resume(). |
void |
turnGunLeft(double degrees)
Immediately turns the robot's gun to the left by degrees. |
void |
turnGunRight(double degrees)
Immediately turns the robot's gun to the right by degrees. |
void |
turnLeft(double degrees)
Immediately turns the robot's body to the left by degrees. |
void |
turnRadarLeft(double degrees)
Immediately turns the robot's radar to the left by degrees. |
void |
turnRadarRight(double degrees)
Immediately turns the robot's radar to the right by degrees. |
void |
turnRight(double degrees)
Immediately turns the robot's body to the right by degrees. |
Methods inherited from class robocode._Robot |
---|
getBattleNum, getGunCharge, getGunImageName, getLife, getNumBattles, getRadarImageName, getRobotImageName, setGunImageName, setInterruptible, setPeer, setRadarImageName, setRobotImageName, uninitializedException |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.io.PrintStream out
You can view the print-outs by clicking the button for your robot in the right side of the battle window.
Example:
// Print out a line each time my robot hits another robot public void onHitRobot(HitRobotEvent e) { out.println("I hit a robot! My energy: " + getEnergy() + " his energy: " + e.getEnergy()); }
Constructor Detail |
---|
public Robot()
Method Detail |
---|
public void ahead(double distance)
This call executes immediately, and does not return until it is complete, i.e. when the remaining distance to move is 0.
If the robot collides with a wall, the move is complete, meaning that the robot will not move any further. If the robot collides with another robot, the move is complete if you are heading toward the other robot.
Note that both positive and negative values can be given as input, where negative values means that the robot is set to move backward instead of forward.
Example:
// Move the robot 100 pixels forward ahead(100); // Afterwards, move the robot 50 pixels backward ahead(-50);
distance
- the distance to move ahead measured in pixels.
If this value is negative, the robot will move back instead of ahead.back(double)
,
onHitWall(robocode.HitWallEvent)
,
onHitRobot(robocode.HitRobotEvent)
public void back(double distance)
This call executes immediately, and does not return until it is complete, i.e. when the remaining distance to move is 0.
If the robot collides with a wall, the move is complete, meaning that the robot will not move any further. If the robot collides with another robot, the move is complete if you are heading toward the other robot.
Note that both positive and negative values can be given as input, where negative values means that the robot is set to move forward instead of backward.
Example:
// Move the robot 100 pixels backward back(100); // Afterwards, move the robot 50 pixels forward back(-50);
distance
- the distance to move back measured in pixels.
If this value is negative, the robot will move ahead instead of back.ahead(double)
,
onHitWall(robocode.HitWallEvent)
,
onHitRobot(robocode.HitRobotEvent)
public double getBattleFieldHeight()
public double getBattleFieldWidth()
public double getHeading()
Note that the heading in Robocode is like a compass, where 0 means North, 90 means East, 180 means South, and 270 means West.
public double getHeight()
getWidth()
public double getWidth()
getHeight()
public java.lang.String getName()
public double getX()
getY()
public double getY()
getX()
public void run()
Example:
// A basic robot that moves around in a square public void run() { while (true) { ahead(100); turnRight(90); } }
run
in interface java.lang.Runnable
public void turnLeft(double degrees)
This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the robot's turn is 0.
Note that both positive and negative values can be given as input, where negative values means that the robot's body is set to turn right instead of left.
Example:
// Turn the robot 180 degrees to the left turnLeft(180); // Afterwards, turn the robot 90 degrees to the right turnLeft(-90);
degrees
- the amount of degrees to turn the robot's body to the left
If this value is negative, the robot's body is set to turn to the rightpublic void turnRight(double degrees)
Note that both positive and negative values can be given as input, where negative values means that the robot's body is set to turn left instead of right.
Example:
// Turn the robot 180 degrees to the right turnRight(180); // Afterwards, turn the robot 90 degrees to the left turnRight(-90);
degrees
- the amount of degrees to turn the robot's body to the right
If this value is negative, the robot's body is set to turn to the leftpublic void doNothing()
This call executes immediately, and does not return until the turn is over.
public final void finalize()
finalize
in class java.lang.Object
public void fire(double power)
The specified bullet power is an amount of energy that will be taken from the robot's energy. Hence, the more power you want to spend on the bullet, the more energy is taken from your robot.
The bullet will do (4 * power) damage if it hits another robot. If power
is greater than 1, it will do an additional 2 * (power - 1) damage.
You will get (3 * power) back if you hit the other robot. You can call
Rules.getBulletDamage(double)
for getting the damage that a
bullet with a specific bullet power will do.
The specified bullet power should be between
Rules.MIN_BULLET_POWER
and Rules.MAX_BULLET_POWER
.
Note that the gun cannot fire if the gun is overheated, meaning that
getGunHeat()
returns a value > 0.
An event is generated when the bullet hits a robot, wall, or another bullet.
Example:
// Fire a bullet with maximum power if the gun is ready if (getGunHeat() == 0) { fire(Rules.MAX_BULLET_POWER); }
power
- the amount of energy given to the bullet, and subtracted
from the robot's energy.fireBullet(double)
,
getGunHeat()
,
getGunCoolingRate()
,
onBulletHit(robocode.BulletHitEvent)
,
onBulletHitBullet(robocode.BulletHitBulletEvent)
,
onBulletMissed(robocode.BulletMissedEvent)
public Bullet fireBullet(double power)
The specified bullet power is an amount of energy that will be taken from the robot's energy. Hence, the more power you want to spend on the bullet, the more energy is taken from your robot.
The bullet will do (4 * power) damage if it hits another robot. If power
is greater than 1, it will do an additional 2 * (power - 1) damage.
You will get (3 * power) back if you hit the other robot. You can call
Rules.getBulletDamage(double)
for getting the damage that a
bullet with a specific bullet power will do.
The specified bullet power should be between
Rules.MIN_BULLET_POWER
and Rules.MAX_BULLET_POWER
.
Note that the gun cannot fire if the gun is overheated, meaning that
getGunHeat()
returns a value > 0.
An event is generated when the bullet hits a robot, wall, or another bullet.
Example:
// Fire a bullet with maximum power if the gun is ready if (getGunHeat() == 0) { Bullet bullet = fireBullet(Rules.MAX_BULLET_POWER); // Get the velocity of the bullet double bulletVelocity = bullet.getVelocity(); }
power
- the amount of energy given to the bullet, and subtracted
from the robot's energy.
Bullet
that contains information about the bullet if it
was actually fired, which can be used for tracking the bullet after it
has been fired. If the bullet was not fired, null
is returned.fire(double)
,
Bullet
,
getGunHeat()
,
getGunCoolingRate()
,
onBulletHit(robocode.BulletHitEvent)
,
onBulletHitBullet(robocode.BulletHitBulletEvent)
,
onBulletMissed(robocode.BulletMissedEvent)
public double getGunCoolingRate()
The gun cooling rate is default 0.1 / turn, but can be changed by the battle setup. So don't count on the cooling rate being 0.1!
getGunHeat()
,
fire(double)
,
fireBullet(double)
public double getGunHeading()
Note that the heading in Robocode is like a compass, where 0 means North, 90 means East, 180 means South, and 270 means West.
public double getGunHeat()
The amount of gun heat generated when the gun is fired is
1 + (firePower / 5). Each turn the gun heat drops by the amount returned
by getGunCoolingRate()
, which is a battle setup.
Note that all guns are "hot" at the start of each round, where the gun heat is 3.
getGunCoolingRate()
,
fire(double)
,
fireBullet(double)
public int getNumRounds()
public int getOthers()
public double getRadarHeading()
Note that the heading in Robocode is like a compass, where 0 means North, 90 means East, 180 means South, and 270 means West.
public int getRoundNum()
getNumRounds()
- 1)
in the battle.
getNumRounds()
public long getTime()
A battle consists of multiple rounds.
Time is reset to 0 at the beginning of every round.
public double getVelocity()
The maximum velocity of a robot is defined by Rules.MAX_VELOCITY
(8 pixels / turn).
Rules.MAX_VELOCITY
public void onBulletHit(BulletHitEvent event)
Example:
public void onBulletHit(BulletHitEvent event) { out.println("I hit " + event.getName() + "!"); }
event
- the bullet-hit event set by the gameBulletHitEvent
,
Event
public void onBulletHitBullet(BulletHitBulletEvent event)
Example:
public void onBulletHitBullet(BulletHitBulletEvent event) { out.println("I hit a bullet fired by " + event.getBullet().getName() + "!"); }
event
- the bullet-hit-bullet event set by the gameBulletHitBulletEvent
,
Event
public void onBulletMissed(BulletMissedEvent event)
Example:
public void onBulletHit(BulletMissedEvent event) { out.println("Drat, I missed."); }
event
- the bullet-missed event set by the gameBulletMissedEvent
,
Event
public void onDeath(DeathEvent event)
You should override it in your robot if you want to be informed of this event. Actions will have no effect if called from this section. The intent is to allow you to perform calculations or print something out when the robot is killed.
event
- the death event set by the gameDeathEvent
,
Event
public void onHitByBullet(HitByBulletEvent event)
Example:
public void onHitByBullet(HitByBulletEvent event) { out.println(event.getRobotName() + " hit me!"); }
event
- the hit-by-bullet event set by the gameHitByBulletEvent
,
Event
public void onHitRobot(HitRobotEvent event)
Example:
public void onHitRobot(HitRobotEvent event) { if (event.getBearing() > -90 && event.getBearing() <= 90) { back(100); } else { ahead(100); } } -- or perhaps, for a more advanced robot -- public void onHitRobot(HitRobotEvent event) { if (event.getBearing() > -90 && event.getBearing() <= 90) { setBack(100); } else { setAhead(100); } }The angle is relative to your robot's facing. So 0 is straight ahead of you.
This event can be generated if another robot hits you, in which case
event.isMyFault()
will return
false
. In this case, you will not be automatically stopped by the
game -- but if you continue moving toward the robot you will hit it (and
generate another event). If you are moving away, then you won't hit it.
event
- the hit-robot event set by the gameHitRobotEvent
,
Event
public void onHitWall(HitWallEvent event)
The wall at the top of the screen is 0 degrees, right is 90 degrees, bottom is 180 degrees, left is 270 degrees. But this event is relative to your heading, so: The bearing is such that turnRight(e.getBearing()) will point you perpendicular to the wall.
Example:
public void onHitWall(HitWallEvent event) { out.println("Ouch, I hit a wall bearing " + event.getBearing() + " degrees."); }
event
- the hit-wall event set by the gameHitWallEvent
,
Event
public void onRobotDeath(RobotDeathEvent event)
event
- The robot-death event set by the gameRobotDeathEvent
,
Event
public void onScannedRobot(ScannedRobotEvent event)
This event is automatically called if there is a robot in range of your radar.
Note that the robot's radar can only see robot within the range defined
by Object.equals(Object)
(1200 pixels).
Also not that the bearing of the scanned robot is relative to your robot's heading.
Example:
public void onScannedRobot(ScannedRobotEvent event) { // Assuming radar and gun are aligned... if (event.getDistance() < 100) { fire(3); } else { fire(1); } }Note: The game assists Robots in firing, as follows: If the gun and radar are aligned (and were aligned last turn), and the event is current, and you call fire() before taking any other actions, fire() will fire directly at the robot. In essence, this means that if you can see a robot, and it doesn't move, then fire will hit it.
event
- the scanned-robot event set by the gamescan()
,
ScannedRobotEvent
,
Event
,
turnRadarLeft(double)
,
turnRadarRight(double)
public void onWin(WinEvent event)
Your robot could perform a victory dance here! :-)
event
- the win event set by the gameWinEvent
,
Event
public void resume()
This call executes immediately, and does not return until it is complete.
stop()
public void scan()
Scan will cause onScannedRobot
to be called if you see a robot.
There are 2 reasons to call scan() manually: 1 - You want to scan after you stop moving. 2 - You want to interrupt the onScannedRobot event. This is more likely. If you are in onScannedRobot, and call scan(), and you still see a robot, then the system will interrupt your onScannedRobot event immediately and start it from the top.
This call executes immediately.
onScannedRobot(robocode.ScannedRobotEvent)
,
ScannedRobotEvent
public void setAdjustGunForRobotTurn(boolean independent)
Ok, so this needs some explanation: The gun is mounted on the robot's body. So, normally, if the robot turns 90 degrees to the right, then the gun will turn with it as it is mounted on top of the robot's body. To compensate for this, you can call setAdjustGunForRobotTurn(true). When this is set, the gun will turn independent from the robot's turn, i.e. the gun will compensate for the robot's body turn.
Example, assuming both the robot and gun start out facing up (0 degrees):
// Set gun to turn with the robot's turn setAdjustGunForRobotTurn(false); // This is the default turnRight(90); // At this point, both the robot and gun are facing right (90 degrees) turnLeft(90); // Both are back to 0 degrees -- or -- // Set gun to turn independent from the robot's turn setAdjustGunForRobotTurn(true); turnRight(90); // At this point, the robot is facting right (90 degrees), but the gun is still facing up. turnLeft(90); // Both are back to 0 degrees.Note: The gun compensating this way does count as "turning the gun". See
setAdjustRadarForGunTurn(boolean)
for details.
independent
- @{code true} if the gun must turn independent from the
robot's turn; false
if the gun must turn with the robot's turn.setAdjustRadarForGunTurn(boolean)
public void setAdjustRadarForGunTurn(boolean independent)
Ok, so this needs some explanation: The radar is mounted on the robot's gun. So, normally, if the gun turns 90 degrees to the right, then the radar will turn with it as it is mounted on top of the gun. To compensate for this, you can call setAdjustRadarForGunTurn(true). When this is set, the radar will turn independent from the robot's turn, i.e. the radar will compensate for the gun's turn.
Example, assuming both the gun and radar start out facing up (0 degrees):
// Set radar to turn with the gun's turn setAdjustRadarForGunTurn(false); // This is the default turnGunRight(90); // At this point, both the radar and gun are facing right (90 degrees); -- or -- // Set radar to turn independent from the gun's turn setAdjustRadarForGunTurn(true); turnGunRight(90); // At this point, the gun is facing right (90 degrees), but the radar is still facing up.Note: Calling setAdjustRadarForGunTurn will automatically call
setAdjustRadarForRobotTurn(boolean)
with the same value, unless
you have already called it earlier. This behavior is primarily for
backward compatibility with older Robocode robots.
independent
- @{code true} if the radar must turn independent from
the gun's turn; false
if the radar must turn with the gun's
turn.setAdjustRadarForRobotTurn(boolean)
,
setAdjustGunForRobotTurn(boolean)
public void setColors(java.awt.Color bodyColor, java.awt.Color gunColor, java.awt.Color radarColor)
You may only call this method one time per battle. A null
indicates the default (blue-ish) color.
Example:
// Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setColors(null, Color.RED, new Color(150, 0, 150)); }
bodyColor
- the new body colorgunColor
- the new gun colorradarColor
- the new radar colorsetColors(Color, Color, Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setBodyColor(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setColors(java.awt.Color bodyColor, java.awt.Color gunColor, java.awt.Color radarColor, java.awt.Color bulletColor, java.awt.Color scanColor)
You may only call this method one time per battle. A null
indicates the default (blue-ish) color for the body, gun, radar, and scan
arc, but white for the bullet color.
Example:
// Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setColors(null, Color.RED, Color.GREEN, null, new Color(150, 0, 150)); }
bodyColor
- the new body colorgunColor
- the new gun colorradarColor
- the new radar colorbulletColor
- the new bullet colorscanColor
- the new scan colorsetColors(Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setBodyColor(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setAllColors(java.awt.Color color)
You may only call this method one time per battle. A null
indicates the default (blue-ish) color for the body, gun, radar, and scan
arc, but white for the bullet color.
Example: // Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setAllColors(Color.RED); }
color
- the new color for all the colors of the robotsetColors(Color, Color, Color)
,
setColors(Color, Color, Color, Color, Color)
,
setBodyColor(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setBodyColor(java.awt.Color color)
A null
indicates the default (blue-ish) color.
Example: // Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setBodyColor(Color.BLACK); }
color
- the new body colorsetColors(Color, Color, Color)
,
setColors(Color, Color, Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setGunColor(java.awt.Color color)
A null
indicates the default (blue-ish) color.
Example: // Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setGunColor(Color.RED); }
color
- the new gun colorsetColors(Color, Color, Color)
,
setColors(Color, Color, Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setBodyColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setRadarColor(java.awt.Color color)
A null
indicates the default (blue-ish) color.
Example: // Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setRadarColor(Color.YELLOW); }
color
- the new radar colorsetColors(Color, Color, Color)
,
setColors(Color, Color, Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setBodyColor(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setBulletColor(java.awt.Color color)
A null
indicates the default white color.
Example: // Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setBulletColor(Color.GREEN); }
color
- the new bullet colorsetColors(Color, Color, Color)
,
setColors(Color, Color, Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setBodyColor(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setScanColor(java.awt.Color)
,
Color
public void setScanColor(java.awt.Color color)
A null
indicates the default (blue-ish) color.
Example: // Don't forget to import java.awt.Color at the top... import java.awt.Color; ... public void run() { setScanColor(Color.WHITE); }
color
- the new scan arc colorsetColors(Color, Color, Color)
,
setColors(Color, Color, Color, Color, Color)
,
setAllColors(java.awt.Color)
,
setBodyColor(java.awt.Color)
,
setGunColor(java.awt.Color)
,
setRadarColor(java.awt.Color)
,
setBulletColor(java.awt.Color)
,
Color
public void stop()
This method is equivalent to stop(false).
resume()
,
stop(boolean)
public void stop(boolean overwrite)
resume()
,
stop()
public void turnGunLeft(double degrees)
This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the gun's turn is 0.
Note that both positive and negative values can be given as input, where negative values means that the robot's gun is set to turn right instead of left.
Example:
// Turn the robot's gun 180 degrees to the left turnGunLeft(180); // Afterwards, turn the robot's gun 90 degrees to the right turnGunLeft(-90);
degrees
- the amount of degrees to turn the robot's gun to the left
If this value is negative, the robot's gun is set to turn to the rightsetAdjustGunForRobotTurn(boolean)
public void turnGunRight(double degrees)
Note that both positive and negative values can be given as input, where negative values means that the robot's gun is set to turn left instead of right.
Example:
// Turn the robot's gun 180 degrees to the right turnGunRight(180); // Afterwards, turn the robot's gun 90 degrees to the left turnGunRight(-90);
degrees
- the amount of degrees to turn the robot's gun to the right
If this value is negative, the robot's gun is set to turn to the leftsetAdjustGunForRobotTurn(boolean)
public void turnRadarLeft(double degrees)
This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the radar's turn is 0.
Note that both positive and negative values can be given as input, where negative values means that the robot's radar is set to turn right instead of left.
Example:
// Turn the robot's radar 180 degrees to the left turnRadarLeft(180); // Afterwards, turn the robot's radar 90 degrees to the right turnRadarLeft(-90);
degrees
- the amount of degrees to turn the robot's radar to the left
If this value is negative, the robot's radar is set to turn to the rightsetAdjustRadarForRobotTurn(boolean)
,
setAdjustRadarForGunTurn(boolean)
public void turnRadarRight(double degrees)
Note that both positive and negative values can be given as input, where negative values means that the robot's radar is set to turn left instead of right.
Example:
// Turn the robot's radar 180 degrees to the right turnRadarRight(180); // Afterwards, turn the robot's radar 90 degrees to the left turnRadarRight(-90);
degrees
- the amount of degrees to turn the robot's radar to the right
If this value is negative, the robot's radar is set to turn to the leftsetAdjustRadarForRobotTurn(boolean)
,
setAdjustRadarForGunTurn(boolean)
public double getEnergy()
public void setAdjustRadarForRobotTurn(boolean independent)
Ok, so this needs some explanation: The radar is mounted on the gun, and the gun is mounted on the robot's body. So, normally, if the robot turns 90 degrees to the right, the gun turns, as does the radar. Hence, if the robot turns 90 degrees to the right, then the gun and radar will turn with it as the radar is mounted on top of the gun. To compensate for this, you can call setAdjustRadarForRobotTurn(true). When this is set, the radar will turn independent from the robot's turn, i.e. the radar will compensate for the robot's turn.
Example, assuming the robot, gun, and radar all start out facing up (0 degrees):
// Set radar to turn with the robots's turn setAdjustRadarForRobotTurn(false); // This is the default turnRight(90); // At this point, the body, gun, and radar are all facing right (90 degrees); -- or -- // Set radar to turn independent from the robot's turn setAdjustRadarForRobotTurn(true); turnRight(90); // At this point, the robot and gun are facing right (90 degrees), but the radar is still facing up.
independent
- @{code true} if the radar must turn independent from
the robots's turn; false
if the radar must turn with the robot's
turn.setAdjustGunForRobotTurn(boolean)
,
setAdjustRadarForGunTurn(boolean)
public void onPaint(java.awt.Graphics2D g)
This method is very useful for debugging your robot.
Note that the robot will only be painted if the "Paint" is enabled on the robot's console window; otherwise the robot will never get painted (the reason being that all robots might have graphical items that must be painted, and then you might not be able to tell what graphical items that have been painted for your robot).
Also note that the coordinate system for the graphical context where you paint items fits for the Robocode coordinate system where (0, 0) is at the buttom left corner of the battlefield, where X is towards right and Y is upwards.
g
- the graphics context to use for painting graphical items for the
robot
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |