-
Notifications
You must be signed in to change notification settings - Fork 0
/
Highscore.pde
55 lines (48 loc) · 1.56 KB
/
Highscore.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
/*
Class managing the highscore screen and restart the game
by Flocksserver http://flocksserver.de
*/
class Highscore{
PShape restartButton;
float restartButtonWidth;
float restartButtonHeight;
String restart;
float buttonXLeft;
float buttonXRight;
float buttonYTop;
float buttonYBottom;
public Highscore( ) {
rectMode(CENTER);
init();
}
void init( ) {
restart = "RESTART";
restartButtonWidth = textWidth(restart)*3;
restartButtonHeight = textAscent()*3.5;
restartButton = createShape(RECT, 0, 0, restartButtonWidth, restartButtonHeight, 18);
restartButton.setFill(yellow);
buttonXLeft = (gameWidth/2)-(restartButtonWidth/2);
buttonXRight = (gameWidth/2)+(restartButtonWidth/2);
buttonYTop = (gameHeight-(gameHeight/5))-(restartButtonHeight/2);
buttonYBottom = (gameHeight-(gameHeight/5))+(restartButtonHeight/2);
}
void execute(int score) {
if (isRestartButtonClicked()) {
state = stateGameRestart;
}else{
shape(restartButton, gameWidth/2, gameHeight-(gameHeight/5));
textAlign(CENTER);
textFont(normalFont);
fill(50);
text(restart, gameWidth/2, gameHeight-(gameHeight/5)+(textAscent()/2));
textFont(bigFont);
fill(yellow);
text(score, gameWidth/2, gameHeight/2);
}
}
boolean isRestartButtonClicked(){
boolean isClickInXRange = playerPosX >= buttonXLeft && playerPosX <= buttonXRight;
boolean isClickInYRange = playerPosY >= buttonYTop && playerPosY <= buttonYBottom;
return isClickInXRange && isClickInYRange;
}
}