diff --git a/Makefile b/Makefile index 707ba97..fa4337b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ game.jar: clean find src/ -type f -name '*.java' -print0 | xargs -0 javac -cp src/ -d compiled/ cp -r res/* compiled/ echo 'Main-Class: de.teamteamteam.spacescooter.Main' >compiled/manifest.txt - jar cvfe game.jar 'de.teamteamteam.spacescooter.Main' -C compiled de -C compiled images + jar cvfe game.jar 'de.teamteamteam.spacescooter.Main' -C compiled de -C compiled images -C compiled sounds run: game.jar java -jar game.jar diff --git a/res/sounds/abgang.wav b/res/sounds/abgang.wav new file mode 100644 index 0000000..6f8ffa3 Binary files /dev/null and b/res/sounds/abgang.wav differ diff --git a/src/de/teamteamteam/spacescooter/Main.java b/src/de/teamteamteam/spacescooter/Main.java index 3515619..b1ffae2 100644 --- a/src/de/teamteamteam/spacescooter/Main.java +++ b/src/de/teamteamteam/spacescooter/Main.java @@ -29,6 +29,7 @@ public class Main { GameConfig.windowWidth = 800; GameConfig.windowHeight = 600; + //Instantiate the GameFrame final GameFrame gameFrame = new GameFrame(); //Initialize SuperScreen and add to GameFrame, so we can call doPaint() on it. diff --git a/src/de/teamteamteam/spacescooter/utility/Loader.java b/src/de/teamteamteam/spacescooter/utility/Loader.java index a1c5f7a..5cad2a8 100644 --- a/src/de/teamteamteam/spacescooter/utility/Loader.java +++ b/src/de/teamteamteam/spacescooter/utility/Loader.java @@ -1,23 +1,40 @@ package de.teamteamteam.spacescooter.utility; import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.util.Hashtable; import javax.imageio.ImageIO; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.UnsupportedAudioFileException; import de.teamteamteam.spacescooter.screen.LoadingScreen; +/** + * This Loader prefetches all required resources for the Game, such as images or + * sounds. + */ public class Loader { + /** + * HashTable containing loaded BufferedImages + */ private static Hashtable images; + /** + * HashTable containing loaded AudioInputStreams + */ + private static Hashtable sounds; + static { Loader.images = new Hashtable(); + Loader.sounds = new Hashtable(); } - + /** * Private constructor, this class will never be instantiated. */ @@ -25,7 +42,7 @@ public class Loader { /** - * Return the loaded BufferedImage by its filename. + * Return the loaded BufferedImage by its relative filename. */ public static BufferedImage getBufferedImageByFilename(String filename) { if(CodeEnvironment.isJar()) { @@ -34,9 +51,21 @@ public class Loader { return Loader.images.get(filename.replace("/", File.separator)); } } - + /** - * Perform the initial loading of everything and show the progress on the given LoadingScreen. + * Return the loaded AudioInputStream by its relative filename. + */ + public static AudioInputStream getAudioInputStreamByFilename(String filename) { + if(CodeEnvironment.isJar()) { + return Loader.sounds.get(filename); + } else { + return Loader.sounds.get(filename.replace("/", File.separator)); + } + } + + /** + * Perform the initial loading of everything and show the progress on the + * given LoadingScreen. */ public static void load(LoadingScreen loadingScreen) { // get a list of stuff to load and create buffered images @@ -46,15 +75,21 @@ public class Loader { for(int i=0; i