Class HitByBulletEvent
- All Implemented Interfaces:
Serializable,Comparable<Event>
onHitByBullet() when your robot has been hit by a bullet.
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
ConstructorsConstructorDescriptionHitByBulletEvent(double bearing, Bullet bullet) Called by the game to create a new HitByBulletEvent. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the bearing to the bullet, relative to your robot's heading, in degrees (-180 invalid input: '<' getBearing() invalid input: '<'= 180).doubleReturns the bearing to the bullet, relative to your robot's heading, in radians (-Math.PI invalid input: '<' getBearingRadians() invalid input: '<'= Math.PI).Returns the bullet that hit your robot.doubleReturns the heading of the bullet when it hit you, in degrees (0 invalid input: '<'= getHeading() invalid input: '<' 360).doubleDeprecated.doubleReturns the heading of the bullet when it hit you, in radians (0 invalid input: '<'= getHeadingRadians() invalid input: '<' 2 * PI).getName()Returns the name of the robot that fired the bullet.doublegetPower()Returns the power of this bullet.doubleReturns the velocity of this bullet.Methods inherited from class robocode.Event
compareTo, getPriority, getTime, setPriority, setTime
-
Constructor Details
-
HitByBulletEvent
Called by the game to create a new HitByBulletEvent.- Parameters:
bearing- the bearing of the bullet that hit your robot, in radiansbullet- the bullet that has hit your robot
-
-
Method Details
-
getBearing
public double getBearing()Returns the bearing to the bullet, relative to your robot's heading, in degrees (-180 invalid input: '<' getBearing() invalid input: '<'= 180).If you were to turnRight(event.getBearing()), you would be facing the direction the bullet came from. The calculation used here is: (bullet's heading in degrees + 180) - (your heading in degrees)
- Returns:
- the bearing to the bullet, in degrees
-
getBearingRadians
public double getBearingRadians()Returns the bearing to the bullet, relative to your robot's heading, in radians (-Math.PI invalid input: '<' getBearingRadians() invalid input: '<'= Math.PI).If you were to turnRightRadians(event.getBearingRadians()), you would be facing the direction the bullet came from. The calculation used here is: (bullet's heading in radians + Math.PI) - (your heading in radians)
- Returns:
- the bearing to the bullet, in radians
-
getBullet
Returns the bullet that hit your robot.- Returns:
- the bullet that hit your robot
-
getHeading
public double getHeading()Returns the heading of the bullet when it hit you, in degrees (0 invalid input: '<'= getHeading() invalid input: '<' 360).Note: This is not relative to the direction you are facing. The robot that fired the bullet was in the opposite direction of getHeading() when it fired the bullet.
- Returns:
- the heading of the bullet, in degrees
-
getHeadingDegrees
Deprecated.UsegetHeading()instead.- Returns:
- the heading of the bullet, in degrees
-
getHeadingRadians
public double getHeadingRadians()Returns the heading of the bullet when it hit you, in radians (0 invalid input: '<'= getHeadingRadians() invalid input: '<' 2 * PI).Note: This is not relative to the direction you are facing. The robot that fired the bullet was in the opposite direction of getHeadingRadians() when it fired the bullet.
- Returns:
- the heading of the bullet, in radians
-
getName
Returns the name of the robot that fired the bullet.- Returns:
- the name of the robot that fired the bullet
-
getPower
public double getPower()Returns the power of this bullet. The damage you take (in fact, already took) is 4 * power, plus 2 * (power-1) if power > 1. The robot that fired the bullet receives 3 * power back.- Returns:
- the power of the bullet
-
getVelocity
public double getVelocity()Returns the velocity of this bullet.- Returns:
- the velocity of the bullet
-
getHeading()instead.