/
GameOver.pde
99 lines (77 loc) · 2.19 KB
/
GameOver.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
class GameOverState extends State {
MainGame main;
String mainMessage;
String subMessage;
GameOverState(MainGame main, String mainMessage, String subMessage) {
this.main = main;
this.mainMessage = mainMessage;
this.subMessage = subMessage;
}
void draw() {
main.draw();
textAlign(CENTER, TOP);
textSize(40);
color outline = color(255,255,255);
color fill = color(255,0,0);
textWithOutline(mainMessage, width/2, 200, outline, fill);
textSize(20);
textWithOutline(subMessage, width/2, 240, outline, fill);
outline = color(0,0,0);
fill = color(255,255,255);
textSize(20);
textWithOutline("Try again (Y/N)?", width/2, 280, outline, fill);
}
void keyPressed() {
if(key == 'y' || key == 'Y') {
changeState(new MainGame());
} else if(key == 'n' || key == 'N') {
changeState(new IntroState());
}
}
}
class EnterNameState extends State {
MainGame main;
TypedInput input;
GameOverState nextState;
EnterNameState(MainGame main, GameOverState nextState) {
this.main = main;
this.nextState = nextState;
}
void setup() {
input = new TypedInput();
input.setup();
textSize(24);
input.x = 20 + (int)textWidth("Your name?");
input.y = 30 + 40 + 10;
}
void draw() {
main.draw();
textAlign(LEFT, TOP);
textSize(36);
color outline = color(255,255,255);
color fill = color(255,0,0);
textWithOutline("You made a new highscore: " + main.score, 10, 30, outline, fill);
fill(color(0,0,0));
textSize(24);
text("Your name?", 10, input.y);
input.draw();
}
void keyPressed() {
input.keyPressed();
if(input.done) {
highscore.add(main.score, input.text);
highscore.save();
changeState(nextState);
}
}
}
class GameOverWonState extends GameOverState {
GameOverWonState(MainGame main, int numberOfEnemies) {
super(main, "YOU WON!", "The cute platypus outsmarted "+numberOfEnemies+" crocodiles!");
}
}
class GameOverLostState extends GameOverState {
GameOverLostState(MainGame main, Enemy e) {
super(main, "GAME OVER", "The poor platypus was eaten by "+e.name+"!");
}
}