com.threecoffee.util
Class Gravity

java.lang.Object
  extended by java.lang.Thread
      extended by com.threecoffee.util.Gravity
All Implemented Interfaces:
java.lang.Runnable

public class Gravity
extends java.lang.Thread

Simple class to imitate the action of Gravity.

Author:
Divyansh Prakash

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Gravity(Sprite s, double bounce)
          Sets gravity on the given Sprite.
 
Method Summary
 void bounce()
          Bounces the Sprite vertically.
 double getAcceleration()
          Returns the acceleration of the Sprite due to gravity.
 double getBounce()
          Returns the fraction of energy maintained after every bounce.
 long getDelay()
          Returns the time difference in ms between successive Gravity updates.
 double getVel()
          Returns the velocity of the Sprite due to gravity.
 boolean isPaused()
          Returns true if this Gravity object is paused.
 void pause(boolean b)
          Pauses this Gravity object.
 void run()
          Called by the System internally.
 void setAcceleration(double a)
          Sets the vertical acceleration of the Sprite due to this Gravity object.
 void setBounce(double b)
          Sets the fraction of energy maintained after every bounce.
 void setDelay(long d)
          Sets the time difference in ms between successive Gravity updates.
 void setVel(double v)
          Sets the vertical velocity of the Sprite controlled by this Gravity object.
 void toggleGravity()
          Used by the System internally.
 void update()
          Called in every iteration of the Gravity loop.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Gravity

public Gravity(Sprite s,
               double bounce)
Sets gravity on the given Sprite. For normal purposes, use the Sprite.setGravity(boolean) method.

Parameters:
bounce - A value typically between 0 and 1.
Method Detail

setDelay

public void setDelay(long d)
Sets the time difference in ms between successive Gravity updates.


getDelay

public long getDelay()
Returns the time difference in ms between successive Gravity updates.


getBounce

public double getBounce()
Returns the fraction of energy maintained after every bounce.


setBounce

public void setBounce(double b)
Sets the fraction of energy maintained after every bounce.


getVel

public double getVel()
Returns the velocity of the Sprite due to gravity.


setVel

public void setVel(double v)
Sets the vertical velocity of the Sprite controlled by this Gravity object.


setAcceleration

public void setAcceleration(double a)
Sets the vertical acceleration of the Sprite due to this Gravity object.


getAcceleration

public double getAcceleration()
Returns the acceleration of the Sprite due to gravity.


run

public final void run()
Called by the System internally. Call the start() method to start this Gravity object.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

update

public void update()
Called in every iteration of the Gravity loop.


bounce

public void bounce()
Bounces the Sprite vertically.


pause

public void pause(boolean b)
Pauses this Gravity object.


isPaused

public boolean isPaused()
Returns true if this Gravity object is paused.


toggleGravity

public void toggleGravity()
Used by the System internally. Use pause() method instead.