client
Class UserDefinedClient

java.lang.Object
  |
  +--client.UserDefinedClient

public class UserDefinedClient
extends java.lang.Object

A class that may be subclassed to create robot clients, or clients that extend the player's capabilities.

The class provides several kinds of methods, some of which must be overridden to have any effect:

Updater
The updater is called by the main client several times a second. This method should be overridden to provide the main logic of the new client. There is no need to call the super method, as it's empty.
Callbacks
There are three kinds of callbacks: One lets you draw on the game board, some provide information from the game server, while others give information on how the user interacts with the client. The callbacks are all empty methods by default, and may be overridden on demand without calling the super method.
Action Methods
These methods make this client's player do something, like moving, fireing, and sending chat messages.
Display Handling
Provide (at the moment limited) access to the game display.
Game Queries
Methods for finding enemies, weapons, etc. Queries on single entities are not found here. Such queries must be directed to the object in question, thru the objects package.
Convenience Methods
Not directly connected to the game, these methods provide calculation of distances, angles, optimal turn direction, etc.
It is not possible to create advanced clients without diving into the objects package, that provide information on players, weapons, etc.

Author:
Sverre H. Huseby <shh@thathost.com>

Field Summary
static int MAX_BOMB_SPEED
          Maximum bomb speed in pixels per second.
static int MAX_PHASER_SPEED
          Maximum phaser shot speed in pixels per second.
static int MAX_SHIP_SPEED
          Maximum player/ship speed in pixels per second.
static int TURN_LEFT
          getBestTurn advices you to turn left.
static int TURN_NONE
          getBestTurn advices you to not turn.
static int TURN_RIGHT
          getBestTurn advices you to turn right.
 
Constructor Summary
UserDefinedClient()
          NOTE: Your constructor should not call any of the methods in this class, as things have not been set up yet.
 
Method Summary
protected  void annotateBoardImage(java.awt.Graphics g)
          Lets you draw on the game board.
 void fireBomb()
          Fires a targeting bomb.
 void firePhaser()
          Fires a phaser shot.
 double getAbsDeltaAngle(double angle1, double angle2)
          Calculates the smallest angle between two given angles, without taking care of direction.
 double getAngle(DrawableGameObject o)
          Calculates the angle in radians of a vector from our ship to the given object.
 double getAngle(int fromX, int fromY, int toX, int toY)
          Calculates the angle in radians from one point to another.
 int getBestTurn(double oldAngle, double newAngle)
          Finds the best way to turn to move from one direction to another.
 BombPack[] getBombPacks()
          Gets all currently available bomb packs.
 Bomb[] getBombs()
          Gets all currently moving bombs, including our own.
 BombPack getClosestBombPack()
          Finds the closest bomb pack.
 BombPack getClosestBombPack(int myX, int myY)
          Finds the closest bomb pack.
 Player getClosestEnemy()
          Finds the closest enemy player that is alive.
 Player getClosestEnemy(int myX, int myY)
          Finds the closest enemy player that is alive.
 Bomb getClosestEnemyBomb()
          Finds the closest enemy bomb.
 Bomb getClosestEnemyBomb(int myX, int myY)
          Finds the closest enemy bomb.
 Phaser getClosestEnemyPhaser()
          Finds the closest enemy phaser.
 Phaser getClosestEnemyPhaser(int myX, int myY)
          Finds the closest enemy phaser shot.
 double getDeltaAngle(double fromAngle, double toAngle)
          Calculates the smallest angle from one angle to another.
 int getDistanceBetween(DrawableGameObject o1, DrawableGameObject o2)
          Calculates the pixel distance between two objects.
 int getDistanceBetween(DrawableGameObject o, int x, int y)
          Calculates the pixel distance between an objects and a given location.
 int getDistanceBetween(int x0, int y0, int x1, int y1)
          Calculates the pixel distance between two points.
 java.awt.Component getGameComponent()
          Returns the AWT Component that functions as the game are of the window.
 Player getMyPlayer()
          Returns the player controlled by this client.
 double getNormalizedAngle(double angle)
          Makes sure an angle is within the interval 0.0 to 2PI.
 Phaser[] getPhasers()
          Gets all currently moving phasers, including our own.
 Player[] getPlayers()
          Gets all available players, including our own, and including dead ones.
 int getSquareDistanceBetween(DrawableGameObject o1, DrawableGameObject o2)
          Calculates the squared pixel distance between two objects.
 int getSquareDistanceBetween(DrawableGameObject o, int x, int y)
          Calculates the squared pixel distance between an object and a given location.
 int getSquareDistanceBetween(int x0, int y0, int x1, int y1)
          Calculates the squared pixel distance between two points.
 int getUpdateFrequency()
          Returns the number of times per second that the update method is called.
 int getVisibleHeight()
          Returns the height of the current visible display are.
 int getVisibleOffsetX()
          Gets the horizontal offset into the world of the area currently visible in the game window.
 int getVisibleOffsetY()
          Gets the vertical offset into the world of the area currently visible in the game window.
 int getVisibleWidth()
          Returns the width of the current visible display are.
 int getWorldHeight()
          Returns the height of the entire playing area.
 int getWorldWidth()
          Returns the width of the entire playing area.
