com.golden.gamedev.object
Class CollisionRect

java.lang.Object
  |
  +--com.golden.gamedev.object.CollisionRect

public class CollisionRect
extends Object

Almost equal with java.awt.Rectangle, but use some optimized method. This class is created to optimize collision detection, because collision detection is heavily used in game.

CollisionRect is the sprite bounding box. A sprite bounding box is checked its intersection with other sprite bounding box to determine is the collision occured or not.


Field Summary
 int height
           
 int width
           
 int x
           
 int y
           
 
Constructor Summary
CollisionRect()
           
 
Method Summary
 int getHeight()
           
 int getWidth()
           
 int getX()
           
 int getY()
           
 void grow(int h, int v)
           
 void intersection(CollisionRect r, CollisionRect iRect)
           
 boolean intersects(CollisionRect rect)
           
 void move(int dx, int dy)
           
 void setBounds(CollisionRect rect)
           
 void setBounds(int x1, int y1, int w1, int h1)
           
 void shrink(int h, int v)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x

y

public int y

width

public int width

height

public int height
Constructor Detail

CollisionRect

public CollisionRect()
Method Detail

grow

public void grow(int h,
                 int v)

shrink

public void shrink(int h,
                   int v)

intersects

public boolean intersects(CollisionRect rect)

setBounds

public void setBounds(int x1,
                      int y1,
                      int w1,
                      int h1)

setBounds

public void setBounds(CollisionRect rect)

move

public void move(int dx,
                 int dy)

getX

public int getX()

getY

public int getY()

getWidth

public int getWidth()

getHeight

public int getHeight()

intersection

public void intersection(CollisionRect r,
                         CollisionRect iRect)

toString

public String toString()
Overrides:
toString in class Object