vooga.gameEngine.graphics
Class Texture

java.lang.Object
  extended by vooga.gameEngine.graphics.Texture
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ImageTexture, ShapeTexture, TextTexture

public abstract class Texture
extends java.lang.Object
implements java.io.Serializable

Super class for rendering an image that will represent a GameItem on screen.

Author:
Justin C. Klaassen
See Also:
Serialized Form

Constructor Summary
protected Texture()
          Protected constructor for subclasses; creates a new Texture object with default constructors for a Dimension, Position, and Rotation2D.
 
Method Summary
 java.awt.geom.Area getArea()
          Method for getting the area occupied by this Texture in terms of the game's coordinate system.
 int getIndex()
          Method for getting the rendering index associated with this Texture.
 Position getPosition()
          Method for getting the position of this texture in terms of the game's coordinate system.
 Rotation2D getRotation()
          Method for getting the rotation of this texture in terms of the game's coordinate system.
 java.awt.Shape getShape()
          Method for getting a shape representing the convex outline associated with this Texture.
 Dimension getSize()
          Method for getting the size of this texture in terms of the game's coordinate system.
protected abstract  java.awt.Shape makeShape()
          Method for a Texture subclass to supply a Shape representing their bounding box.
 void paintComponent(java.awt.Graphics2D g2d, double scalefactor)
          Paints this component on the provided Graphics object.
protected  void setImage(java.awt.image.BufferedImage image)
          Method for subclasses to change the image used to represent this Texture on screen.
 void setIndex(int index)
          Method for setting the rendering index associated with this Texture.
 void setPosition(Position p)
          Sets the position of the game object relative to the game's coordinate system.
 void setRotation(Rotation2D r)
          Sets the rotation of the game object relative to the game's coordinate system.
 void setSize(Dimension d)
          Sets the specified Dimension, d, as this Texture's size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Texture

protected Texture()
Protected constructor for subclasses; creates a new Texture object with default constructors for a Dimension, Position, and Rotation2D. The index is also defaulted to 0.

Method Detail

setImage

protected void setImage(java.awt.image.BufferedImage image)
Method for subclasses to change the image used to represent this Texture on screen. Calculates the convex outline of the image when called.

Parameters:
image - to be used

setSize

public void setSize(Dimension d)
Sets the specified Dimension, d, as this Texture's size.

Parameters:
d - is the dimension of this game object in the game coordinate system

getSize

public Dimension getSize()
Method for getting the size of this texture in terms of the game's coordinate system.

Returns:
a copy of the Dimension associated with this texture

setPosition

public void setPosition(Position p)
Sets the position of the game object relative to the game's coordinate system.

Parameters:
p - is the Position to be set from the top left corner

getPosition

public Position getPosition()
Method for getting the position of this texture in terms of the game's coordinate system.

Returns:
a copy of the Position associated with this texture

setRotation

public void setRotation(Rotation2D r)
Sets the rotation of the game object relative to the game's coordinate system.

Parameters:
r - is the Rotation2D to be set

getRotation

public Rotation2D getRotation()
Method for getting the rotation of this texture in terms of the game's coordinate system.

Returns:
a copy of the Rotation2D associated with this texture

setIndex

public void setIndex(int index)
Method for setting the rendering index associated with this Texture. Objects are rendered on screen from highest to lowest index values.

Parameters:
index - to be set

getIndex

public int getIndex()
Method for getting the rendering index associated with this Texture. Objects are rendered on screen from highest to lowest index values.

Returns:
the index of this Texture

getShape

public java.awt.Shape getShape()
Method for getting a shape representing the convex outline associated with this Texture.

Returns:
a shape representing the outline of this Texture

makeShape

protected abstract java.awt.Shape makeShape()
Method for a Texture subclass to supply a Shape representing their bounding box. For efficiency, an object should cache their Shape if possible.

Returns:
a Shape representing the boundaries of the object

getArea

public java.awt.geom.Area getArea()
Method for getting the area occupied by this Texture in terms of the game's coordinate system. Useful for collision detection.

Returns:
the area occupied by this Texture

paintComponent

public void paintComponent(java.awt.Graphics2D g2d,
                           double scalefactor)
Paints this component on the provided Graphics object.

Parameters:
g2d - is the Graphics2D representing the game