protected  void infoBombCreated(Bomb bomb)
          Informs that a new targetting bomb has been created.
protected  void infoBombDestroyed(Bomb bomb)
          Informs that a targetting bomb has been removed, either because it ran out of fuel, or because it hit something.
protected  void infoBombMoved(Bomb bomb)
          Informs that a targetting bomb has moved to a new location.
protected  void infoBombPackCreated(BombPack bombPack)
          Informs that someone has lost their weapons somewhere.
protected  void infoBombPackDestroyed(BombPack bombPack)
          Informs that a bomb pack has been removed, probably because it was picked up by someone.
protected  void infoBombPackMoved(BombPack bombPack)
          Informs that a bomb pack has moved.
protected  void infoLoggedIntoServer()
          Informs that the client has successfully logged into the server.
protected  void infoManualFireBomb()
          Informs that the user has fired the bomb.
protected  void infoManualFirePhaser()
          Informs that the user has fired the phaser.
protected  void infoManualStartMovingBack()
          Informs that the user started to move backward.
protected  void infoManualStartMovingForeward()
          Informs that the user started to move foreward.
protected  void infoManualStartTurningLeft()
          Informs that the user started to turn left.
protected  void infoManualStartTurningRight()
          Informs that the user started to turn right.
protected  void infoManualStopMovingBack()
          Informs that the user stopped moving backward.
protected  void infoManualStopMovingForeward()
          Informs that the user stopped moving foreward.
protected  void infoManualStopTurningLeft()
          Informs that the user stopped turning left.
protected  void infoManualStopTurningRight()
          Informs that the user stopped turning right.
protected  void infoPhaserCreated(Phaser phaser)
          Informs that a new phaser shot has been created.
protected  void infoPhaserDestroyed(Phaser phaser)
          Informs that a phaser has been removed.
protected  void infoPhaserMoved(Phaser phaser)
          Informs that a phaser has moved a small distance.
protected  void infoPlayerDied(Player player, Player killer, byte weapon)
          Informs that a player has been killed.
protected  void infoPlayerEntered(Player player)
          Informs that a new player has entered the game.
protected  void infoPlayerHit(Player player, Player hitter, byte weapon)
          Informs that a player has been hit by some weapon, without necessarily being killed.
protected  void infoPlayerLeft(Player player)
          Informs that a player has left the game.
protected  void infoPlayerMoved(Player player)
          Informs that a player has moved or changed direction.
protected  void infoPlayerResurrected(Player player)
          Informs that a player has resurrected from the dead.
protected  void infoPlayerSaidSomething(Player player, java.lang.String message)
          Informs that a player has sent a global chat message.
protected  void infoUnhandeledKeyPressed(int code)
          Informs that the user has pressed a key that has no normal function in the game.
