uk.ac.ic.doc.game
Class RegularPolygon

java.lang.Object
  extended by uk.ac.ic.doc.game.RegularPolygon
All Implemented Interfaces:
IGameObject

public abstract class RegularPolygon
extends java.lang.Object
implements IGameObject

An IGameObject implementation that represents a regular polygon in the game.


Constructor Summary
RegularPolygon(Point position, double rotation, double size, int sides)
          Constructs a new regular polygon of the given position, rotation and size with the given number of sides.
 
Method Summary
 void draw(java.awt.Graphics2D graphics, Point scale)
          Draws this object on the given graphics context at the given scale.
 Point getPosition()
          Returns the current position of this object.
 double getRotation()
          Returns the current rotation of this object.
 double getSize()
          Returns the current size of this object.
 boolean isExitingScreen()
          Tests whether this object is exiting the screen.
 boolean isOverlapping(IGameObject polygon)
          Tests whether or not this object is overlapping the given object.
 void moveBackward(double amount)
          Moves this object the given amount away from the direction it is currently facing.
 void moveForward(double amount)
          Moves this object the given amount in the direction it is currently facing.
abstract  void onCreate(IGame game)
          Called when the object is added to the game.
 void setPosition(Point position)
          Sets the position of this object.
 void setRotation(double angle)
          Sets the rotation of this object.
 void setSize(double size)
          Sets the size of this object.
 void strafeLeft(double amount)
          Moves this object the given amount 90-degrees clockwise to the direction it is currently facing.
 void strafeRight(double amount)
          Moves this object the given amount 90-degrees counter-clockwise to the direction it is currently facing.
 void turnClockwise(double amount)
          Turns this object clockwise by the given amount.
 void turnCounterClockwise(double amount)
          Turns this object counter-clockwise by the given amount.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegularPolygon

public RegularPolygon(Point position,
                      double rotation,
                      double size,
                      int sides)
Constructs a new regular polygon of the given position, rotation and size with the given number of sides.

Parameters:
position - The initial position of this object, in terms of proportion of window size (e.g. (0, 0) is top-left and (1, 1) is bottom-right).
rotation - The initial angle of this object, in terms of proportion of total rotation clockwise from the vertical (e.g. 0 is facing upwards, 0.25 is facing right, 0.5 is facing downwards and 0.75 is facing left).
size - The initial size of this object, in terms of proportion of window size (e.g. 0.5 makes this object half the size of the game window).
sides - The number of sides this regular polygon has. Must be greater than 2.
Method Detail

getPosition

public Point getPosition()
Returns the current position of this object.

Returns:
The position of this object, in terms of proportion of window size (e.g. (0, 0) is top-left and (1, 1) is bottom-right).

getRotation

public double getRotation()
Returns the current rotation of this object.

Returns:
The angle of this object, in terms of proportion of total rotation clockwise from the vertical (e.g. 0 is facing upwards, 0.25 is facing right, 0.5 is facing downwards and 0.75 is facing left).

getSize

public double getSize()
Returns the current size of this object.

Returns:
The new size of this object, in terms of proportion of window size (e.g. 0.5 makes this object half the size of the game window).

setPosition

public void setPosition(Point position)
Sets the position of this object.

Parameters:
position - The new position of this object, in terms of proportion of window size (e.g. (0, 0) is top-left and (1, 1) is bottom-right).

setRotation

public void setRotation(double angle)
Sets the rotation of this object.

Parameters:
angle - The new angle of this object, in terms of proportion of total rotation clockwise from the vertical (e.g. 0 is facing upwards, 0.25 is facing right, 0.5 is facing downwards and 0.75 is facing left).

setSize

public void setSize(double size)
Sets the size of this object.

Parameters:
size - The new size of this object, in terms of proportion of window size (e.g. 0.5 makes this object half the size of the game window).

moveForward

public void moveForward(double amount)
Moves this object the given amount in the direction it is currently facing.

Parameters:
amount - The amount to move forward, in terms of proportion of window size.

moveBackward

public void moveBackward(double amount)
Moves this object the given amount away from the direction it is currently facing.

Parameters:
amount - The amount to move backwards, in terms of proportion of window size.

strafeLeft

public void strafeLeft(double amount)
Moves this object the given amount 90-degrees clockwise to the direction it is currently facing.

Parameters:
amount - The amount to strafe left, in terms of proportion of window size.

strafeRight

public void strafeRight(double amount)
Moves this object the given amount 90-degrees counter-clockwise to the direction it is currently facing.

Parameters:
amount - The amount to strafe right, in terms of proportion of window size.

turnClockwise

public void turnClockwise(double amount)
Turns this object clockwise by the given amount.

Parameters:
amount - The amount to rotate this object by, in terms of proportion of total rotation clockwise from the vertical (e.g. 0 is no change, 0.25 is 90-degrees, 0.5 is 180 degrees and 0.75 is 270 degrees).

turnCounterClockwise

public void turnCounterClockwise(double amount)
Turns this object counter-clockwise by the given amount.

Parameters:
amount - The amount to rotate this object by, in terms of proportion of total rotation counter-clockwise from the vertical (e.g. 0 is no change, 0.25 is 90-degrees, 0.5 is 180 degrees and 0.75 is 270 degrees).

draw

public void draw(java.awt.Graphics2D graphics,
                 Point scale)
Draws this object on the given graphics context at the given scale. The scale provides the width and height of the game window, such that proportional positions and sizes can be converted to on-screen coordinates.

Specified by:
draw in interface IGameObject
Parameters:
graphics - The graphics context on which to draw the object.
scale - The scale at which to draw the object.

isExitingScreen

public boolean isExitingScreen()
Tests whether this object is exiting the screen.

Specified by:
isExitingScreen in interface IGameObject
Returns:
True if this object is exiting the screen, false otherwise.

isOverlapping

public boolean isOverlapping(IGameObject polygon)
Tests whether or not this object is overlapping the given object.

Specified by:
isOverlapping in interface IGameObject
Parameters:
object - The object to test for overlap with.
Returns:
True if this object is overlapping the given object, false otherwise.

onCreate

public abstract void onCreate(IGame game)
Called when the object is added to the game. Implementations of this method should register any listeners when this method is called.

Specified by:
onCreate in interface IGameObject
Parameters:
game - The game that the object is being added to.