Coverage Summary for Class: SoundFX (com.mozarellabytes.kroy.Utilities)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
SoundFX | 100% (1/ 1) | 14.3% (1/ 7) | 40.6% (13/ 32) |
1 package com.mozarellabytes.kroy.Utilities;
2
3 import com.badlogic.gdx.Gdx;
4 import com.badlogic.gdx.audio.Music;
5 import com.badlogic.gdx.audio.Sound;
6
7 /**
8 * Sound Effects Manager for all in-game audio, accessed via static context.
9 * All Music and SoundFX can be enabled/disabled with the StopMusic/PlayMusic.
10 */
11
12 public class SoundFX {
13
14 /** Used only for the truck attacking sound. True if it is playing, false if it isn't */
15 public static boolean isPlaying = false;
16
17 /** All sounds can be played when this is true, else no sound will play */
18 public static boolean music_enabled = true;
19
20 public static final Music sfx_menu = Gdx.audio.newMusic(Gdx.files.internal("sounds/menu.mp3"));
21 public static final Music sfx_soundtrack = Gdx.audio.newMusic(Gdx.files.internal("sounds/soundtrack.mp3"));
22
23 public static final Sound sfx_truck_attack = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/truck_attack.wav"));
24 public static final Sound sfx_truck_damage = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/truck_damage.wav"));
25 public static final Sound sfx_truck_spawn = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/truck_spawn.wav"));
26 public static final Sound sfx_fortress_destroyed = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/fortress_destroyed.wav"));
27 public static final Sound sfx_fortress_attack = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/fortress_attack.wav"));
28 public static final Sound sfx_pause = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/pause.wav"));
29 public static final Sound sfx_unpause = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/unpause.wav"));
30 public static final Sound sfx_horn = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/horn.mp3"));
31 public static final Sound sfx_button_clicked = Gdx.audio.newSound(Gdx.files.internal("sounds/sfx/button_clicked.wav"));
32
33 /** Plays attacking sound for FireTrucks only if it isn't already playing */
34 public static void playTruckAttack() {
35 if (!isPlaying) {
36 sfx_truck_attack.loop();
37 sfx_truck_attack.play();
38 isPlaying = true;
39 }
40 }
41
42 /** Stops the sound of FireTrucks attacking and resets isPlaying to false */
43 public static void stopTruckAttack() {
44 sfx_truck_attack.stop();
45 isPlaying = false;
46 }
47 /** Plays game music */
48 public static void playGameMusic() {
49 sfx_soundtrack.play();
50 music_enabled = true;
51 }
52
53 /** Plays menu music */
54 public static void playMenuMusic() {
55 sfx_menu.play();
56 music_enabled = true;
57 }
58
59 /** Stops both menu music and game music */
60 public static void stopMusic() {
61 sfx_soundtrack.stop();
62 sfx_menu.stop();
63 music_enabled = false;
64 }
65
66 }