protected  void infoUnhandeledKeyReleased(int code)
          Informs that the user has released a key that has no normal function in the game.
 boolean isBehind(DrawableGameObject o)
          Checks if the given object is behind our ship.
 boolean isInFront(DrawableGameObject o)
          Checks if the given object is in front of our ship.
 boolean isToTheLeft(DrawableGameObject o)
          Checks if the given object is to the left of our ship.
 boolean isToTheRight(DrawableGameObject o)
          Checks if the given object is to the right of our ship.
 void say(java.lang.String message)
          Sends a message to all the players.
 void setAutoResurrect(boolean status)
          Instructs the main client code to autimatically resurrect (bring back to life) after being killed.
 void setName(java.lang.String name)
          Sets new name for our player.
 void showMessage(java.lang.String message)
          Displays a message on the game board.
 void startMovingBack()
          Starts moving the ship backward.
 void startMovingForeward()
          Starts moving the ship foreward.
 void startTurningLeft()
          Starts turning the ship to the left.
 void startTurningRight()
          Starts turning the ship to the right.
 void stopMoving()
          Stops all foreward/backward movement of the ship.
 void stopMovingBack()
          Stops backward movement of the ship.
 void stopMovingForeward()
          Stops foreward movement of the ship.
 void stopTurning()
          Stops any turning of the ship.
 void stopTurningLeft()
          Stops leftward movement of the ship.
 void stopTurningRight()
          Stops rightward movement of the ship.
protected  void update()
          Updates the client logic at regular intervals.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TURN_NONE

public static final int TURN_NONE
getBestTurn advices you to not turn.

See Also:
Constant Field Values

TURN_LEFT

public static final int TURN_LEFT
getBestTurn advices you to turn left.

See Also:
Constant Field Values

TURN_RIGHT

public static final int TURN_RIGHT
getBestTurn advices you to turn right.

See Also:
Constant Field Values

MAX_PHASER_SPEED

public static final int MAX_PHASER_SPEED
Maximum phaser shot speed in pixels per second.

See Also:
Constant Field Values

MAX_BOMB_SPEED

public static final int MAX_BOMB_SPEED
Maximum bomb speed in pixels per second.

See Also:
Constant Field Values

MAX_SHIP_SPEED

public static final int MAX_SHIP_SPEED
Maximum player/ship speed in pixels per second.

See Also:
Constant Field Values
Constructor Detail

UserDefinedClient

public UserDefinedClient()
NOTE: Your constructor should not call any of the methods in this class, as things have not been set up yet.

Method Detail

update

protected void update()
Updates the client logic at regular intervals.

If you override this, there's no need to call the super method.


annotateBoardImage

protected void annotateBoardImage(java.awt.Graphics g)
Lets you draw on the game board. The graphic context provided is connected to an image that has size equal to the entire world. You may thus use world coordinates when drawing.

If you override this, there's no need to call the super method.

Parameters:
g - the graphic context.

infoLoggedIntoServer

protected void infoLoggedIntoServer()
Informs that the client has successfully logged into the server. When this method is called, everything is set up, and ready to be used, including info on other players.

If you override this, there's no need to call the super method.


infoPlayerEntered

protected void infoPlayerEntered(Player player)
Informs that a new player has entered the game.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
See Also:
Player

infoPlayerLeft

protected void infoPlayerLeft(Player player)
Informs that a player has left the game.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
See Also:
Player

infoPlayerMoved

protected void infoPlayerMoved(Player player)
Informs that a player has moved or changed direction.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
See Also:
Player

infoPlayerHit

protected void infoPlayerHit(Player player,
                             Player hitter,
                             byte weapon)
Informs that a player has been hit by some weapon, without necessarily being killed. If the player dies from the hit, this call is followed by a call to infoPlayerDied.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
hitter - the player who's weapon hit the first player.
weapon - the weapon type, as found in objects.WeaponType.
See Also:
Player, WeaponType

infoPlayerDied

protected void infoPlayerDied(Player player,
                              Player killer,
                              byte weapon)
Informs that a player has been killed.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
weapon - the weapon type, as found in objects.WeaponType.
See Also:
Player, WeaponType

infoPlayerResurrected

