Package robocode
Class HitRobotEvent
java.lang.Object
robocode.Event
robocode.HitRobotEvent
- All Implemented Interfaces:
Serializable
,Comparable<Event>
A HitRobotEvent is sent to
onHitRobot()
when your robot collides with another robot.
You can use the information contained in this event to determine what to do.- Author:
- Mathew A. Nelson (original), Flemming N. Larsen (contributor)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHitRobotEvent
(String name, double bearing, double energy, boolean atFault) Called by the game to create a new HitRobotEvent. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Compares this event to another event regarding precedence.double
Returns the bearing to the robot you hit, relative to your robot's heading, in degrees (-180 <= getBearing() < 180)double
Deprecated.double
Returns the bearing to the robot you hit, relative to your robot's heading, in radians (-PI <= getBearingRadians() < PI)double
Returns the amount of energy of the robot you hit.getName()
Returns the name of the robot you hit.Deprecated.UsegetName()
instead.boolean
Checks if your robot was moving towards the robot that was hit.Methods inherited from class robocode.Event
getPriority, getTime, setPriority, setTime
-
Constructor Details
-
HitRobotEvent
Called by the game to create a new HitRobotEvent.- Parameters:
name
- the name of the robot you hitbearing
- the bearing to the robot that your robot hit, in radiansenergy
- the amount of energy of the robot you hitatFault
-true
if your robot was moving toward the other robot;false
otherwise
-
-
Method Details
-
getBearing
public double getBearing()Returns the bearing to the robot you hit, relative to your robot's heading, in degrees (-180 <= getBearing() < 180)- Returns:
- the bearing to the robot you hit, in degrees
-
getBearingDegrees
Deprecated.UsegetBearing()
instead.- Returns:
- the bearing to the robot you hit, in degrees
-
getBearingRadians
public double getBearingRadians()Returns the bearing to the robot you hit, relative to your robot's heading, in radians (-PI <= getBearingRadians() < PI)- Returns:
- the bearing to the robot you hit, in radians
-
getEnergy
public double getEnergy()Returns the amount of energy of the robot you hit.- Returns:
- the amount of energy of the robot you hit
-
getName
Returns the name of the robot you hit.- Returns:
- the name of the robot you hit
-
getRobotName
Deprecated.UsegetName()
instead.- Returns:
- the name of the robot you hit
-
isMyFault
public boolean isMyFault()Checks if your robot was moving towards the robot that was hit.If
isMyFault()
returnstrue
then your robot's movement (including turning) will have stopped and been marked complete.Note: If two robots are moving toward each other and collide, they will each receive two HitRobotEvents. The first will be the one if
isMyFault()
returnstrue
.- Returns:
true
if your robot was moving towards the robot that was hit;false
otherwise.
-
compareTo
Compares this event to another event regarding precedence. The event precedence is first and foremost determined by the event time, secondly the event priority, and lastly specific event information.This method will first compare the time of each event. If the event time is the same for both events, then this method compared the priority of each event. If the event priorities are equals, then this method will compare the two event based on specific event information.
This method is called by the game in order to sort the event queue of a robot to make sure the events are listed in chronological order.
- Specified by:
compareTo
in interfaceComparable<Event>
- Overrides:
compareTo
in classEvent
- Parameters:
event
- the event to compare to this event.- Returns:
- a negative value if this event has higher precedence, i.e. must be listed before the specified event. A positive value if this event has a lower precedence, i.e. must be listed after the specified event. 0 means that the precedence of the two events are equal.
-
getBearing()
instead.