-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHUD.pde
More file actions
135 lines (122 loc) · 2.92 KB
/
HUD.pde
File metadata and controls
135 lines (122 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class HUD {
int score ;
int scoreForNewLive;
int lives;
int drawShipLiveScale;
int halfDrawShipLiveScale;
HUD() {
reset();
drawShipLiveScale = 16;
halfDrawShipLiveScale = drawShipLiveScale / 2;
}
void addPointsByDestroyAsteroid(float radius) {
if (radius > 90) {
addPoints(20);
} else if (radius > 40) {
addPoints(50);
} else {
addPoints(100);
}
}
void addPoints(int points) {
score += points;
scoreForNewLive += points;
if (scoreForNewLive >= 10000) {
scoreForNewLive = 10000 - scoreForNewLive;
lives++;
}
}
void removeLive() {
if (lives > 0) {
lives--;
}
}
void reset() {
score = 0;
scoreForNewLive = 0;
lives = 3;
}
void update() {
switch (currentGameState) {
case PRESS_START:
{
updatePressStartRender();
}
break;
case PLAYING:
{
updatePlayingRender();
}
break;
case GAME_OVER:
{
updateGameOverRender();
}
break;
}
}
void updatePressStartRender() {
if (shouldDrawHighScores) {
textFont(asteroidFontBig);
stroke(255);
fill(255);
textAlign(CENTER);
text("High Scores", width/2, 100);
textFont(asteroidFontMed);
stroke(255);
fill(255);
textAlign(LEFT);
ArrayList<ScoreData> scores = scoreManager.getScores();
for (int i=0; i < min(10, scores.size()); ++i) {
text(convertToNumericString(i+1, 2) + "." + " " + convertToNumericString(scores.get(i).score, 7) + " - " + scores.get(i).name, width/5, 170 + 40*i);
}
} else {
textFont(asteroidFontBig, 48);
stroke(255);
fill(255);
textAlign(CENTER);
text("Press any key to start", width/2, height/2);
}
}
String convertToNumericString(int amount, int maxSize) {
String retStr = "";
String amountStr = "" + amount;
for (int i = 0; i < maxSize - amountStr.length(); ++i) {
retStr = retStr + "0";
}
retStr = retStr + amountStr;
return retStr;
}
void updatePlayingRender() {
textFont(asteroidFontBig);
textAlign(LEFT);
stroke(255);
fill(255);
text(score, 10, 70);
for (int i = 0; i < lives; i++) {
drawShipAt(20 + i * 20, 100);
}
}
void updateGameOverRender() {
textFont(asteroidFontBig);
stroke(255);
fill(255);
textAlign(CENTER);
text("Your score", width/2, height/3);
textFont(asteroidFontBig, 64);
textAlign(CENTER);
text(this.score, width/2, height/2);
textFont(asteroidFontBig, 64);
textAlign(LEFT);
text(">" + curScoreName, width/4, 100 + height/2);
}
void drawShipAt(int x, int y) {
stroke(155);
noFill();
pushMatrix();
translate(x, y);
rotate(-HALF_PI);
triangle(-halfDrawShipLiveScale, -halfDrawShipLiveScale, drawShipLiveScale/1.2, 0, -halfDrawShipLiveScale, halfDrawShipLiveScale);
popMatrix();
}
}