public interface IBasicEvents
IBasicRobot
.IBasicRobot
Modifier and Type | Method and Description |
---|---|
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 |
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 |
onStatus(StatusEvent event)
This method is called every turn in a battle round in order to provide
the robot status as a complete snapshot of the robot's current state at
that specific time.
|
void |
onWin(WinEvent event)
This method is called if your robot wins a battle.
|
void onStatus(StatusEvent event)
The main benefit of this method is that you'll automatically receive all current data values of the robot like e.g. the x and y coordinate, heading, gun heat etc., which are grouped into the exact same time/turn.
This is the only way to map the robots data values to a specific time.
For example, it is not possible to determine the exact time of the
robot's heading by calling first calling Robot.getTime()
and then
Robot.getHeading()
afterwards, as the time might change
after between the Robot.getTime()
and Robot.getHeading()
call.
event
- the event containing the robot status at the time it occurred.StatusEvent
,
Event
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
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
void onBulletMissed(BulletMissedEvent event)
Example:
public void onBulletMissed(BulletMissedEvent event) { out.println("Drat, I missed."); }
event
- the bullet-missed event set by the gameBulletMissedEvent
,
Event
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
,
WinEvent
,
RoundEndedEvent
,
BattleEndedEvent
,
Event
void onHitByBullet(HitByBulletEvent event)
Example:
void onHitByBullet(HitByBulletEvent event) { out.println(event.getRobotName() + " hit me!"); }
event
- the hit-by-bullet event set by the gameHitByBulletEvent
,
Event
void onHitRobot(HitRobotEvent event)
Example:
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
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
(event.getBearing())
will
point you perpendicular to the wall.
Example:
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
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 Rules.RADAR_SCAN_RADIUS
(1200 pixels).
Also not that the bearing of the scanned robot is relative to your robot's heading.
Example:
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:
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.
AdvancedRobots will NOT be assisted in this manner, and are expected to
examine the event to determine if fire()
would
hit. (i.e. you are spinning your gun around, but by the time you get the
event, your gun is 5 degrees past the robot).
event
- the scanned-robot event set by the gameScannedRobotEvent
,
Event
,
Rules.RADAR_SCAN_RADIUS
void onRobotDeath(RobotDeathEvent event)
event
- The robot-death event set by the gameRobotDeathEvent
,
Event
void onWin(WinEvent event)
Your robot could perform a victory dance here! :-)
event
- the win event set by the gameDeathEvent
,
RoundEndedEvent
,
BattleEndedEvent
,
Event
Copyright © 2021 Robocode. All Rights Reserved.