protected void infoPlayerResurrected(Player player)
Informs that a player has resurrected from the dead.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
See Also:
Player

infoPlayerSaidSomething

protected void infoPlayerSaidSomething(Player player,
                                       java.lang.String message)
Informs that a player has sent a global chat message.

If you override this, there's no need to call the super method.

Parameters:
player - the player, which may include the client's own player.
message - the message sent by the player.
See Also:
Player

infoPhaserCreated

protected void infoPhaserCreated(Phaser phaser)
Informs that a new phaser shot has been created.

If you override this, there's no need to call the super method.

Parameters:
phaser - the phaser shot.
See Also:
Phaser

infoPhaserMoved

protected void infoPhaserMoved(Phaser phaser)
Informs that a phaser has moved a small distance.

If you override this, there's no need to call the super method.

Parameters:
phaser - the phaser shot.
See Also:
Phaser

infoPhaserDestroyed

protected void infoPhaserDestroyed(Phaser phaser)
Informs that a phaser has been removed.

If you override this, there's no need to call the super method.

Parameters:
phaser - the phaser shot.
See Also:
Phaser

infoBombCreated

protected void infoBombCreated(Bomb bomb)
Informs that a new targetting bomb has been created.

If you override this, there's no need to call the super method.

Parameters:
bomb - the bomb.
See Also:
Bomb

infoBombMoved

protected void infoBombMoved(Bomb bomb)
Informs that a targetting bomb has moved to a new location.

If you override this, there's no need to call the super method.

Parameters:
bomb - the bomb.
See Also:
Bomb

infoBombDestroyed

protected void infoBombDestroyed(Bomb bomb)
Informs that a targetting bomb has been removed, either because it ran out of fuel, or because it hit something.

If you override this, there's no need to call the super method.

Parameters:
bomb - the bomb.
See Also:
Bomb

infoBombPackCreated

protected void infoBombPackCreated(BombPack bombPack)
Informs that someone has lost their weapons somewhere.

If you override this, there's no need to call the super method.

Parameters:
bombPack - the bomb pack.
See Also:
BombPack

infoBombPackMoved

protected void infoBombPackMoved(BombPack bombPack)
Informs that a bomb pack has moved.

If you override this, there's no need to call the super method.

Parameters:
bombPack - the bomb pack.
See Also:
BombPack

infoBombPackDestroyed

protected void infoBombPackDestroyed(BombPack bombPack)
Informs that a bomb pack has been removed, probably because it was picked up by someone.

If you override this, there's no need to call the super method.

Parameters:
bombPack - the bomb pack.
See Also:
BombPack

infoUnhandeledKeyPressed

protected void infoUnhandeledKeyPressed(int code)
Informs that the user has pressed a key that has no normal function in the game.

If you override this, there's no need to call the super method.

Parameters:
code - the result from java.awt.event.KeyEvent.getKeyCode().
See Also:
KeyEvent

infoUnhandeledKeyReleased

protected void infoUnhandeledKeyReleased(int code)
Informs that the user has released a key that has no normal function in the game.

If you override this, there's no need to call the super method.

Parameters:
code - the result from java.awt.event.KeyEvent.getKeyCode().
See Also:
KeyEvent

infoManualStartTurningLeft

protected void infoManualStartTurningLeft()
Informs that the user started to turn left. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStopTurningLeft

protected void infoManualStopTurningLeft()
Informs that the user stopped turning left. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStartTurningRight

protected void infoManualStartTurningRight()
Informs that the user started to turn right. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStopTurningRight

protected void infoManualStopTurningRight()
Informs that the user stopped turning right. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStartMovingForeward

protected void infoManualStartMovingForeward()
Informs that the user started to move foreward. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStopMovingForeward

protected void infoManualStopMovingForeward()
Informs that the user stopped moving foreward. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStartMovingBack

protected void infoManualStartMovingBack()
Informs that the user started to move backward. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualStopMovingBack

protected void infoManualStopMovingBack()
Informs that the user stopped moving backward. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualFirePhaser

protected void infoManualFirePhaser()
Informs that the user has fired the phaser. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


infoManualFireBomb

