|
Genuts API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.genuts.gameui.SpriteCollisionManager
The sprite collision manager checks collisions in the general case for sprites.
The collision bounding box used for collision checking is the sprite bounding box without collision offsets on each side.
To know if a sprite is in collision with borders of the playfield, it uses the sprite collision bounding
box, and to know if a sprite is in collision with another one, the manager calls
checkCollision(Sprite) of each sprite. Then if a collision is
detected, the collision manager calls
fireCollisionEvent(Sprite, Sprite) to dispatch
the collision.
The method getSpriteAt(int, int) uses the collision bounding box to optimise
the process.
The collision order in a cell is given by sprites' ID; more the ID is high more the priority of the collision is high. For sprites with the same ID, the last validated sprite will have the priority.
Sprite,
PlayField.fireCollisionEvent(Sprite, Sprite)| Constructor Summary | |
SpriteCollisionManager(int step)
Initializes this collision manager with a collision step. |
|
| Method Summary | |
void |
addSprite(Sprite sprite)
Adds a sprite in the check list of this collision manager. |
void |
checkAllCollisions()
Checks collisions of sprites with all other sprites in the playfield, and with the edges of the playfield. |
void |
checkCollision(Sprite sprite)
Checks collision of the given sprite with all other sprites in the playfield, and with the edges of the playfield. |
void |
drawDebug(java.awt.Graphics g)
Draws debug informations for this collision manager. |
int |
getCollisionStep()
Returns the collision step check of this collision manager. |
PlayField |
getPlayfield()
Returns the playfield associated with this collision manager. |
Sprite |
getSpriteAt(int x,
int y)
Locates the first Sprite that contains the x,y position. |
Sprite |
getSpriteAtCell(int x,
int y)
Locates the first Sprite which is contained in cell x,y of the array of sprites. |
void |
invalidateSprite(Sprite sprite)
Performs actions when a sprite is invalidate. |
void |
playfieldSizeChanged()
Informs that the size of the playfield has changed. |
boolean |
preCheckCollision(Sprite sprite)
Checks pre-collision of the given sprite with all other sprites in this playfield, and with the edges of this playfield. |
void |
removeSprite(Sprite sprite)
Removes a sprite from the check list of this collision manager. |
void |
reset()
Resets cache datas for this CollisionManager. |
void |
setCollisionStep(int step)
Sets the collision step check of this collision manager. |
void |
setPlayfield(PlayField playfield)
Sets the playfield associated with this collision manager. |
void |
validateSprite(Sprite sprite)
Performs actions when a sprite is validate. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public SpriteCollisionManager(int step)
More the step is small, more the collision checking is quicker, but more memory needed is important and more movement of a sprite is slower.
step - Step for collision check.| Method Detail |
public int getCollisionStep()
public void setCollisionStep(int step)
More the step is small, more the collision checking is quicker, but more memory need is important and more movement of a sprite is slower.
step - The collision step for this collision manager.public PlayField getPlayfield()
CollisionManager
getPlayfield in interface CollisionManagerpublic void setPlayfield(PlayField playfield)
CollisionManager
setPlayfield in interface CollisionManagerplayfield - The playfield associated with this collision manager.public void playfieldSizeChanged()
Be careful with sprites which are out the new size of the playfield, they are simply ignored, and on there next move, a collision will be generated.
playfieldSizeChanged in interface CollisionManagerpublic void reset()
CollisionManager
reset in interface CollisionManagerpublic void addSprite(Sprite sprite)
CollisionManagerGenerally, this is called by the playfield when a new sprite is added.
addSprite in interface CollisionManagersprite - Sprite to addpublic void removeSprite(Sprite sprite)
CollisionManagerGenerally, this is called by the playfield when a sprite is removed.
removeSprite in interface CollisionManagersprite - Sprite to removepublic void invalidateSprite(Sprite sprite)
CollisionManagerGenerally, this is called by a sprite when Sprite.invalidate() is called.
invalidateSprite in interface CollisionManagersprite - Sprite to invalidate.Sprite.invalidate()public void validateSprite(Sprite sprite)
CollisionManagerGenerally, this is called by a sprite when Sprite.validate() is called.
validateSprite in interface CollisionManagersprite - Sprite to validate.Sprite.validate()
public Sprite getSpriteAt(int x,
int y)
x - X coordinate to checky - Y coordinate to check
null if there is no sprite.Sprite.isSpriteAt(int, int)
public Sprite getSpriteAtCell(int x,
int y)
The upper left cell's coordinates are (0, 0).
x - X coordinate of the cell to checky - Y coordinate of the cell to check
null if there is no sprite.public boolean preCheckCollision(Sprite sprite)
CollisionManager
If one or more pre-collisions are detected, firePreCollisionEvent(Sprite, Sprite)
is called.
preCheckCollision in interface CollisionManagersprite - Sprite to check
true to confirm the state of the sprite, false
otherwise.CollisionManager.checkCollision(Sprite),
PlayField.firePreCollisionEvent(Sprite, Sprite)public void checkCollision(Sprite sprite)
CollisionManagerfireCollisionEvent(Sprite, Sprite)
is called.
checkCollision in interface CollisionManagersprite - Sprite to checkPlayField.fireCollisionEvent(Sprite, Sprite)public void checkAllCollisions()
CollisionManagerfireCollisionEvent(Sprite, Sprite)
is called.
checkAllCollisions in interface CollisionManagerPlayField.fireCollisionEvent(Sprite, Sprite)public void drawDebug(java.awt.Graphics g)
CollisionManager
drawDebug in interface CollisionManagerg - The graphics context to use for painting.
|
Genuts API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||