-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startscreen.pde
53 lines (45 loc) · 1.35 KB
/
Startscreen.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
/*
Class managing the start screen
by Flocksserver http://flocksserver.de
*/
class Startscreen{
PShape startButton;
float startButtonWidth;
float startButtonHeight;
String start;
float buttonXLeft;
float buttonXRight;
float buttonYTop;
float buttonYBottom;
public Startscreen( ) {
rectMode(CENTER);
init();
}
void init( ) {
textFont(normalFont);
start = "START";
startButtonWidth = textWidth(start)*3;
startButtonHeight = textAscent()*3.5;
startButton = createShape(RECT, 0, 0, startButtonWidth, startButtonHeight, 18);
startButton.setFill(yellow);
buttonXLeft = (gameWidth/2)-(startButtonWidth/2);
buttonXRight = (gameWidth/2)+(startButtonWidth/2);
buttonYTop = (gameHeight/2)-(startButtonHeight/2);
buttonYBottom = (gameHeight/2)+(startButtonHeight/2);
}
void execute() {
if (isStartButtonClicked()) {
state = stateGameRunning;
}else{
shape(startButton, gameWidth/2, gameHeight/2);
textAlign(CENTER);
fill(50);
text(start, gameWidth/2, gameHeight/2+(textAscent()/2));
}
}
boolean isStartButtonClicked(){
boolean isClickInXRange = playerPosX >= buttonXLeft && playerPosX <= buttonXRight;
boolean isClickInYRange = playerPosY >= buttonYTop && playerPosY <= buttonYBottom;
return isClickInXRange && isClickInYRange;
}
}