com.golden.gamedev.genre.platform
Class PlatformCollision

java.lang.Object
  |
  +--com.golden.gamedev.object.CollisionGroupStandard
        |
        +--com.golden.gamedev.object.CollisionGroup
              |
              +--com.golden.gamedev.object.CollisionGroupPrecise
                    |
                    +--com.golden.gamedev.genre.platform.PlatformCollision
All Implemented Interfaces:
CollisionGroupManager, Comparator

public abstract class PlatformCollision
extends CollisionGroupPrecise
implements Comparator

CollisionGroup that used very accurate collision calculation event.

In platform game, there are many blocks to hold, and collision with that blocks must be very accurate to determine the sprite movement. Collision in platform game is not like other type of game (destroy the collided sprite, bounce, etc), but physics is heavily used in here.

Because of there are many blocks, sometimes could be happen, that a sprite collided with many blocks (three to six at a time). If using standard collision group, all the collision events is directly send to the listener, there's no check is the collision really occured or not.

Therefore this class is specially designed for sprite that collision with many other sprites. The collision events is not directly send to the listener. All collision events is collected and then calculated accurately before send to the listener.


Field Summary
static int ASCENDING_Y
           
static int DESCENDING_Y
           
 
Fields inherited from class com.golden.gamedev.object.CollisionGroup
BOTTOM_TOP_COLLISION, collisionSide, collisionX1, collisionX2, collisionY1, collisionY2, LEFT_RIGHT_COLLISION, RIGHT_LEFT_COLLISION, sprite1, sprite2, TOP_BOTTOM_COLLISION
 
Constructor Summary
PlatformCollision()
           
PlatformCollision(SpriteGroup group1, SpriteGroup group2)
           
 
Method Summary
 void checkCollision()
           
 void collided(Sprite sprite1, Sprite sprite2)
          Collects all collided sprites event into HashMap collection.
abstract  void collided2(Sprite sprite1, Sprite sprite2)
           
 int compare(Object o1, Object o2)
           
 HashMap getStorage()
           
 boolean interestCollide(Sprite s1, Sprite s2)
           
protected  boolean sort(Sprite source)
          Determines all sprites that collide with Sprite source should be sorted or not before checking is the collision really occured.
 
Methods inherited from class com.golden.gamedev.object.CollisionGroupPrecise
isCollide
 
Methods inherited from class com.golden.gamedev.object.CollisionGroup
getCollisionSide, getCollisionSideString, getSprite1, getSprite2, revertPosition1, revertPosition2
 
Methods inherited from class com.golden.gamedev.object.CollisionGroupStandard
getCollisionRect1, getCollisionRect2, getGroup1, getGroup2, isActive, isCollide, setActive, setCollisionGroup, setCollisionRect1, setCollisionRect2
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

ASCENDING_Y

public static final int ASCENDING_Y
See Also:
Constant Field Values

DESCENDING_Y

public static final int DESCENDING_Y
See Also:
Constant Field Values
Constructor Detail

PlatformCollision

public PlatformCollision(SpriteGroup group1,
                         SpriteGroup group2)

PlatformCollision

public PlatformCollision()
Method Detail

sort

protected boolean sort(Sprite source)
Determines all sprites that collide with Sprite source should be sorted or not before checking is the collision really occured. Commonly when Sprite source is falling (vertical speed >= 0), all collided sprites is sorted ascending (greater y at bottom), otherwise it sort descending (greater y at top).

Returns:
true, sprites will be sorted before checking the actual collision

checkCollision

public void checkCollision()
Specified by:
checkCollision in interface CollisionGroupManager
Overrides:
checkCollision in class CollisionGroupStandard

interestCollide

public boolean interestCollide(Sprite s1,
                               Sprite s2)

collided2

public abstract void collided2(Sprite sprite1,
                               Sprite sprite2)

collided

public final void collided(Sprite sprite1,
                           Sprite sprite2)
Collects all collided sprites event into HashMap collection.

Specified by:
collided in class CollisionGroupStandard

compare

public int compare(Object o1,
                   Object o2)
Specified by:
compare in interface Comparator

getStorage

public HashMap getStorage()