protected void infoManualFireBomb()
Informs that the user has fired the bomb. This information may be useful if you want your client to avoid interfering with the user's actions.

If you override this, there's no need to call the super method.


startTurningLeft

public final void startTurningLeft()
Starts turning the ship to the left. The ship will continue to turn left untill told to stop the movement in this direction, or untill told to move in the opposite direction.


stopTurningLeft

public final void stopTurningLeft()
Stops leftward movement of the ship.


startTurningRight

public final void startTurningRight()
Starts turning the ship to the right. The ship will continue to turn right untill told to stop the movement in this direction, or untill told to move in the opposite direction.


stopTurningRight

public final void stopTurningRight()
Stops rightward movement of the ship.


stopTurning

public final void stopTurning()
Stops any turning of the ship.


startMovingForeward

public final void startMovingForeward()
Starts moving the ship foreward. The ship will continue to move foreward untill told to stop the movement in this direction, or untill told to move in the opposite direction.


stopMovingForeward

public final void stopMovingForeward()
Stops foreward movement of the ship.


startMovingBack

public final void startMovingBack()
Starts moving the ship backward. The ship will continue to move backward untill told to stop the movement in this direction, or untill told to move in the opposite direction.


stopMovingBack

public final void stopMovingBack()
Stops backward movement of the ship.


stopMoving

public final void stopMoving()
Stops all foreward/backward movement of the ship.


firePhaser

public final void firePhaser()
Fires a phaser shot. Note that the server may ignore our demand, so you should not rely on it being performed untill you are told using one of the callbacks.


fireBomb

public final void fireBomb()
Fires a targeting bomb. Note that the server may ignore our demand, so you should not rely on it being performed untill you are told using one of the callbacks.


say

public final void say(java.lang.String message)
Sends a message to all the players.

Parameters:
message - the message to send.

setName

public final void setName(java.lang.String name)
Sets new name for our player. The name is not stored in SpaceGame's settings file.

Parameters:
name - the new name.

setAutoResurrect

public final void setAutoResurrect(boolean status)
Instructs the main client code to autimatically resurrect (bring back to life) after being killed.

Parameters:
status - true to turn on, false to turn off.

showMessage

public final void showMessage(java.lang.String message)
Displays a message on the game board. This is a local message, that may be used to inform the user of any action taken.

Parameters:
message - the message to display.

getGameComponent

public final java.awt.Component getGameComponent()
Returns the AWT Component that functions as the game are of the window. May be used for capturing mouse events, etc.

Returns:
the component.

getVisibleOffsetX

public final int getVisibleOffsetX()
Gets the horizontal offset into the world of the area currently visible in the game window.

Returns:
the horizontal offset.

getVisibleOffsetY

public final int getVisibleOffsetY()
Gets the vertical offset into the world of the area currently visible in the game window.

Returns:
the vertical offset.

getWorldWidth

public final int getWorldWidth()
Returns the width of the entire playing area.

Returns:
the width of the world in pixels.

getWorldHeight

public final int getWorldHeight()
Returns the height of the entire playing area.

Returns:
the height of the world in pixels.

getVisibleWidth

public final int getVisibleWidth()
Returns the width of the current visible display are.

Returns:
the width in pixels.

getVisibleHeight

public final int getVisibleHeight()
Returns the height of the current visible display are.

Returns:
the height in pixels.

getClosestEnemy

public final Player getClosestEnemy(int myX,
                                    int myY)
Finds the closest enemy player that is alive. This method compares locations against a given point, that possibly lays outside our client's ship location.

Parameters:
myX - x-coordinate to compare to.
myY - y-coordinate to compare to.
Returns:
the object found, or null if no other players are present.
See Also:
Player

getClosestEnemy

public final Player getClosestEnemy()
Finds the closest enemy player that is alive. This method compares according to the location of your client's player.

Returns:
the object found, or null if no other players are present.
See Also:
Player

getClosestEnemyBomb

public final Bomb getClosestEnemyBomb(int myX,
                                      int myY)
Finds the closest enemy bomb. This method compares locations against a given point, that possibly lays outside our client's ship location.

