GTGE API

com.golden.gamedev.object.collision
Class CollisionGroup

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
Direct Known Subclasses:
PreciseCollisionGroup

public abstract class CollisionGroup
extends BasicCollisionGroup

Basic collision check, with calculation of some collision events, such as collision side, and sprite return position.

Suitable for collision that only need to know the side of the collision, but not need precise sprite return position.

For example collision between projectile and enemy in platform game, the implementation need collision side to determine to which side the enemy should fall.

To get more precise sprite position after collision use PreciseCollisionGroup instead.

See Also:
PlayField.addCollisionGroup(SpriteGroup, SpriteGroup, CollisionManager)

Field Summary
static int BOTTOM_TOP_COLLISION
          Indicates the collision side of the collided sprites is the bottom of first sprite againts the top of other sprite.
protected  int collisionSide
          The collision side of current collision.
protected  double collisionX1
          The x return coordinate of sprite in group 1 in current collision.
protected  double collisionX2
          The x return coordinate of sprite in group 2 in current collision.
protected  double collisionY1
          The y return coordinate of sprite in group 1 in current collision.
protected  double collisionY2
          The y return coordinate of sprite in group 2 in current collision.
static int LEFT_RIGHT_COLLISION
          Indicates the collision side of the collided sprites is the left of first sprite againts the right of other sprite.
static int RIGHT_LEFT_COLLISION
          Indicates the collision side of the collided sprites is the right of first sprite againts the left of other sprite.
protected  Sprite sprite1
          The sprite from group 1 in current collision.
protected  Sprite sprite2
          The sprite from group 2 in current collision.
static int TOP_BOTTOM_COLLISION
          Indicates the collision side of the collided sprites is the top of first sprite againts the bottom of other sprite.
 
Fields inherited from class com.golden.gamedev.object.collision.BasicCollisionGroup
pixelPerfectCollision, rect1, rect2
 
Constructor Summary
CollisionGroup()
          Creates new CollisionGroup.
 
Method Summary
 int getCollisionSide()
          Returns collision side of current collision.
 Sprite getSprite1()
          Returns the sprite of current collision from group 1.
 Sprite getSprite2()
          Returns the sprite of current collision from group 2.
 boolean isCollide(Sprite s1, Sprite s2, CollisionShape shape1, CollisionShape shape2)
          Performs collision check between Sprite s1 and Sprite s2, and returns true if the sprites (shape1, shape2) is collided.
 void printCollisionSide()
          Prints collision side of current collision to console (for debugging).
 void revertPosition1()
          Reverts sprite 1 position before the collision occured.
 void revertPosition2()
          Reverts sprite 2 position before the collision occured.
 
Methods inherited from class com.golden.gamedev.object.collision.BasicCollisionGroup
checkCollision, 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
 

Field Detail

LEFT_RIGHT_COLLISION

public static final int LEFT_RIGHT_COLLISION
Indicates the collision side of the collided sprites is the left of first sprite againts the right of other sprite.

See Also:
Constant Field Values

RIGHT_LEFT_COLLISION

public static final int RIGHT_LEFT_COLLISION
Indicates the collision side of the collided sprites is the right of first sprite againts the left of other sprite.

See Also:
Constant Field Values

TOP_BOTTOM_COLLISION

public static final int TOP_BOTTOM_COLLISION
Indicates the collision side of the collided sprites is the top of first sprite againts the bottom of other sprite.

See Also:
Constant Field Values

BOTTOM_TOP_COLLISION

public static final int BOTTOM_TOP_COLLISION
Indicates the collision side of the collided sprites is the bottom of first sprite againts the top of other sprite.

See Also:
Constant Field Values

sprite1

protected Sprite sprite1
The sprite from group 1 in current collision.


sprite2

protected Sprite sprite2
The sprite from group 2 in current collision.


collisionSide

protected int collisionSide
The collision side of current collision.


collisionX1

protected double collisionX1
The x return coordinate of sprite in group 1 in current collision.


collisionY1

protected double collisionY1
The y return coordinate of sprite in group 1 in current collision.


collisionX2

protected double collisionX2
The x return coordinate of sprite in group 2 in current collision.


collisionY2

protected double collisionY2
The y return coordinate of sprite in group 2 in current collision.

Constructor Detail

CollisionGroup

public CollisionGroup()
Creates new CollisionGroup.

Method Detail

isCollide

public boolean isCollide(Sprite s1,
                         Sprite s2,
                         CollisionShape shape1,
                         CollisionShape shape2)
Performs collision check between Sprite s1 and Sprite s2, and returns true if the sprites (shape1, shape2) is collided.

This method is responsible to take care all collision events, such as the collided sprite (in this case s1 and s2), the collision side, position where collision actually occured (collisionX1, collisionY1).

The collision information is used to return the collided sprite using revertPosition1() and revertPosition2() method. Therefore if the given information is wrong, those two methods will behave unpredictable. Note: this method do not check active state of the sprites.

Overrides:
isCollide in class BasicCollisionGroup
Parameters:
s1 - sprite from group 1
s2 - sprite from group 2
shape1 - bounding box of sprite 1
shape2 - bounding box of sprite 2
Returns:
true, if the sprites is collided one another.
See Also:
collisionSide, sprite1, collisionX1, collisionY1, revertPosition1()

revertPosition1

public void revertPosition1()
Reverts sprite 1 position before the collision occured.


revertPosition2

public void revertPosition2()
Reverts sprite 2 position before the collision occured.


getSprite1

public Sprite getSprite1()
Returns the sprite of current collision from group 1.


getSprite2

public Sprite getSprite2()
Returns the sprite of current collision from group 2.


getCollisionSide

public int getCollisionSide()
Returns collision side of current collision.


printCollisionSide

public void printCollisionSide()
Prints collision side of current collision to console (for debugging).


GTGE API

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