public class Sprite
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected int |
currentState
the sprites current state
|
private ImageEntity |
entity
the sprites image
|
protected Point2D |
pos
sprites position
|
protected Point2D |
vel
sprites velocity
|
Constructor and Description |
---|
Sprite(org.havi.ui.HScene hscene)
class constructor initializes the sprites properties and adds it to the scene
|
Modifier and Type | Method and Description |
---|---|
boolean |
alive()
returns if the sprite should be displayed
|
Point2D |
center()
returns the center position of the image as a tuple
|
boolean |
collidesWith(Point2D point)
returns if the sprite collides with another point
|
boolean |
collidesWith(java.awt.Rectangle rect)
returns if the sprite collides with another object
|
boolean |
collidesWith(Sprite sprite)
returns if the sprite collides with another sprite
|
void |
draw(java.awt.Graphics g)
draws the sprite on the screen
|
java.awt.Rectangle |
getBounds()
returns the bounding rectangle of the sprite
|
int |
getState()
gets the sprites current state (alive, dead, etc.)
|
int |
imageHeight()
returns the sprite images height
|
int |
imageWidth()
returns the sprite images width
|
void |
load(java.lang.String filename)
loads an image to use as the sprite
|
Point2D |
Position()
Reurns the sprites position as a single tuple
|
void |
setAlive(boolean alive)
sets whether to display the sprite or not
|
void |
setPosition(Point2D pos)
sets the sprites position
|
void |
setState(int state)
sets the sprites new state
|
void |
setVelocity(Point2D vel)
sets the sprites velocity
|
void |
updatePosition()
updates the sprites position based on it's velocity
|
Point2D |
Velocity()
returns the sprites velocity as a single tuple
|
private ImageEntity entity
protected Point2D pos
protected Point2D vel
protected int currentState
public Sprite(org.havi.ui.HScene hscene)
hscene
- scene to add to for drawing purposespublic final void load(java.lang.String filename)
filename
- filename of image to load and use as the sprite imagepublic final void draw(java.awt.Graphics g)
g
- graphics context to use for drawingpublic final void updatePosition()
public final int getState()
public final void setState(int state)
state
- sprites new statepublic final java.awt.Rectangle getBounds()
public final Point2D Position()
public final void setPosition(Point2D pos)
pos
- sprites new position as a tuplepublic final Point2D Velocity()
public final void setVelocity(Point2D vel)
vel
- sprites new velocity as a tuplepublic final Point2D center()
public final boolean alive()
public final void setAlive(boolean alive)
alive
- true to display the object, otherwise falsepublic final int imageWidth()
public final int imageHeight()
public final boolean collidesWith(java.awt.Rectangle rect)
rect
- bounds of object to check againstpublic final boolean collidesWith(Sprite sprite)
sprite
- sprite to check againstpublic final boolean collidesWith(Point2D point)
point
- point to check against