-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameTrans.pde
118 lines (94 loc) · 2.8 KB
/
GameTrans.pde
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
/**
* Draws a round transition to the screen when the round is finished
*
* Should call `.update()` at the end of the draw function
*/
public class GameTrans extends Obj {
public int start_games_y = 200;
public boolean transOut = false;
public boolean alreadyTransitioned = false;
public final int space_btn_y = 850;
public final int game_over_y = 700;
public void _update() {
if (v.roundNum != v.roundMax) { alreadyTransitioned = false; v.transitioning = false; return; }
if (alreadyTransitioned) { return; }
if (v.games[v.game-1] == null) {
Game g = new Game();
g.totalCorrect = v.totalCorrect;
g.currStreak = v.currStreak;
g.highestStreak = v.highestStreak;
g.score = v.score;
v.games[v.game-1] = g;
}
// Show the rounds
// Transition in
v.transitioning = true;
if (!transOut) {
transitionIn.update();
} else {
transitionOut.update();
fill(255, transitionOut.opacity);
drawGames();
if (transitionOut.done) {
// Then update the roundNum variable
// and reset the transition classes
alreadyTransitioned = true;
transOut = false;
v.roundNum = 1;
v.game++;
transitionIn.reset();
transitionOut.reset();
}
}
if (transitionIn.done && !transOut) {
fill(255);
drawGames();
if (v.game >= v.games_max) {
drawGameOver();
} else {
drawSpaceBtn();
}
v.totalCorrect = 0;
v.currStreak = 0;
v.highestStreak = 0;
v.score = 0;
v.transitioning = false;
}
}
private void drawGames() {
textSize(32);
// White text
for(int i =0; i<v.game; i++) {
Game g = v.games[i];
String space = " ";
// ! Rico asks that they are called rounds
// Though interally the rounds are called games
// because the variable name round is allready used
String s = "Round : " + (i+1) +
space + "Score: " + g.score +
space + "Correct: " + g.totalCorrect +
space + "Highest Streak: " + g.highestStreak;
textAlign(CENTER);
int y = start_games_y + i * 50;
text(s, v.cw, y);
}
}
private void drawSpaceBtn() {
// TODO: Draw the space btn
image(a.space, v.cw, space_btn_y);
textSize(20);
text("Press space to continue!", v.cw, space_btn_y + 100);
}
private void drawGameOver() {
textSize(50);
text("Thanks for playing!", v.cw, game_over_y);
}
public void keyPressed() {
// If the spacebar is pressed when the transitionIn is done begin to transiton out
// and the game is not over
if (!(v.game >= v.games_max )&& v.roundNum == v.roundMax && transitionIn.done && key == ' ') {
transOut = true;
}
}
public GameTrans(Assets a, Variables v) { super(a, v); }
}