Parameters:
myX - x-coordinate to compare to.
myY - y-coordinate to compare to.
Returns:
the object found, or null if no bombs owned by other players are present.
See Also:
Bomb

getClosestEnemyBomb

public final Bomb getClosestEnemyBomb()
Finds the closest enemy bomb. This method compares according to the location of your client's player.

Returns:
the object found, or null if no bombs owned by other players are present.
See Also:
Bomb

getClosestEnemyPhaser

public final Phaser getClosestEnemyPhaser(int myX,
                                          int myY)
Finds the closest enemy phaser shot. This method compares locations against a given point, that possibly lays outside our client's ship location.

Parameters:
myX - x-coordinate to compare to.
myY - y-coordinate to compare to.
Returns:
the object found, or null if no phasers owned by other players are present.
See Also:
Phaser

getClosestEnemyPhaser

public final Phaser getClosestEnemyPhaser()
Finds the closest enemy phaser. This method compares according to the location of your client's player.

Returns:
the object found, or null if no phasers owned by other players are present.
See Also:
Phaser

getClosestBombPack

public final BombPack getClosestBombPack(int myX,
                                         int myY)
Finds the closest bomb pack. This method compares locations against a given point, that possibly lays outside our client's ship location.

Parameters:
myX - x-coordinate to compare to.
myY - y-coordinate to compare to.
Returns:
the object found, or null if no bomb packs are present.
See Also:
BombPack

getClosestBombPack

public final BombPack getClosestBombPack()
Finds the closest bomb pack. This method compares according to the location of your client's player.

Returns:
the object found, or null if no bomb packs are present.
See Also:
BombPack

getMyPlayer

public final Player getMyPlayer()
Returns the player controlled by this client.

Returns:
our Player-object.
See Also:
Player

getPlayers

public final Player[] getPlayers()
Gets all available players, including our own, and including dead ones.

Returns:
an array of Player-objects.
See Also:
Player

getPhasers

public final Phaser[] getPhasers()
Gets all currently moving phasers, including our own.

Returns:
an array of Phaser-objects.
See Also:
Phaser

getBombs

public final Bomb[] getBombs()
Gets all currently moving bombs, including our own.

Returns:
an array of Bomb-objects.
See Also:
Bomb

getBombPacks

public final BombPack[] getBombPacks()
Gets all currently available bomb packs.

Returns:
an array of BombPack-objects.
See Also:
BombPack

getSquareDistanceBetween

public final int getSquareDistanceBetween(DrawableGameObject o1,
                                          DrawableGameObject o2)
Calculates the squared pixel distance between two objects. May be used for comparing distances, as it is faster than the method that calculates the real distance.

Parameters:
o1 - one object.
o2 - another object.
Returns:
the squared pixel distance.
See Also:
DrawableGameObject

getDistanceBetween

public final int getDistanceBetween(DrawableGameObject o1,
                                    DrawableGameObject o2)
Calculates the pixel distance between two objects.

Parameters:
o1 - one object.
o2 - another object.
Returns:
the pixel distance.
See Also:
DrawableGameObject

getSquareDistanceBetween

public final int getSquareDistanceBetween(DrawableGameObject o,
                                          int x,
                                          int y)
Calculates the squared pixel distance between an object and a given location. May be used for comparing distances, as it is faster than the method that calculates the real distance.

Parameters:
x - an x-coordinate.
y - a y-coordinate.
Returns:
the squared pixel distance.
See Also:
DrawableGameObject

getDistanceBetween

public final int getDistanceBetween(DrawableGameObject o,
                                    int x,
                                    int y)
Calculates the pixel distance between an objects and a given location.

Parameters:
x - an x-coordinate.
y - a y-coordinate.
Returns:
the pixel distance.
See Also:
DrawableGameObject

getSquareDistanceBetween

public final int getSquareDistanceBetween(int x0,
                                          int y0,
                                          int x1,
                                          int y1)
Calculates the squared pixel distance between two points. May be used for comparing distances, as it is faster than the method that calculates the real distance.

