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.
-
background
-
-
SpriteVector(Background)
- SpriteVector constructor method - sets the background.
-
add(Sprite)
- Use a binary search to find the right location to insert the
new sprite (based on z-order).
-
collision(int, int)
- Swap velocities (bounce).
-
draw(Graphics)
- Draw the background and iterate through sprites, drawing each
-
getBackground()
- Get the background object.
-
getEmptyPosition(Dimension)
- This method allows Sprites to be placed randomly on the
screen without overlapping.
-
isPointInside(Point)
- Returns a Sprite if the point lies within a Sprite.
-
setBackground(Background)
- Set the background.
-
testCollision(Sprite)
- Check for collision with other sprites.
-
update()
- Iterate through Sprites, updating each
background
protected Background background
SpriteVector
public SpriteVector(Background back)
- SpriteVector constructor method - sets the background.
getBackground
public Background getBackground()
- Get the background object.
setBackground
public void setBackground(Background back)
- Set the background.
getEmptyPosition
public Point getEmptyPosition(Dimension sSize)
- This method allows Sprites to be placed randomly on the
screen without overlapping.
isPointInside
Sprite isPointInside(Point pt)
- Returns a Sprite if the point lies within a Sprite.
Searches list of all Sprite objects.
update
public void update()
- Iterate through Sprites, updating each
draw
public void draw(Graphics g)
- Draw the background and iterate through sprites, drawing each
add
public int add(Sprite s)
- Use a binary search to find the right location to insert the
new sprite (based on z-order).
testCollision
protected int testCollision(Sprite test)
- Check for collision with other sprites.
collision
protected boolean collision(int i,
int iHit)
- Swap velocities (bounce).