Class SpriteVector

java.lang.Object
   |
   +----java.util.Vector
           |
           +----SpriteVector

public class SpriteVector
extends Vector
This class handles all the details of maintaining a list of Sprite objects and the handling of the interactions between them. 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 background

Constructor Index

 o SpriteVector(Background)
SpriteVector constructor method - sets the background.

Method Index

 o add(Sprite)
Use a binary search to find the right location to insert the new sprite (based on z-order).
 o collision(int, int)
Swap velocities (bounce).
 o draw(Graphics)
Draw the background and iterate through sprites, drawing each
 o getBackground()
Get the background object.
 o getEmptyPosition(Dimension)
This method allows Sprites to be placed randomly on the screen without overlapping.
 o isPointInside(Point)
Returns a Sprite if the point lies within a Sprite.
 o setBackground(Background)
Set the background.
 o testCollision(Sprite)
Check for collision with other sprites.
 o update()
Iterate through Sprites, updating each

Variables

 o background
 protected Background background

Constructors

 o SpriteVector
 public SpriteVector(Background back)
SpriteVector constructor method - sets the background.

Methods

 o getBackground
 public Background getBackground()
Get the background object.

 o setBackground
 public void setBackground(Background back)
Set the background.

 o getEmptyPosition
 public Point getEmptyPosition(Dimension sSize)
This method allows Sprites to be placed randomly on the screen without overlapping.

 o isPointInside
 Sprite isPointInside(Point pt)
Returns a Sprite if the point lies within a Sprite. Searches list of all Sprite objects.

 o update
 public void update()
Iterate through Sprites, updating each

 o draw
 public void draw(Graphics g)
Draw the background and iterate through sprites, drawing each

 o add
 public int add(Sprite s)
Use a binary search to find the right location to insert the new sprite (based on z-order).

 o testCollision
 protected int testCollision(Sprite test)
Check for collision with other sprites.

 o collision
 protected boolean collision(int i,
                             int iHit)
Swap velocities (bounce).