summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/Audio.java18
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/Map.java24
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapMusicType.java27
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java11
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java22
5 files changed, 93 insertions, 9 deletions
diff --git a/src/com/fourisland/fourpuzzle/Audio.java b/src/com/fourisland/fourpuzzle/Audio.java index 5fe0dfc..3e40e6a 100755 --- a/src/com/fourisland/fourpuzzle/Audio.java +++ b/src/com/fourisland/fourpuzzle/Audio.java
@@ -5,7 +5,6 @@
5 5
6package com.fourisland.fourpuzzle; 6package com.fourisland.fourpuzzle;
7 7
8import com.fourisland.fourpuzzle.util.MidiParser;
9import com.fourisland.fourpuzzle.util.ObjectLoader; 8import com.fourisland.fourpuzzle.util.ObjectLoader;
10import java.util.concurrent.Executor; 9import java.util.concurrent.Executor;
11import java.util.concurrent.Executors; 10import java.util.concurrent.Executors;
@@ -14,6 +13,7 @@ import java.util.logging.Logger;
14import javax.sound.midi.InvalidMidiDataException; 13import javax.sound.midi.InvalidMidiDataException;
15import javax.sound.midi.MidiSystem; 14import javax.sound.midi.MidiSystem;
16import javax.sound.midi.MidiUnavailableException; 15import javax.sound.midi.MidiUnavailableException;
16import javax.sound.midi.Sequence;
17import javax.sound.midi.Sequencer; 17import javax.sound.midi.Sequencer;
18import javax.sound.sampled.Clip; 18import javax.sound.sampled.Clip;
19 19
@@ -64,8 +64,16 @@ public class Audio {
64 64
65 public static void playMusic(String file, boolean loop, float speed) 65 public static void playMusic(String file, boolean loop, float speed)
66 { 66 {
67 Sequence s = ObjectLoader.getMusic(file);
68
69 if ((seq.getSequence() != null) && (seq.getSequence().equals(s)))
70 {
71 return;
72 }
73
67 try { 74 try {
68 seq.setSequence(ObjectLoader.getMusic(file)); 75 seq.setSequence(s);
76 seq.setTickPosition(0);
69 77
70 if (loop) { 78 if (loop) {
71 seq.setLoopCount(seq.LOOP_CONTINUOUSLY); 79 seq.setLoopCount(seq.LOOP_CONTINUOUSLY);
@@ -86,6 +94,12 @@ public class Audio {
86 if (seq != null) 94 if (seq != null)
87 { 95 {
88 seq.stop(); 96 seq.stop();
97
98 try {
99 seq.setSequence((Sequence) null);
100 } catch (InvalidMidiDataException ex) {
101 Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex);
102 }
89 } 103 }
90 } 104 }
91 105
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index d02c7ed..bb40b39 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java
@@ -182,9 +182,31 @@ public abstract class Map {
182 { 182 {
183 return music; 183 return music;
184 } 184 }
185 public void setMusic(String music) 185
186 /**
187 * Sets the name of the Music file to play when this Map loads
188 *
189 * When this function is run, it also sets the MusicType to Specified
190 * automatically as the only time this function would be used would be when
191 * the MusicType was Specified.
192 *
193 * @param music
194 */
195 protected void setMusic(String music)
186 { 196 {
187 this.music = music; 197 this.music = music;
198 this.musicType = MapMusicType.Specified;
199 }
200
201 private MapMusicType musicType = MapMusicType.NoChange;
202 public MapMusicType getMusicType()
203 {
204 return musicType;
205 }
206
207 protected void setMusicType(MapMusicType musicType)
208 {
209 this.musicType = musicType;
188 } 210 }
189 211
190 BufferedImage lowerLayer = null; 212 BufferedImage lowerLayer = null;
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapMusicType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapMusicType.java new file mode 100644 index 0000000..52fd712 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapMusicType.java
@@ -0,0 +1,27 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8/**
9 *
10 * @author hatkirby
11 */
12public enum MapMusicType {
13 /**
14 * NoMusic represents the instance where no Music should be played
15 */
16 NoMusic,
17 /**
18 * NoChange represents the instance where the currently playing Music (or
19 * silence) should be kept
20 */
21 NoChange,
22 /**
23 * Specified represents the instance where a specified Music file should be
24 * played
25 */
26 Specified
27}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 9924c9e..52a56c4 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -50,18 +50,17 @@ public class MapViewGameState implements GameState {
50 50
51 public void initalize() 51 public void initalize()
52 { 52 {
53 //if (!currentMap.getMusic().equals("")) 53 switch (currentMap.getMusicType())
54 { 54 {
55 // Audio.playMusic(currentMap.getMusic()); 55 case NoMusic: Audio.stopMusic(); break;
56 case NoChange: break;
57 case Specified: Audio.playMusic(currentMap.getMusic()); break;
56 } 58 }
57 } 59 }
58 60
59 public void deinitalize() 61 public void deinitalize()
60 { 62 {
61 //if (!currentMap.getMusic().equals("")) 63 // Do nothing, yet
62 {
63 Audio.stopMusic();
64 }
65 } 64 }
66 65
67 public void processInput() 66 public void processInput()
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 22e464d..7ca08ff 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -298,4 +298,26 @@ public class SpecialEvent {
298 })); 298 }));
299 } 299 }
300 300
301 /**
302 * Starts playing a Music file
303 *
304 * @param filename The name of the Music file to play
305 * @param loop Whether or not you want this Music to loop
306 * @param speed The Tempo Factor. If this is 1, the Music will play at
307 * normal speed. If this is 2, the Music will play at twice the normal
308 * speed, and so on.
309 */
310 public void PlayMusic(String filename, boolean loop, float speed)
311 {
312 Audio.playMusic(filename, loop, speed);
313 }
314
315 /**
316 * Stops playing the currently playing Music file
317 */
318 public void StopMusic()
319 {
320 Audio.stopMusic();
321 }
322
301} 323}