GTGE API

com.golden.gamedev.object.collision
Class AdvanceCollisionGroup

java.lang.Object
  extended by com.golden.gamedev.object.CollisionManager
      extended by com.golden.gamedev.object.collision.BasicCollisionGroup
          extended by com.golden.gamedev.object.collision.CollisionGroup
              extended by com.golden.gamedev.object.collision.PreciseCollisionGroup
                  extended by com.golden.gamedev.object.collision.AdvanceCollisionGroup
All Implemented Interfaces:
Comparator

public abstract class AdvanceCollisionGroup
extends PreciseCollisionGroup
implements Comparator

Accurates collision check that able to check collision between one sprite with many sprites (one to many collision check).

This collision check is the most advance among all other collision check, it checking is the collision really occured or not.

For example:
A sprite is checked its collision with three other sprites, if the checking only based on the sprite position, the sprite is collided with the three other sprites. But if the sprite is collided with the first sprite and stop, the sprite actually only collide with the first, because the second and the third is right behind the first sprite.

This collision group is suitable for collision that using physics heavily, like in platformer game, where a sprite could collide with many blocks at one time.


Field Summary
 
Fields inherited from class com.golden.gamedev.object.collision.CollisionGroup
BOTTOM_TOP_COLLISION, collisionSide, collisionX1, collisionX2, collisionY1, collisionY2, LEFT_RIGHT_COLLISION, RIGHT_LEFT_COLLISION, sprite1, sprite2, TOP_BOTTOM_COLLISION
 
Fields inherited from class com.golden.gamedev.object.collision.BasicCollisionGroup
pixelPerfectCollision, rect1, rect2
 
Constructor Summary
AdvanceCollisionGroup()
          Constructs new AdvanceCollisionGroup.
 
Method Summary
 void checkCollision()
          Checks for collision between all members in group 1 againts all members in group 2.
 int compare(Object o1, Object o2)
          Sorts two sprites (o1 and o2) that collided with the object sprite to determine which one should be checked first.
protected  Sprite getSourceSprite()
          Returns the source sprite to be checked at the moment.
 Map getStorage()
          Returns collided sprites storage.
protected  boolean sort(Sprite source)
          Determines all sprites that collided with Sprite source should be sorted or not before checking the actual collision.
 
Methods inherited from class com.golden.gamedev.object.collision.PreciseCollisionGroup
isCollide
 
Methods inherited from class com.golden.gamedev.object.collision.CollisionGroup
getCollisionSide, getSprite1, getSprite2, printCollisionSide, revertPosition1, revertPosition2
 
Methods inherited from class com.golden.gamedev.object.collision.BasicCollisionGroup
collided, getCollisionShape1, getCollisionShape2
 
Methods inherited from class com.golden.gamedev.object.CollisionManager
getGroup1, getGroup2, getIntersectionRect, isActive, isPixelCollide, setActive, setCollisionGroup
 
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
 

Constructor Detail

AdvanceCollisionGroup

public AdvanceCollisionGroup()
Constructs new AdvanceCollisionGroup.

Method Detail

checkCollision

public void checkCollision()
Description copied from class: CollisionManager
Checks for collision between all members in group 1 againts all members in group 2.

Overrides:
checkCollision in class BasicCollisionGroup

sort

protected boolean sort(Sprite source)
Determines all sprites that collided with Sprite source should be sorted or not before checking the actual collision.

By default this method return true in order to sort the collided sprites.

Returns:
true, collided sprites will be sorted before checking the actual collision.
See Also:
compare(Object, Object)

compare

public int compare(Object o1,
                   Object o2)
Sorts two sprites (o1 and o2) that collided with the object sprite to determine which one should be checked first.

By default when the object sprite is falling (vertical speed >= 0), all collided sprites are sorted by greater y at bottom, otherwise it sort by greater y at top.

Specified by:
compare in interface Comparator

getSourceSprite

protected Sprite getSourceSprite()
Returns the source sprite to be checked at the moment.

Source sprite is the sprite from group 1 that will be checked its actual collision with sprite from group 2.


getStorage

public Map getStorage()
Returns collided sprites storage.

Mapping a sprite with its collided sprites.


GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id