mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:29:45 +02:00
added some audio improvements
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package de.heatup.audio;
|
||||||
|
|
||||||
|
public class AudioFiles {
|
||||||
|
|
||||||
|
//base path
|
||||||
|
private static final String basePath = "src/de/heatup/resources/audio/";
|
||||||
|
|
||||||
|
//sound files
|
||||||
|
private String Invaders;
|
||||||
|
private String YouGetNothing;
|
||||||
|
|
||||||
|
public AudioFiles() {
|
||||||
|
|
||||||
|
//set paths
|
||||||
|
this.Invaders = basePath + "8bitinvaders.wav";
|
||||||
|
this.YouGetNothing = basePath + "yougetnothing.wav";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInvaders() {
|
||||||
|
return this.Invaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getYouGetNothing() {
|
||||||
|
return this.YouGetNothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ public class AudioPlayer {
|
|||||||
|
|
||||||
public AudioPlayer() {}
|
public AudioPlayer() {}
|
||||||
|
|
||||||
|
/** plays a file once */
|
||||||
public void play(String file) {
|
public void play(String file) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -38,4 +39,33 @@ public class AudioPlayer {
|
|||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** loops every given file */
|
||||||
|
public void loop(String file) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
final Clip clip = (Clip)AudioSystem.getLine(new Line.Info(Clip.class));
|
||||||
|
clip.addLineListener(new LineListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(LineEvent event) {
|
||||||
|
if(event.getType() == LineEvent.Type.STOP)
|
||||||
|
clip.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
File f = new File(file);
|
||||||
|
if(!f.exists()) {
|
||||||
|
System.out.println("File not found: " + f.getAbsolutePath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clip.open(AudioSystem.getAudioInputStream(f));
|
||||||
|
clip.loop(clip.LOOP_CONTINUOUSLY);
|
||||||
|
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SoundfileBomb b = new SoundfileBomb();
|
AudioFiles f = new AudioFiles();
|
||||||
|
|
||||||
AudioPlayer p = new AudioPlayer();
|
AudioPlayer p = new AudioPlayer();
|
||||||
p.play(b.getPath());
|
//p.loop(f.getInvaders());
|
||||||
|
p.play(f.getYouGetNothing());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package de.heatup.audio;
|
|
||||||
|
|
||||||
public class SoundfileBomb {
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
public SoundfileBomb() {
|
|
||||||
this.path = "src/de/heatup/resources/audio/" + "bomb.wav";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return this.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package de.heatup.audio;
|
|
||||||
|
|
||||||
public class SoundfileInvaders {
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
public SoundfileInvaders() {
|
|
||||||
this.path = "src/de/heatup/resources/audio/" + "8bitinvaders.wav";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return this.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -13,8 +13,8 @@ import java.awt.Point;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import de.heatup.audio.AudioFiles;
|
||||||
import de.heatup.audio.AudioPlayer;
|
import de.heatup.audio.AudioPlayer;
|
||||||
import de.heatup.audio.SoundfileInvaders;
|
|
||||||
import de.heatup.cfg.Config;
|
import de.heatup.cfg.Config;
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
import de.heatup.mapengine.CollisionHandler;
|
import de.heatup.mapengine.CollisionHandler;
|
||||||
@@ -129,9 +129,12 @@ public class Main extends JFrame implements Runnable {
|
|||||||
actionPanel.setVisible(true);
|
actionPanel.setVisible(true);
|
||||||
statusPanel.setVisible(true);
|
statusPanel.setVisible(true);
|
||||||
|
|
||||||
SoundfileInvaders bgsound = new SoundfileInvaders();
|
/**
|
||||||
|
* muss noch in den ClasLoader, loop für background sound geht
|
||||||
|
*/
|
||||||
|
AudioFiles f = new AudioFiles();
|
||||||
AudioPlayer p = new AudioPlayer();
|
AudioPlayer p = new AudioPlayer();
|
||||||
p.play(bgsound.getPath());
|
p.loop(f.getInvaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user