hermes
Class Being

java.lang.Object
  extended by hermes.HObject
      extended by hermes.Being
All Implemented Interfaces:
KeySubscriber, MouseSubscriber, MouseWheelSubscriber, OscSubscriber
Direct Known Subclasses:
HCamera, MassedBeing

public abstract class Being
extends HObject

General game object class.

Represents "beings", defined as (H)Objects that have:

Furthermore, Beings can be: Subclasses of Being should be game entities that have at least one of these properties. Subclass HObject directly only if the entity has none of these properties.

If you want a Being to draw itself to screen, override the draw() method. If you want a Being to update itself, override the update() method. If you want a Being to receive input messages from the PostOffice, override the message handler method specific to the type of message you want.


Field Summary
protected  PVector _position
           
protected  HShape _shape
           
protected  long _time
           
protected  PVector _velocity
           
 
Constructor Summary
Being(HShape collisionShape)
          Alternate constructor that defaults to 0 velocity.
Being(HShape collisionShape, PVector velocity)
          Creates a Being.
 
Method Summary
 void draw()
          Override in subclass if you want to draw the Being to the screen.
protected  void EulerIntegratePosition(double dt)
          Moves the Being by its velocity * the elapsed time dt.
 HRectangle getBoundingBox()
          Gets the bounding box enclosing the Being's shape.
 PVector getPosition()
           
 HShape getShape()
           
 PVector getVelocity()
           
 float getVelocityX()
           
 float getVelocityY()
           
 float getX()
           
 float getY()
           
 boolean needsMoreSamples()
          Used for multisampling -- if true the object needs to be sampled more on the current update.
protected  boolean processUpdate()
          Used internally (needed for multi-sampling).
protected  void setDone(boolean done)
           
 void setPosition(float x, float y)
          Sets the Being's position to given x,y values.
 void setPosition(float x, float y, float z)
          Sets the Being's position to given x,y,z values.
 void setPosition(PVector position)
          Sets the Being's new position.
 void setVelocity(PVector velocity)
          Sets the Being's velocity to a given vector.
 void setVelocityX(float x)
           
 void setVelocityY(float y)
           
 void setX(float x)
           
 void setY(float y)
           
protected  void step()
          Updates the Being's position, called for on each update, if multisampling is enabled will be for each sample.
 java.lang.String toString()
           
protected  void update()
          Override if Being should update itself on every game step
protected  long updateTime()
          Updates the internal recorded time of the Being using the current system time.
 
Methods inherited from class hermes.HObject
addToGroup, delete, getGroups, receive, receive, receive, receive, removeFromGroup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_position

protected PVector _position

_velocity

protected PVector _velocity

_shape

protected HShape _shape

_time

protected long _time
Constructor Detail

Being

public Being(HShape collisionShape,
             PVector velocity)
Creates a Being. Should be called by a class that extends Being.

Parameters:
collisionShape - Shape used to determine Being's position and collision detection
velocity - The Being's initial velocity. Velocity gets updated automatically every timestep.

Being

public Being(HShape collisionShape)
Alternate constructor that defaults to 0 velocity.

When a Being's velocity in 0, the World that it is in won't update the Being's position automatically. Thus, all motion must be handled through setX, setY, or setPosition.

NOTE: If this Being's velocity is later set to something other than 0, it will then have its position updated automatically.

Parameters:
collisionShape - Shape used to determine Being's position and collision detection
Method Detail

updateTime

protected long updateTime()
Updates the internal recorded time of the Being using the current system time.

Returns:
time elaspsed since the last call to updateTime

draw

public void draw()
Override in subclass if you want to draw the Being to the screen.


getShape

public HShape getShape()
Returns:
The Being's shape

getPosition

public PVector getPosition()
Returns:
The Being's position

setPosition

public void setPosition(PVector position)
Sets the Being's new position.

Note: this is a deep copy so the Being's position and its Shape's position will always be in sync.

Parameters:
position -

setPosition

public void setPosition(float x,
                        float y)
Sets the Being's position to given x,y values.

Parameters:
x - x position
y - y position

setPosition

public void setPosition(float x,
                        float y,
                        float z)
Sets the Being's position to given x,y,z values.

Parameters:
x - x position
y - y position
z - z position (at the currrent time a nonzero z may result in unexpected behavior)

getX

public float getX()
Returns:
The Being's x position

getY

public float getY()
Returns:
The Being's y position

setX

public void setX(float x)
Parameters:
x - Being's new x position

setY

public void setY(float y)
Parameters:
y - Being's new y position

getVelocity

public PVector getVelocity()
Returns:
The Being's velocity

getVelocityX

public float getVelocityX()
Returns:
The Being's x velocity

getVelocityY

public float getVelocityY()
Returns:
The Being's y velocity

setVelocity

public void setVelocity(PVector velocity)
Sets the Being's velocity to a given vector.

NOTE: this is a deep copy; changing velocity vector passed in after this call will have no effect on the Being.

Parameters:
velocity -

setVelocityX

public void setVelocityX(float x)
Parameters:
x - Being's new x velocity

setVelocityY

public void setVelocityY(float y)
Parameters:
y - Being's new y velocity

getBoundingBox

public HRectangle getBoundingBox()
Gets the bounding box enclosing the Being's shape.

Returns:
The bounding box enclosing the Being's shape

setDone

protected void setDone(boolean done)

processUpdate

protected boolean processUpdate()
Used internally (needed for multi-sampling).


needsMoreSamples

public boolean needsMoreSamples()
Description copied from class: HObject
Used for multisampling -- if true the object needs to be sampled more on the current update.

Overrides:
needsMoreSamples in class HObject
Returns:
whether the object needs more samples this update

update

protected void update()
Override if Being should update itself on every game step


step

protected void step()
Updates the Being's position, called for on each update, if multisampling is enabled will be for each sample.
Override if you want to perform movement manually rather than letting it move automatically.


EulerIntegratePosition

protected void EulerIntegratePosition(double dt)
Moves the Being by its velocity * the elapsed time dt.

Parameters:
dt - the elapsed time to use for Euler integration

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String with position and velocity of Being, use for debugging