Genuts API

com.genuts.gameui
Class LCDCollisionManager

java.lang.Object
  |
  +--com.genuts.gameui.LCDCollisionManager
All Implemented Interfaces:
CollisionManager

public class LCDCollisionManager
extends java.lang.Object
implements CollisionManager

This collision manager is specially designed for games where sprites have definite positions.

Collision points should be added for each sprites. A collision point is definite for each sprite by its ID and an offset in its array of positions.
When a collision point is set for sprites A and B, it is automatically set for sprites B and A.

It has to be used for old LCD games clone.


Constructor Summary
LCDCollisionManager()
          Initializes the LCD collision manager.
 
Method Summary
 void addCollisionPosition(int sprite1Id, int sprite1Pos, int sprite2Id, int sprite2Pos)
          Adds a collision position for 2 sprites.
 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 clearAllCollisionPositions()
          Clears all collision positions for this collision manager.
 void drawDebug(java.awt.Graphics g)
          Draws debug informations for this collision manager.
 PlayField getPlayfield()
          Returns the playfield associated with this collision manager.
 LCDSprite getSpriteWithId(int id)
          Returns the first sprite with the desired id.
 void invalidateSprite(Sprite sprite)
          Performs actions when a sprite is invalidate.
 void playfieldSizeChanged()
          No action
 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()
          No action
 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

LCDCollisionManager

public LCDCollisionManager()
Initializes the LCD collision manager.

Method Detail

getPlayfield

public PlayField getPlayfield()
Description copied from interface: CollisionManager
Returns the playfield associated with this collision manager.

Specified by:
getPlayfield in interface CollisionManager
Returns:
The playfield associated with this collision manager.

setPlayfield

public void setPlayfield(PlayField playfield)
Description copied from interface: CollisionManager
Sets the playfield associated with this collision manager.

Specified by:
setPlayfield in interface CollisionManager
Parameters:
playfield - The playfield associated with this collision manager.

playfieldSizeChanged

public void playfieldSizeChanged()
No action

Specified by:
playfieldSizeChanged in interface CollisionManager

reset

public void reset()
No action

Specified by:
reset in interface CollisionManager

preCheckCollision

public boolean preCheckCollision(Sprite sprite)
Description copied from interface: CollisionManager
Checks pre-collision of the given sprite with all other sprites in this playfield, and with the edges of this playfield.

If one or more pre-collisions are detected, firePreCollisionEvent(Sprite, Sprite) is called.

Specified by:
preCheckCollision in interface CollisionManager
Parameters:
sprite - Sprite to check
Returns:
true to confirm the state of the sprite, false otherwise.
See Also:
CollisionManager.checkCollision(Sprite), PlayField.firePreCollisionEvent(Sprite, Sprite)

checkCollision

public void checkCollision(Sprite sprite)
Description copied from interface: CollisionManager
Checks collision of the given sprite with all other sprites in the playfield, and with the edges of the playfield. If one or more collisions are detected, fireCollisionEvent(Sprite, Sprite) is called.

Specified by:
checkCollision in interface CollisionManager
Parameters:
sprite - Sprite to check
See Also:
PlayField.fireCollisionEvent(Sprite, Sprite)

checkAllCollisions

public void checkAllCollisions()
Description copied from interface: CollisionManager
Checks collisions of sprites with all other sprites in the playfield, and with the edges of the playfield. If one or more collisions are detected, fireCollisionEvent(Sprite, Sprite) is called.

Specified by:
checkAllCollisions in interface CollisionManager
See Also:
PlayField.fireCollisionEvent(Sprite, Sprite)

addSprite

public void addSprite(Sprite sprite)
Description copied from interface: CollisionManager
Adds a sprite in the check list of this collision manager.

Generally, this is called by the playfield when a new sprite is added.

Specified by:
addSprite in interface CollisionManager
Parameters:
sprite - Sprite to add

removeSprite

public void removeSprite(Sprite sprite)
Description copied from interface: CollisionManager
Removes a sprite from the check list of this collision manager.

Generally, this is called by the playfield when a sprite is removed.

Specified by:
removeSprite in interface CollisionManager
Parameters:
sprite - Sprite to remove

invalidateSprite

public void invalidateSprite(Sprite sprite)
Description copied from interface: CollisionManager
Performs actions when a sprite is invalidate.

Generally, this is called by a sprite when Sprite.invalidate() is called.

Specified by:
invalidateSprite in interface CollisionManager
Parameters:
sprite - Sprite to invalidate.
See Also:
Sprite.invalidate()

validateSprite

public void validateSprite(Sprite sprite)
Description copied from interface: CollisionManager
Performs actions when a sprite is validate.

Generally, this is called by a sprite when Sprite.validate() is called.

Specified by:
validateSprite in interface CollisionManager
Parameters:
sprite - Sprite to validate.
See Also:
Sprite.validate()

drawDebug

public void drawDebug(java.awt.Graphics g)
Description copied from interface: CollisionManager
Draws debug informations for this collision manager.

Specified by:
drawDebug in interface CollisionManager
Parameters:
g - The graphics context to use for painting.

clearAllCollisionPositions

public void clearAllCollisionPositions()
Clears all collision positions for this collision manager.


addCollisionPosition

public void addCollisionPosition(int sprite1Id,
                                 int sprite1Pos,
                                 int sprite2Id,
                                 int sprite2Pos)
Adds a collision position for 2 sprites.

Collision points should be added for each sprites. A collision point is definite for each sprite by its ID and an offset in its array of positions.
When a collision point is set for sprites A and B, it is automatically set for sprites B and A.

Parameters:
sprite1Id - Id of the sprite 1.
sprite1Pos - Collision position for sprite 1.
sprite2Id - Id of the sprite 2.
sprite2Pos - Collision position for sprite 2.

getSpriteWithId

public LCDSprite getSpriteWithId(int id)
Returns the first sprite with the desired id.

Parameters:
id - The id to look for.
Returns:
The first sprite with the desired id. or null if there no sprite with this id.

Genuts API

Genuts API