Game Development Reference
In-Depth Information
4.3 Scoring System
The idea of scoring is simple. Whenever the player picks up any bonus such as nut, cherry,
or gift box on the map, he/she is rewarded with points to add to his/her score. Different types
of bonuses stand for different points. In the project Raccoon Rob, nut, cherry, and gift box
stand for 1, 5, and 20 points respectively. Collect 2 gift boxes on each level to get passed.
Let's see its implementation:
Displaying Points
We use a class
Score
and 2 methods
drawScore(), drawNumber()
to display points whenever
the player picks up any bonus on the map.
/*
* This class encapsulates all members & methods of Score.
* Designed for displaying points on the screen whenever the
* player picks up any bonus.
*/
public class
Score {
int
x
;
int
y
;
int
score
;
int
imgid
;
//Each tick is 100ms, the object of Score will be
//removed from Array after 15 ticks
int
tick
;
//Constructor: creates a instance of Score
//Parameters:
// score - the score to be displayed
// imgid - the specified image id
// x - x position of the left side of the bitmap being drawn
// y - y position of the top side of the bitmap being drawn
public
Score(
int
score,
int
imgid,
int
x,
int
y){
this
.
score
= score;
this
.
imgid
= imgid;
this
.
x
= x;
this
.
y
= y;
}
Search WWH ::
Custom Search