Class Sprite

java.lang.Object
   |
   +----Sprite

public class Sprite
extends Object
This class is the heart of this sprite based JAVA game engine. The "eye" creatures and the "gun" object are derived from this class. This class is taken directly from the book "Teach yourself Internet Game Programming with Java in 21 days" by Michael Morrison. See chapter 6 for details.


Variable Index

 o BA_BOUNCE
Bounds actions
 o BA_DIE
Bounds actions
 o BA_STOP
Bounds actions
 o BA_WRAP
Bounds actions
 o bounds
 o boundsAction
 o collision
 o component
 o frame
 o frameDelay
 o frameInc
 o frameTrigger
 o hidden
 o image
 o position
 o SA_ADDSPRITE
Sprite action flags
 o SA_KILL
Sprite action flags
 o SA_RESTOREPOS
Sprite action flags
 o velocity
 o zOrder

Constructor Index

 o Sprite(Component, Image, Point, Point, int, int)
Sprite constructor method for a single image bitmap with NO frame animation.
 o Sprite(Component, Image[], int, int, int, Point, Point, int, int)
Sprite constructor method for an bitmap image that uses multiple frame animation.

Method Index

 o addSprite(BitSet)
Add a Sprite - does nothing ?
 o draw(Graphics)
Draw the bitmap Sprite image if not hidden
 o getBounds()
Get the Sprite image collision bounds.
 o getCollision()
Get the Sprite image collision coordinates.
 o getFrame()
Get the current animation frame image.
 o getFrameInc()
Get the current animation frame counter.
 o getImage()
Get an image object of this class object.
 o getPosition()
Get the current rectangular position of the Sprite image.
 o getVelocity()
Get the current velocity of the Sprite image.
 o getZOrder()
Get the Sprite image z-order position.
 o hide()
Hide the Sprite from display.
 o incFrame()
Increment the current animation frame.
 o isPointInside(Point)
See if a point is inside the Sprite bounding box limits.
 o setBounds(Rectangle)
Set the Sprite image collision bounds.
 o setCollision()
Set the Sprite image collision coordinates.
 o setFrameInc(int)
Set thje current animation frame counter.
 o setImage(Image[])
Set this classes image object.
 o setPosition(Point)
Move the current rectangular position of the Sprite image.
 o setPosition(Rectangle)
Set the current rectangular position of the Sprite image.
 o setVelocity(Point)
Set the current velocity of the Sprite image.
 o show()
Set the Sprite to display.
 o testCollision(Sprite)
Check for collision with another sprite.
 o update()
This method is the main run-time method for the "Sprite" class.

Variables

 o SA_KILL
 public static final int SA_KILL
Sprite action flags

 o SA_RESTOREPOS
 public static final int SA_RESTOREPOS
Sprite action flags

 o SA_ADDSPRITE
 public static final int SA_ADDSPRITE
Sprite action flags

 o BA_STOP
 public static final int BA_STOP
Bounds actions

 o BA_WRAP
 public static final int BA_WRAP
Bounds actions

 o BA_BOUNCE
 public static final int BA_BOUNCE
Bounds actions

 o BA_DIE
 public static final int BA_DIE
Bounds actions

 o component
 protected Component component
 o image
 protected Image image[]
 o frame
 protected int frame
 o frameInc
 protected int frameInc
 o frameDelay
 protected int frameDelay
 o frameTrigger
 protected int frameTrigger
 o position
 protected Rectangle position
 o collision
 protected Rectangle collision
 o zOrder
 protected int zOrder
 o velocity
 protected Point velocity
 o bounds
 protected Rectangle bounds
 o boundsAction
 protected int boundsAction
 o hidden
 protected boolean hidden

Constructors

 o Sprite
 public Sprite(Component comp,
               Image img,
               Point pos,
               Point vel,
               int z,
               int ba)
Sprite constructor method for a single image bitmap with NO frame animation.

 o Sprite
 public Sprite(Component comp,
               Image img[],
               int f,
               int fi,
               int fd,
               Point pos,
               Point vel,
               int z,
               int ba)
Sprite constructor method for an bitmap image that uses multiple frame animation.

Methods

 o getImage
 public Image[] getImage()
Get an image object of this class object.

 o setImage
 public void setImage(Image img[])
Set this classes image object.

 o getFrameInc
 public int getFrameInc()
Get the current animation frame counter.

 o setFrameInc
 public void setFrameInc(int fi)
Set thje current animation frame counter.

 o getFrame
 public int getFrame()
Get the current animation frame image.

 o incFrame
 protected void incFrame()
Increment the current animation frame.

 o getPosition
 public Rectangle getPosition()
Get the current rectangular position of the Sprite image.

 o setPosition
 void setPosition(Rectangle pos)
Set the current rectangular position of the Sprite image.

 o setPosition
 public void setPosition(Point pos)
Move the current rectangular position of the Sprite image.

 o setCollision
 protected void setCollision()
Set the Sprite image collision coordinates.

 o getCollision
 protected Rectangle getCollision()
Get the Sprite image collision coordinates.

 o getZOrder
 public int getZOrder()
Get the Sprite image z-order position.

 o getVelocity
 public Point getVelocity()
Get the current velocity of the Sprite image.

 o setVelocity
 public void setVelocity(Point vel)
Set the current velocity of the Sprite image.

 o getBounds
 public Rectangle getBounds()
Get the Sprite image collision bounds.

 o setBounds
 public void setBounds(Rectangle b)
Set the Sprite image collision bounds.

 o show
 public void show()
Set the Sprite to display.

 o hide
 public void hide()
Hide the Sprite from display.

 o isPointInside
 boolean isPointInside(Point pt)
See if a point is inside the Sprite bounding box limits.

 o update
 public BitSet update()
This method is the main run-time method for the "Sprite" class. Frame animation, position, and bounds checking for the sprite image are done here.

 o draw
 public void draw(Graphics g)
Draw the bitmap Sprite image if not hidden

 o addSprite
 protected Sprite addSprite(BitSet action)
Add a Sprite - does nothing ?

 o testCollision
 protected boolean testCollision(Sprite test)
Check for collision with another sprite.