com.golden.gamedev.object
Class PlayField

java.lang.Object
  |
  +--com.golden.gamedev.object.PlayField

public class PlayField
extends Object

Game arena, behave as the game manager. All SpriteGroup and CollisionGroupManager is stored here. By calling update() all sprites will be updated and collision also checked. By calling render(Graphics2D) all sprites is rendered into graphics context.


Constructor Summary
PlayField()
           
PlayField(Background backgr)
           
 
Method Summary
 void add(Sprite extra)
          Inserts an extra sprite, for example animation, explosion, etc.
 void addCollisionGroup(SpriteGroup group1, SpriteGroup group2, CollisionGroupManager collisionGroup)
           
 SpriteGroup addGroup(SpriteGroup group)
          Inserts new SpriteGroup into this playfield.
protected  void checkCollisions()
           
 void clearCache()
          Clears cache sprite.
 Background getBackground()
           
 CollisionGroupManager getCollisionGroup(SpriteGroup group)
           
 CollisionGroupManager getCollisionGroup(SpriteGroup group1, SpriteGroup group2)
           
 CollisionGroupManager[] getCollisionGroups()
           
 Comparator getComparator()
           
 SpriteGroup getGroup(String name)
           
 SpriteGroup[] getGroups()
           
 boolean removeCollisionGroup(CollisionGroupManager collisionGroup)
           
 boolean removeGroup(SpriteGroup group)
           
 void render(Graphics2D g)
           
protected  void renderBackground(Graphics2D g)
           
protected  void renderSprites(Graphics2D g)
           
protected  void renderSprites(Graphics2D g, Comparator c)
          Sorts sprites in this playfield with Comparator c before render it.
 void setBackground(Background backgr)
           
 void setComparator(Comparator c)
           
 void update()
          Updates sprites, background and check for collisions.
protected  void updateBackground()
           
protected  void updateSprites()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlayField

public PlayField(Background backgr)

PlayField

public PlayField()
Method Detail

add

public void add(Sprite extra)
Inserts an extra sprite, for example animation, explosion, etc.
It's used for convenient to add sprites directly into screen without have to creates a new SpriteGroup for the sprite.


addGroup

public SpriteGroup addGroup(SpriteGroup group)
Inserts new SpriteGroup into this playfield. The returned sprite group is the reference of the inserted group, used for code reduce and simplicity.
For example:
     Playfield playfield = new Playfield();
     SpriteGroup PLAYER  = playfield.addGroup(new SpriteGroup("Player"));
 
If there's no returned reference, we must set the sprite group and add it manually into playfield, like this:
     Playfield   playfield = new Playfield();
     SpriteGroup PLAYER    = new SpriteGroup("Player");
     playfield.addGroup(PLAYER);
 

Returns:
reference of the inserted sprite group

removeGroup

public boolean removeGroup(SpriteGroup group)
Returns:
true, if the group is successfuly removed

getGroup

public SpriteGroup getGroup(String name)

getGroups

public SpriteGroup[] getGroups()

addCollisionGroup

public void addCollisionGroup(SpriteGroup group1,
                              SpriteGroup group2,
                              CollisionGroupManager collisionGroup)

removeCollisionGroup

public boolean removeCollisionGroup(CollisionGroupManager collisionGroup)

getCollisionGroup

public CollisionGroupManager getCollisionGroup(SpriteGroup group1,
                                               SpriteGroup group2)

getCollisionGroup

public CollisionGroupManager getCollisionGroup(SpriteGroup group)

getCollisionGroups

public CollisionGroupManager[] getCollisionGroups()

update

public void update()
Updates sprites, background and check for collisions.


updateBackground

protected void updateBackground()

updateSprites

protected void updateSprites()

checkCollisions

protected void checkCollisions()

render

public void render(Graphics2D g)

renderBackground

protected void renderBackground(Graphics2D g)

renderSprites

protected void renderSprites(Graphics2D g)

renderSprites

protected void renderSprites(Graphics2D g,
                             Comparator c)
Sorts sprites in this playfield with Comparator c before render it.
Only active and on screen sprite is sorted and rendered.


clearCache

public void clearCache()
Clears cache sprite.

Cache sprite is used to keep sprites in sorted order, that will be used on rendering sprite with comparator.
When method renderSprites(Graphics2D, Comparator) called, all sprite that visible on scren are stored in cache and then sorted, Therefore after rendering done, the cache still remain in memory and wait to be cached again on next rendering.

This method simply clears the cache sprite. Call this method when sort rendering is not needed anymore.

See Also:
renderSprites(Graphics2D, Comparator)

getBackground

public Background getBackground()

setBackground

public void setBackground(Background backgr)

getComparator

public Comparator getComparator()

setComparator

public void setComparator(Comparator c)