Coverage Summary for Class: MenuScreen (com.mozarellabytes.kroy.Screens)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
MenuScreen | 0% (0/ 1) | 0% (0/ 15) | 0% (0/ 94) |
1 package com.mozarellabytes.kroy.Screens;
2
3 import com.badlogic.gdx.*;
4 import com.badlogic.gdx.graphics.GL20;
5 import com.badlogic.gdx.graphics.OrthographicCamera;
6 import com.badlogic.gdx.graphics.Texture;
7 import com.badlogic.gdx.math.Rectangle;
8 import com.mozarellabytes.kroy.Kroy;
9 import com.mozarellabytes.kroy.Utilities.MenuInputHandler;
10 import com.mozarellabytes.kroy.Utilities.SoundFX;
11
12 /** This screen is shown after the splash screen and is
13 * where the player can choose to start the game or view
14 * the control screen */
15 public class MenuScreen implements Screen {
16
17 /** The game */
18 private final Kroy game;
19 public final OrthographicCamera camera;
20
21 /** The menu screen image - see ui/menuscreen_blank_2 */
22 private final Texture backgroundImage;
23
24 /** Rectangle containing the position of the play button */
25 private final Rectangle startButton;
26
27 /** Texture of the start button when it has not been clicked */
28 private final Texture startIdleTexture;
29
30 /** Texture of the start button when has been clicked */
31 private final Texture startClickedTexture;
32
33 /** Contains the current state of the start button:
34 * startIdleTexture if the start button is not being pressed,
35 * startClickedTexture if the start button has been pressed */
36 private Texture currentStartTexture;
37
38
39 /** Rectangle containing the position of the control button */
40 private final Rectangle controlsButton;
41
42 /** Texture of the control button when it has not been clicked */
43 private final Texture controlsIdleTexture;
44
45 /** Texture of the control button when has been clicked */
46 private final Texture controlsClickedTexture;
47
48 /** Contains the current state of the control button:
49 * controlsIdleTexture if the control button is not being pressed,
50 * controlsClickedTexture if the control button has been pressed */
51 private Texture currentControlsTexture;
52
53 /** Rectangle containing the position of the sound button */
54 private final Rectangle soundButton;
55
56 /** Texture of the sound on button when it has not been clicked */
57 private final Texture soundOnIdleTexture;
58
59 /** Texture of the sound off button when it has not been clicked */
60 private final Texture soundOffIdleTexture;
61
62 /** Texture of the sound on button when it has been clicked */
63 private final Texture soundOnClickedTexture;
64
65 /** Texture of the sound off button when it has been clicked */
66 private final Texture soundOffClickedTexture;
67 private Texture currentSoundTexture;
68
69 /** Constructs the MenuScreen
70 *
71 * @param game LibGdx game
72 */
73 public MenuScreen(final Kroy game) {
74 this.game = game;
75
76 camera = new OrthographicCamera();
77 camera.setToOrtho(false, Gdx.graphics.getDisplayMode().width, Gdx.graphics.getDisplayMode().height);
78
79 backgroundImage = new Texture(Gdx.files.internal("menuscreen_blank_2.png"), true);
80 backgroundImage.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
81
82 startIdleTexture = new Texture(Gdx.files.internal("ui/start_idle.png"), true);
83 startIdleTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
84 startClickedTexture = new Texture(Gdx.files.internal("ui/start_clicked.png"), true);
85 startClickedTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
86
87 controlsIdleTexture = new Texture(Gdx.files.internal("ui/controls_idle.png"), true);
88 controlsIdleTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
89 controlsClickedTexture = new Texture(Gdx.files.internal("ui/controls_clicked.png"), true);
90 controlsClickedTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
91
92 soundOnIdleTexture = new Texture(Gdx.files.internal("ui/sound_on_idle.png"), true);
93 soundOnIdleTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
94 soundOffIdleTexture = new Texture(Gdx.files.internal("ui/sound_off_idle.png"), true);
95 soundOffIdleTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
96 soundOnClickedTexture = new Texture(Gdx.files.internal("ui/sound_on_clicked.png"), true);
97 soundOnClickedTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
98 soundOffClickedTexture = new Texture(Gdx.files.internal("ui/sound_off_clicked.png"), true);
99 soundOffClickedTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.MipMapLinearNearest);
100
101 MenuInputHandler ih = new MenuInputHandler(this);
102
103 if (SoundFX.music_enabled) {
104 SoundFX.sfx_menu.setLooping(true);
105 SoundFX.sfx_menu.play();
106 currentSoundTexture = soundOffIdleTexture;
107 } else {
108 currentSoundTexture = soundOnIdleTexture;
109 }
110
111 currentStartTexture = startIdleTexture;
112 currentControlsTexture = controlsIdleTexture;
113
114 startButton = new Rectangle();
115 startButton.width = (float) (currentStartTexture.getWidth()*0.75);
116 startButton.height = (float) (currentStartTexture.getHeight()*0.75);
117 startButton.x = (int) (camera.viewportWidth/2 - startButton.width/2);
118 startButton.y = (int) ((camera.viewportHeight/2 - startButton.height/2) * 0.8);
119
120 controlsButton = new Rectangle();
121 controlsButton.width = (float) (currentControlsTexture.getWidth()*0.75);
122 controlsButton.height = (float) (currentControlsTexture.getHeight()*0.75);
123 controlsButton.x = (int) (camera.viewportWidth/2 - controlsButton.width/2);
124 controlsButton.y = (int) ((camera.viewportHeight/2 - controlsButton.height/2)*0.4);
125
126 soundButton = new Rectangle();
127 soundButton.width = 50;
128 soundButton.height = 50;
129 soundButton.x = camera.viewportWidth - soundButton.getWidth() - 5;
130 soundButton.y = camera.viewportHeight - soundButton.getHeight() - 5;
131
132 Gdx.input.setInputProcessor(ih);
133
134 }
135
136 @Override
137 public void show() {
138
139 }
140
141 /** Renders the menu screen consisting of the background and the start, controls and sound buttons.
142 *
143 * @param delta The time in seconds since the last render.
144 */
145 @Override
146 public void render(float delta) {
147 Gdx.gl.glClearColor(51/255f, 34/255f, 99/255f, 1);
148 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
149
150 camera.update();
151
152 game.batch.setProjectionMatrix(camera.combined);
153
154 game.batch.begin();
155 game.batch.draw(backgroundImage, 0, 0, camera.viewportWidth, camera.viewportHeight);
156 game.batch.draw(currentStartTexture, startButton.x, startButton.y, startButton.width, startButton.height);
157 game.batch.draw(currentControlsTexture, controlsButton.x, controlsButton.y, controlsButton.width, controlsButton.height);
158 game.batch.draw(currentSoundTexture, soundButton.x, soundButton.y, soundButton.width, soundButton.height);
159 game.batch.end();
160
161 }
162
163 @Override
164 public void resize(int width, int height) {
165
166 }
167
168 @Override
169 public void pause() {
170
171 }
172
173 @Override
174 public void resume() {
175
176 }
177
178 @Override
179 public void hide() {
180
181 }
182
183 /** Called when this screen should release all resources. */
184 @Override
185 public void dispose() {
186 backgroundImage.dispose();
187 currentStartTexture.dispose();
188 startClickedTexture.dispose();
189 startIdleTexture.dispose();
190 currentControlsTexture.dispose();
191 controlsClickedTexture.dispose();
192 controlsIdleTexture.dispose();
193 currentSoundTexture.dispose();
194 soundOnIdleTexture.dispose();
195 soundOnClickedTexture.dispose();
196 soundOffIdleTexture.dispose();
197 soundOffClickedTexture.dispose();
198 SoundFX.sfx_menu.stop();
199 }
200
201 /** Changes the screen from menu screen to game screen */
202 public void toGameScreen() {
203 game.setScreen(new GameScreen(game));
204 this.dispose();
205 }
206
207 /** Changes the texture of the start button when it has been clicked on */
208 public void clickedStartButton() {
209 if (SoundFX.music_enabled){
210 SoundFX.sfx_button_clicked.play();
211 }
212 currentStartTexture = startClickedTexture;
213 }
214
215 /** Changes the texture of the controls button when it has been clicked on */
216 public void clickedControlsButton() {
217 if (SoundFX.music_enabled){
218 SoundFX.sfx_button_clicked.play();
219 }
220 currentControlsTexture = controlsClickedTexture;
221 }
222
223 /** Changes the texture of the sound button when it has been clicked on */
224 public void clickedSoundButton() {
225 if (SoundFX.music_enabled){
226 currentSoundTexture = soundOffClickedTexture;
227 } else {
228 currentSoundTexture = soundOnClickedTexture;
229 }
230 }
231
232 /** Turns the sound on and off and changes the sound icon accordingly,
233 * turns the sound off in the sound was on and turns the sound on if the
234 * sound was off */
235 public void changeSound() {
236 if (SoundFX.music_enabled){
237 currentSoundTexture = soundOnIdleTexture;
238 SoundFX.stopMusic();
239 } else {
240 currentSoundTexture = soundOffIdleTexture;
241 SoundFX.playMenuMusic();
242 }
243 }
244
245 /** The texture of the start button when it has not been clicked on */
246 public void idleStartButton() {
247 currentStartTexture = startIdleTexture;
248 }
249
250 /** The texture of the control button when it has not been clicked on */
251 public void idleControlsButton() {
252 currentControlsTexture = controlsIdleTexture;
253 }
254
255 /** The texture of the sound button when it has not been clicked on */
256 public void idleSoundButton() {
257 if (SoundFX.music_enabled){
258 currentSoundTexture = soundOffIdleTexture;
259 } else {
260 currentSoundTexture = soundOnIdleTexture;
261 }
262 }
263
264 /** Changes the screen from the menu screen to the control screen */
265 public void toControlScreen(){ game.setScreen(new ControlsScreen(game, this, "menu")); }
266
267 public Rectangle getStartButton() { return startButton; }
268
269 public Rectangle getControlsButton() { return controlsButton; }
270
271 public Rectangle getSoundButton() {return soundButton; }
272 }