robocode
Class HitByBulletEvent

java.lang.Object
  extended by robocode.Event
      extended by robocode.HitByBulletEvent
All Implemented Interfaces:
Serializable, Comparable<Event>

public final class HitByBulletEvent
extends Event

A HitByBulletEvent is sent to 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:
Serialized Form

Constructor Summary
HitByBulletEvent(double bearing, Bullet bullet)
          Called by the game to create a new HitByBulletEvent.
 
Method Summary
 double getBearing()
          Returns the bearing to the bullet, relative to your robot's heading, in degrees (-180 < getBearing() <= 180).
 double getBearingRadians()
          Returns the bearing to the bullet, relative to your robot's heading, in radians (-Math.PI < getBearingRadians() <= Math.PI).
 Bullet getBullet()
          Returns the bullet that hit your robot.
 double getHeading()
          Returns the heading of the bullet when it hit you, in degrees (0 <= getHeading() < 360).
 double getHeadingDegrees()
          Deprecated. Use getHeading() instead.
 double getHeadingRadians()
          Returns the heading of the bullet when it hit you, in radians (0 <= getHeadingRadians() < 2 * PI).
 String getName()
          Returns the name of the robot that fired the bullet.
 double getPower()
          Returns the power of this bullet.
 double getVelocity()
          Returns the velocity of this bullet.
 
Methods inherited from class robocode.Event
compareTo, getPriority, getTime, setPriority, setTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HitByBulletEvent

public HitByBulletEvent(double bearing,
                        Bullet bullet)
Called by the game to create a new HitByBulletEvent.

Parameters:
bearing - the bearing of the bullet that hit your robot, in radians
bullet - the bullet that has hit your robot
Method Detail

getBearing

public double getBearing()
Returns the bearing to the bullet, relative to your robot's heading, in degrees (-180 < getBearing() <= 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 < getBearingRadians() <= 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

public Bullet 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 <= getHeading() < 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
public double getHeadingDegrees()
Deprecated. Use getHeading() 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 <= getHeadingRadians() < 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

public String 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


Copyright © 2013 Robocode. All Rights Reserved.