### robocode

# Class HitByBulletEvent

- `java.lang.Object`
- - `robocode.Event`
  - - `robocode.HitByBulletEvent`

Implemented Interfaces:
  Comparable, Serializable

`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)

  ## Constructor Summary

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

  ## Method Summary

  `@Deprecated`

  `double getHeadingDegrees()`
    Deprecated. Use `getHeading()` instead.

  `double`

  `getBearing()`
    Returns the bearing to the bullet, relative to your robot's heading, in degrees (-180 <32getBearing() <= 180)

    If you were to turnRight(e.getBearing()), you would be facing the direction the bullet came from.

  `double`

  `getBearingRadians()`
    Returns the bearing to the bullet, relative to your robot's heading, in radians (-Math.PI <32getBearingRadians() <= Math.PI)

    If you were to turnRightRadians(e.getBearingRadians()), you would be facing the direction the bullet came from.

  `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() <32360)

    Note: This is not relative to the direction you are facing.

  `double`

  `getHeadingRadians()`
    Returns the heading of the bullet when it hit you, in radians (0 <= getHeadingRadians() <322 * PI)

    Note: This is not relative to the direction you are facing.

  `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`

## Constructor Details

### 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 Details

### double getHeadingDegrees

    public @Deprecated double getHeadingDegrees()

> Deprecated. Use `getHeading()` instead.

> Returns:
>   the heading of the bullet, in degrees

### getBearing

    public double getBearing()

> Returns the bearing to the bullet, relative to your robot's heading, in degrees (-180 <32getBearing() <= 180)

> If you were to turnRight(e.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 <32getBearingRadians() <= Math.PI)

> If you were to turnRightRadians(e.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() <32360)

> 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

### getHeadingRadians

    public double getHeadingRadians()

> Returns the heading of the bullet when it hit you, in radians (0 <= getHeadingRadians() <322 * 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