Package robocode
Class Bullet
- java.lang.Object
-
- robocode.Bullet
-
- All Implemented Interfaces:
java.io.Serializable
public class Bullet extends java.lang.Object implements java.io.SerializableRepresents a bullet. This is returned fromRobot.fireBullet(double)andAdvancedRobot.setFireBullet(double), and all the bullet-related events.- Author:
- Mathew A. Nelson (original), Flemming N. Larsen (contributor)
- See Also:
Robot.fireBullet(double),AdvancedRobot.setFireBullet(double),BulletHitEvent,BulletMissedEvent,BulletHitBulletEvent, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Bullet(double heading, double x, double y, double power, java.lang.String ownerName, java.lang.String victimName, boolean isActive, int bulletId)Called by the game to create a newBulletobject
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)doublegetHeading()Returns the direction the bullet is/was heading, in degrees (0 <= getHeading() < 360).doublegetHeadingRadians()Returns the direction the bullet is/was heading, in radians (0 <= getHeadingRadians() < 2 * Math.PI).java.lang.StringgetName()Returns the name of the robot that fired this bullet.doublegetPower()Returns the power of this bullet.doublegetVelocity()Returns the velocity of this bullet.java.lang.StringgetVictim()Returns the name of the robot that this bullet hit, ornullif the bullet has not hit a robot.doublegetX()Returns the X position of the bullet.doublegetY()Returns the Y position of the bullet.inthashCode()booleanisActive()Checks if this bullet is still active on the battlefield.
-
-
-
Constructor Detail
-
Bullet
public Bullet(double heading, double x, double y, double power, java.lang.String ownerName, java.lang.String victimName, boolean isActive, int bulletId)Called by the game to create a newBulletobject- Parameters:
heading- the heading of the bullet, in radians.x- the starting X position of the bullet.y- the starting Y position of the bullet.power- the power of the bullet.ownerName- the name of the owner robot that owns the bullet.victimName- the name of the robot hit by the bullet.isActive-trueif the bullet still moves;falseotherwise.bulletId- unique id of bullet for owner robot.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getHeading
public double getHeading()
Returns the direction the bullet is/was heading, in degrees (0 <= getHeading() < 360). This is not relative to the direction you are facing.- Returns:
- the direction the bullet is/was heading, in degrees
-
getHeadingRadians
public double getHeadingRadians()
Returns the direction the bullet is/was heading, in radians (0 <= getHeadingRadians() < 2 * Math.PI). This is not relative to the direction you are facing.- Returns:
- the direction the bullet is/was heading, in radians
-
getName
public java.lang.String getName()
Returns the name of the robot that fired this bullet.- Returns:
- the name of the robot that fired this bullet
-
getPower
public double getPower()
Returns the power of this bullet.The bullet will do (4 * power) damage if it hits another robot. If power is greater than 1, it will do an additional 2 * (power - 1) damage. You will get (3 * power) back if you hit the other robot.
- Returns:
- the power of the bullet
-
getVelocity
public double getVelocity()
Returns the velocity of this bullet. The velocity of the bullet is constant once it has been fired.- Returns:
- the velocity of the bullet
-
getVictim
public java.lang.String getVictim()
Returns the name of the robot that this bullet hit, ornullif the bullet has not hit a robot.- Returns:
- the name of the robot that this bullet hit, or
nullif the bullet has not hit a robot.
-
getX
public double getX()
Returns the X position of the bullet.- Returns:
- the X position of the bullet
-
getY
public double getY()
Returns the Y position of the bullet.- Returns:
- the Y position of the bullet
-
isActive
public boolean isActive()
Checks if this bullet is still active on the battlefield.- Returns:
trueif the bullet is still active on the battlefield;falseotherwise
-
-