-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_screen.pde
59 lines (50 loc) · 1.76 KB
/
start_screen.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
/*
* start_screen.pde
*
* The initial screen presented to the user
*
* Created on: January 12, 2020
* Author: Sean LaPlante
*/
class StartScreen {
/*
* Contains buttons for play, settings, etc.
*/
Button playButton;
Button newGameButton;
StartScreen() {
float buttonHeight = width * 0.15;
float buttonWidth = width / 1.5;
float halfWidth = buttonWidth / 2;
float halfHeight = buttonHeight / 2;
float xPos = (width / 2) - halfWidth;
float yPos = (height / 2) - halfHeight;
float buttonPadding = buttonHeight / 3;
playButton = new Button("CONTINUE", xPos, yPos, buttonWidth, buttonHeight, BUTTON_RADIUS);
newGameButton = new Button("NEW GAME", xPos, yPos + buttonHeight + buttonPadding, buttonWidth, buttonHeight, BUTTON_RADIUS);
}
void display() {
/*
* Called on each iteration of the draw loop
* to display the start screen in GameState.START_SCREEN
*/
pushMatrix();
playButton.display();
newGameButton.display();
popMatrix();
}
void handleInput(InputType input) {
/*
* Called to handle any input that
* happened while on this screen
*/
if (input == InputType.TOUCH_END && playButton.onButton(mouseX, mouseY)) {
println("Continue game");
currentState = GameState.PLAYING; // Set the game state to playing
} else if (input == InputType.TOUCH_END && newGameButton.onButton(mouseX, mouseY)) {
println("New game");
gameOver();
currentState = GameState.PLAYING; // Set the game state to playing
}
}
}