autostart main theme
This commit is contained in:
@@ -23,17 +23,19 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
// WORLD SETTINGS
|
// WORLD SETTINGS
|
||||||
public final int maxWorldCol = 50;
|
public final int maxWorldCol = 50;
|
||||||
public final int maxWorldRow = 50;
|
public final int maxWorldRow = 50;
|
||||||
public final int worldWidth = tileSize * maxWorldCol;
|
|
||||||
public final int worldHeight = tileSize * maxWorldRow;
|
|
||||||
|
|
||||||
//FPS
|
//FPS
|
||||||
int FPS = 60;
|
int FPS = 60;
|
||||||
|
|
||||||
|
// SYSTEM
|
||||||
TileManager tileM = new TileManager(this);
|
TileManager tileM = new TileManager(this);
|
||||||
KeyHandler keyH = new KeyHandler();
|
KeyHandler keyH = new KeyHandler();
|
||||||
|
Sound sound = new Sound();
|
||||||
Thread gameThread;
|
Thread gameThread;
|
||||||
public CollisionHandler collisionH = new CollisionHandler(this);
|
public CollisionHandler collisionH = new CollisionHandler(this);
|
||||||
public AssetSetter assetSetter = new AssetSetter(this);;
|
public AssetSetter assetSetter = new AssetSetter(this);;
|
||||||
|
|
||||||
|
// ENTITY AND OBJECT
|
||||||
public Player player = new Player(this, keyH);
|
public Player player = new Player(this, keyH);
|
||||||
public SuperObject[] obj = new SuperObject[10];
|
public SuperObject[] obj = new SuperObject[10];
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
|
|
||||||
public void setupGame() {
|
public void setupGame() {
|
||||||
assetSetter.setObject();
|
assetSetter.setObject();
|
||||||
|
playMusic(0); //Play main theme
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGameThread() {
|
public void startGameThread() {
|
||||||
@@ -98,4 +101,19 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
graphics.dispose();
|
graphics.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void playMusic(int i) {
|
||||||
|
sound.setFile(i);
|
||||||
|
sound.play();
|
||||||
|
sound.loop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopMusic() {
|
||||||
|
sound.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playSE(int i) {
|
||||||
|
sound.setFile(i);
|
||||||
|
sound.play();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
49
src/de/miaurizius/jgame2d/core/Sound.java
Normal file
49
src/de/miaurizius/jgame2d/core/Sound.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.Clip;
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class Sound {
|
||||||
|
|
||||||
|
Clip clip;
|
||||||
|
URL[] soundURL = new URL[30];
|
||||||
|
|
||||||
|
public Sound() {
|
||||||
|
try {
|
||||||
|
soundURL[0] = new File("assets/sounds/BlueBoyAdventure.wav").toURI().toURL();
|
||||||
|
soundURL[1] = new File("assets/sounds/coin.wav").toURI().toURL();
|
||||||
|
soundURL[2] = new File("assets/sounds/powerup.wav").toURI().toURL();
|
||||||
|
soundURL[3] = new File("assets/sounds/unlock.wav").toURI().toURL();
|
||||||
|
soundURL[4] = new File("assets/sounds/fanfare.wav").toURI().toURL();
|
||||||
|
} catch(MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFile(int i) {
|
||||||
|
try {
|
||||||
|
AudioInputStream ais = AudioSystem.getAudioInputStream(soundURL[i]);
|
||||||
|
clip = AudioSystem.getClip();
|
||||||
|
clip.open(ais);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play() {
|
||||||
|
clip.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loop() {
|
||||||
|
clip.loop(Clip.LOOP_CONTINUOUSLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
clip.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user