Parameters:
x0 - an x-coordinate.
y0 - a y-coordinate.
x1 - another x-coordinate.
y1 - another y-coordinate.
Returns:
the squared pixel distance.

getDistanceBetween

public final int getDistanceBetween(int x0,
                                    int y0,
                                    int x1,
                                    int y1)
Calculates the pixel distance between two points.

Parameters:
x0 - an x-coordinate.
y0 - a y-coordinate.
x1 - another x-coordinate.
y1 - another y-coordinate.
Returns:
the pixel distance.

getAngle

public final double getAngle(int fromX,
                             int fromY,
                             int toX,
                             int toY)
Calculates the angle in radians from one point to another. The angle is the visual angle: 0 is to the right, PI/2 is up, etc. You may have to think a little bit when using this, as the screen's y-axis is positive downwards.

Parameters:
fromX - start point x-coordinate.
fromY - start point y-coordinate.
toX - end point x-coordinate.
toY - end point y-coordinate.
Returns:
the angle in radians.

getAngle

public final double getAngle(DrawableGameObject o)
Calculates the angle in radians of a vector from our ship to the given object. The angle is the visual angle: 0 is to the right, PI/2 is up, etc. You may have to think a little bit when using this, as the screen's y-axis is positive downwards.

Parameters:
o - the object to find the direction to.
Returns:
the angle in radians.

getNormalizedAngle

public final double getNormalizedAngle(double angle)
Makes sure an angle is within the interval 0.0 to 2PI. May be useful when working with angle differences. Note that it will not work for values > 4PI or < -2PI (more than one round around the circle)!

Parameters:
angle - the angle to normalize.
Returns:
the normalized angle.

getDeltaAngle

public final double getDeltaAngle(double fromAngle,
                                  double toAngle)
Calculates the smallest angle from one angle to another. The angle found is the one that must be added to the fromAngle to reach the toAngle, without moving more than half way through the circle.

The input angles must be between 0 and 2PI. The output is between -PI and PI.

Parameters:
fromAngle - the angle to start from.
toAngle - the angle to end up with.
Returns:
the angle difference.

getAbsDeltaAngle

public final double getAbsDeltaAngle(double angle1,
                                     double angle2)
Calculates the smallest angle between two given angles, without taking care of direction. The smallest angle is the one that is less than or equal to the half circle.

The input angles must be between 0 and 2PI. The output is between 0 and PI.

Parameters:
angle1 - one angle.
angle2 - another angle.
Returns:
the angle between the two angles.

getBestTurn

public final int getBestTurn(double oldAngle,
                             double newAngle)
Finds the best way to turn to move from one direction to another. Very useful for aiming your ship against other players.

Parameters:
oldAngle - the current angle of direction.
newAngle - the wanted angle of direction.
Returns:
the best turn: TURN_NONE, TURN_LEFT, or TURN_RIGHT.

isInFront

public final boolean isInFront(DrawableGameObject o)
Checks if the given object is in front of our ship. Given a line thru the ship's center, perpendicular to the ship's pointing direction, any objects on the same side as the ship's nose are said to be in front.

Parameters:
o - the object to check.
Returns:
true if the object is in front, false otherwise.

isBehind

public final boolean isBehind(DrawableGameObject o)
Checks if the given object is behind our ship. Given a line thru the ship's center, perpendicular to the ship's pointing direction, any objects on the opposite side as the ship's nose are said to be behind.

Parameters:
o - the object to check.
Returns:
true if the object is behind, false otherwise.

isToTheLeft

public final boolean isToTheLeft(DrawableGameObject o)
Checks if the given object is to the left of our ship.

Parameters:
o - the object to check.
Returns:
true if the object is to the left, false otherwise.

isToTheRight

public final boolean isToTheRight(DrawableGameObject o)
Checks if the given object is to the right of our ship.

Parameters:
o - the object to check.
Returns:
true if the object is to the right, false otherwise.

getUpdateFrequency

public final int getUpdateFrequency()
Returns the number of times per second that the update method is called.

Returns:
the update frequency in Hz.
See Also:
update()