-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
159 lines (138 loc) · 5.69 KB
/
Menu.java
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package game.menu;
import game.*;
import game.waves.RainbowText;
import util.Random;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.function.Consumer;
import java.util.stream.Stream;
public class Menu extends GameLevel.Unending { // the main menu, has buttons that stay available on the other menus
private Theme space, water, dvd;
private Random.RandomDifferentElement<Color> fireworkColor;
private MenuButton.MuteButton mute;
public Menu(Menu m) {
super(m);
space = m.space;
water = m.water;
dvd = m.dvd;
fireworkColor = m.fireworkColor;
mute = m.mute;
}
public Menu(GameLevel g) {
super(g);
space = new Theme("space", getTheme());
water = new Theme("water", getTheme());
dvd = new Theme("dvd", space);
System.out.println("Loading themes...");
Stream.of(space, water, dvd).parallel().forEach(Runnable::run); // still not fast enough >:L
setTheme(space);
fireworkColor = getRandom().new RandomDifferentElement<>(RainbowText.rainbow);
mute = new Button.MuteButton(20, 900, 100, 100, this);
}
private void resetTheme(Theme t) { // change the current theme
getState().forEach(s -> s.setTheme(t));
getState().peek().setClipped(true);
}
private static class Button extends MenuButton.TextButton {
public Button(double x, double y, GameLevel level, Consumer<Player> c, String t, Font f) {
super(x, y, level, c, t, f);
}
@Override
public void collide(Player p) {
if(p == null) {
super.collide(p);
}
}
}
@Override
public void tick() {
super.tick();
if(getClass() == Menu.class) { // like a static final method, see the constructor of java.util.Random
Font f = new Font("Amoebic", Font.BOLD, 130);
final Button // buttons to navigate the menu
back = new Button(100, 250, this, p -> {
getState().clear();
getState().push(this);
}, "<", f),
next = new Button(300, 250, this, p -> {
getState().peek().end();
}, ">", f),
help = new Button(1620, 250, this, p -> {
if(getState().peek().getClass() != Help.class) {
getState().peek().setMaxTick(15);
Help h = new Help(this);
getState().push(new Transition(this, h, this));
getState().push(h);
getState().push(new Transition(this, this, h));
}
else {
getState().peek().end();
}
}, "?", f),
exit = new Button(1820, 250, this, p -> {
System.exit(0);
}, "X", f);
getEntities().clear();
getEntities().add(back);
getEntities().add(next);
getEntities().add(help);
getEntities().add(exit);
getEntities().add(mute); // maybe all the buttons should be instance variables...
f = new Font("Amoebic", Font.BOLD, 70);
getEntities().add(new Button(1300, 1060, this, p -> resetTheme(space), "Space", f));
getEntities().add(new Button(1565, 1060, this, p -> resetTheme(water), "Water", f));
getEntities().add(new Button(1800, 1060, this, p -> resetTheme(dvd), "DVD", f));
setClipped(false);
GameLevel // the components of the menu
input = new GameInput(this),
avatar = new GameAvatar(this),
mode = new GameMode(this),
over = new GameOver(this);
setMaxTick(40);
getState().push(over);
getState().push(mode);
getState().push(Transition.Slide.horizontal(this).apply(avatar, mode));
getState().push(avatar);
getState().push(Transition.Slide.horizontal(this).apply(input, avatar));
getState().push(input);
getState().peek().setClipped(true);
}
if(getEntities().stream().noneMatch(Fireworks.class::isInstance)) { // spawn a new firework after the last one is gone
getEntities().add(new Fireworks(
getRandom().nextInt(getDimension().width),
getDimension().getHeight(),
this,
fireworkColor.get()
));
}
}
@Override
public void render(Graphics g) {
super.render(g);
getEntities().forEach(b -> b.render(g));
g.setColor(Color.white);
GameWindow.drawStringCentered(g, new Font("Amoebic", Font.BOLD, 130), "Wavegame", 960, 275);
Font f = new Font("Amoebic", Font.BOLD, 34);
GameWindow.drawStringCentered(g, f, "Credits: Team", 120, 1070);
int shake = getRandom().nextInt(3);
int blake = getRandom().nextInt(2);
GameWindow.drawStringCentered(g, f,"Shakey", 300 + shake, 1070 + blake);
GameWindow.drawStringCentered(g, f,"Blakey", 420, 1070);
}
@Override
public void render(Clip c, int i) {
super.render(c,i);
((FloatControl)c.getControl(FloatControl.Type.MASTER_GAIN)).setValue(mute.getVolume());
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
for (int i = getEntities().size() - 1; i >= 0; i -= 1) {
if (getEntities().get(i).getBounds().contains(e.getPoint())) {
getEntities().get(i).collide(null);
}
}
}
}