vooga.gameEngine.item
Class GameItem

java.lang.Object
  extended by vooga.gameEngine.game.GameRelatedObject
      extended by vooga.gameEngine.item.GameItem
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Renderable>, Renderable, Tangible
Direct Known Subclasses:
AIDemoItem, AIDemoText, BoundedItem, CameraRectangle, Explosion, Laser, PhysicalItem, Platform, RobotUnicorn, StaticItem, TerrainPiece, TestGameItem, Weapon, Worm

public class GameItem
extends GameRelatedObject
implements Renderable

Every item that will be displayed on screen in a game must extend the GameItem class. This class ensures that items created for a game are Renderable and extend a GameRelatedObject.

Author:
Justin C. Klaassen
See Also:
Serialized Form

Constructor Summary
GameItem(Texture t)
          Creates a GameItem set to visible by default.
 
Method Summary
 int compareTo(Renderable o)
           
 Position getPosition()
          Getter method for the current position of this item in the coordinate system used by the game.
 Rotation2D getRotation()
          Getter method for the current rotation of this item in the coordinate system used by the game.
 java.awt.Shape getShape()
          Method for getting a Shape representing the area that can be rendered on screen.
 Dimension getSize()
          Getter method for the current dimension of this item in the coordinate system used by the game.
 Texture getTexture()
          Getter method for the current Texture of this item.
 boolean isVisible()
          Gives the visibility status of the GameItem.
 void move(double dx, double dy)
          Moves this object dx to the right and dy up, which is relative to the in game coordinate system.
 void resize(double dx, double dy)
          Change's the size of this object dx in width and dy in height, which is relative to the in game coordinate system.
 void rotate(double dtheta)
          Rotates this object dtheta clockwise, which is relative to the Position defined the existing Rotation2D associated with this object.
 void setPosition(Position p)
          Moves this object to a specified Position.
 void setRotation(Rotation2D r)
          Changes this object's rotation to the specified Rotation2D.
 void setSize(Dimension d)
          Changes this object's size to a specified Dimension.
 void setVisibility(boolean visible)
          Sets the visibility status of the GameItem.
 
Methods inherited from class vooga.gameEngine.game.GameRelatedObject
addEventListener, clearListeners, equals, fire, fire, fire, getEventListeners, getID, getListenerCount, removeEventListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameItem

public GameItem(Texture t)
Creates a GameItem set to visible by default.

Parameters:
t - is the Texture representing the GameItem
Method Detail

isVisible

public final boolean isVisible()
Description copied from interface: Renderable
Gives the visibility status of the GameItem.

Specified by:
isVisible in interface Renderable
Returns:
true if visible

setVisibility

public final void setVisibility(boolean visible)
Description copied from interface: Renderable
Sets the visibility status of the GameItem.

Specified by:
setVisibility in interface Renderable
Parameters:
visible - if true, if not false

getPosition

public final Position getPosition()
Description copied from interface: Tangible
Getter method for the current position of this item in the coordinate system used by the game.

Specified by:
getPosition in interface Tangible
Returns:
a copy of the Position representing current position

getSize

public final Dimension getSize()
Description copied from interface: Tangible
Getter method for the current dimension of this item in the coordinate system used by the game.

Specified by:
getSize in interface Tangible
Returns:
a copy of the Dimension representing current size

getRotation

public final Rotation2D getRotation()
Description copied from interface: Tangible
Getter method for the current rotation of this item in the coordinate system used by the game.

Specified by:
getRotation in interface Tangible
Returns:
a copy of the Rotation2D representing current rotation

move

public final void move(double dx,
                       double dy)
Description copied from interface: Tangible
Moves this object dx to the right and dy up, which is relative to the in game coordinate system. A negative dx corresponds to moving left, and a negative dy corresponds to moving down. Fires a PositionChangedEvent when called.

Specified by:
move in interface Tangible
Parameters:
dx - the change in the x-axis
dy - the change in the y-axis

resize

public final void resize(double dx,
                         double dy)
Description copied from interface: Tangible
Change's the size of this object dx in width and dy in height, which is relative to the in game coordinate system. Fires a SizeChangedEvent when called.

Specified by:
resize in interface Tangible
Parameters:
dx - the change in the width
dy - the change in the height

rotate

public final void rotate(double dtheta)
Description copied from interface: Tangible
Rotates this object dtheta clockwise, which is relative to the Position defined the existing Rotation2D associated with this object. Fires a RotationChangedEvent when called.

Specified by:
rotate in interface Tangible
Parameters:
dtheta - is the angle to rotate the object in radians

setPosition

public final void setPosition(Position p)
Description copied from interface: Tangible
Moves this object to a specified Position. Fires a PositionChangedEvent when called.

Specified by:
setPosition in interface Tangible
Parameters:
p - new position of the object (top left corner)

setSize

public final void setSize(Dimension d)
Description copied from interface: Tangible
Changes this object's size to a specified Dimension. Fires a SizeChangedEvent when called.

Specified by:
setSize in interface Tangible
Parameters:
d - is new dimension of the object in the game's coordinate system

setRotation

public final void setRotation(Rotation2D r)
Description copied from interface: Tangible
Changes this object's rotation to the specified Rotation2D. Fires a RotationChangedEvent when called.

Specified by:
setRotation in interface Tangible
Parameters:
r - is new rotation of the object

compareTo

public final int compareTo(Renderable o)
Specified by:
compareTo in interface java.lang.Comparable<Renderable>

getTexture

public final Texture getTexture()
Description copied from interface: Renderable
Getter method for the current Texture of this item. The texture represents how the GameItem is displayed on the screen. The dimensions of the Texture should be relative to the coordinate system used in the game.

Specified by:
getTexture in interface Renderable
Returns:
the Texture of the game item

getShape

public final java.awt.Shape getShape()
Description copied from interface: Tangible
Method for getting a Shape representing the area that can be rendered on screen.

Specified by:
getShape in interface Tangible
Returns:
the shape of the object