|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Coin
public class Coin
This class represents a coin the player can pick up in the car game. It increases the player's score and time. The lifetime of the coin is measured in ticks. The time and score bonus decrease by specific amounts periodically after a specified number of ticks.
Field Summary | |
---|---|
int |
ID
A unique ID of this coin. |
static double |
LENGTH
The length of every coin will be the same. |
static int |
MAX_ALPHA
Transparency (alpha value) of this coin when displayed right after its creation |
static int |
MAX_SCORE
A maximum score threshold for the purpose of determining display color for a coin. |
static java.awt.Color |
MAX_SCORE_COLOR
The color a coin should have when displayed if its score bonus is above MAX_SCORE |
static int |
MIN_ALPHA
Transparency (alpha value) of this coin when displayed right before its expiration. |
static int |
MIN_SCORE
A minimum score threshold for the purpose of determining display color for a coin. |
static java.awt.Color |
MIN_SCORE_COLOR
The color a coin should have when displayed if its score bonus is below MIN_SCORE |
Constructor Summary | |
---|---|
Coin(double timeBonus,
double timeDecrease,
int scoreBonus,
int scoreDecrease,
long lifetimeInTicks,
double positionOfFront,
double velocity,
long decreasePeriod)
Creates a new coin with specified properties. |
Method Summary | |
---|---|
void |
draw(java.awt.Graphics g,
int x,
int y)
This method paints the coin using the provided Graphics coin g. |
boolean |
equals(java.lang.Object o)
Two coins are equal to each other if and only if their IDs are the same. |
double |
getPositionOfFront()
Returns how far the coin is along the highway. |
double |
getScoreBonus()
Returns the score bonus this coin grants if picked up at the time this method is called. |
long |
getTimeAlive()
Returns how many ticks this coin has been alive. |
double |
getTimeBonus()
Returns the time bonus this coin grants if picked up at the time this method is called. |
double |
getVelocity()
Returns how fast the coin is currently moving. |
boolean |
isExpired()
Indicates whether this coin's lifetime is over. |
void |
tick(double time)
Updates the state of the coin. |
java.lang.String |
toString()
Returns a one-line string with some meaningful easy-to-read description of this coin's properties. |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public int ID
public static double LENGTH
public static final java.awt.Color MAX_SCORE_COLOR
public static final java.awt.Color MIN_SCORE_COLOR
public static final int MIN_SCORE
public static final int MAX_SCORE
public static final int MAX_ALPHA
public static final int MIN_ALPHA
Constructor Detail |
---|
public Coin(double timeBonus, double timeDecrease, int scoreBonus, int scoreDecrease, long lifetimeInTicks, double positionOfFront, double velocity, long decreasePeriod)
timeBonus
- The initial time bonus this coin grants to the playertimeDecrease
- The time bonus is decreased periodically by this
amount after decreasePeriod many ticks.scoreBonus
- The initial score bonus this coin grants to the playerscoreDecrease
- The score bonus is decreased periodically by this
amount after decreasePeriod many ticks.lifetimeInTicks
- The number of ticks for which this coin will
exist.positionOfFront
- The starting position of the front of
this coin on the highway.velocity
- The velocity at which this coin is moving.decreasePeriod
- Number of ticks after which bonuses periodically decrease.Method Detail |
---|
public double getTimeBonus()
public double getScoreBonus()
public long getTimeAlive()
public double getPositionOfFront()
public double getVelocity()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public void tick(double time)
time
- The tick length of the car gamepublic boolean isExpired()
public void draw(java.awt.Graphics g, int x, int y)
g
- The graphics coin where this coin should be painted.x
- The x coordinate where the REAR of the coin should be painted.y
- The y coordinate where the TOP of the coin should be painted.public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |