Add sound
This commit is contained in:
@@ -2,13 +2,11 @@
|
||||
|
||||
import com.jme3.audio.AudioNode;
|
||||
import com.jme3.system.NanoTimer;
|
||||
import pp.mdga.client.Board.Asset;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.client.MdgaState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
public class AcousticHandler {
|
||||
private MdgaApp app;
|
||||
@@ -26,13 +24,15 @@ public class AcousticHandler {
|
||||
private GameMusic playing = null;
|
||||
private NanoTimer fadeTimer = new NanoTimer();
|
||||
private float fadeVolume = 1.0f;
|
||||
private final float FADE_DURATION = 3.0f; // Sekunden für das Fading
|
||||
private final float CROSSFADE_DURATION = 1.0f; // Zeit, in der beide Tracks gleichzeitig spielen
|
||||
private final float FADE_DURATION = 3.0f;
|
||||
private final float CROSSFADE_DURATION = 1.5f;
|
||||
|
||||
private float mainVolume = 1.0f;
|
||||
private float musicVolume = 1.0f;
|
||||
private float soundVolume = 1.0f;
|
||||
|
||||
private ArrayList<GameSound> sounds = new ArrayList<>();
|
||||
|
||||
public AcousticHandler(MdgaApp app) {
|
||||
this.app = app;
|
||||
}
|
||||
@@ -55,6 +55,35 @@ public void update() {
|
||||
if(playGame) {
|
||||
updateGameTracks();
|
||||
}
|
||||
|
||||
Iterator<GameSound> iterator = sounds.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
GameSound s = iterator.next();
|
||||
if (!s.isPlaying()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playSound(Sound sound) {
|
||||
ArrayList<SoundAsset> assets = new ArrayList<SoundAsset>();
|
||||
switch (sound) {
|
||||
case LOST:
|
||||
assets.add(SoundAsset.LOST);
|
||||
break;
|
||||
case VICTORY:
|
||||
assets.add(SoundAsset.VICTORY);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
for (SoundAsset a : assets) {
|
||||
GameSound gameSound = new GameSound(app, a, getSoundVolume() * getMainVolume());
|
||||
gameSound.play();
|
||||
sounds.add(gameSound);
|
||||
}
|
||||
}
|
||||
|
||||
public void playState(MdgaState state) {
|
||||
@@ -86,7 +115,7 @@ public void playState(MdgaState state) {
|
||||
|
||||
assert(null != asset) : "music sceduling went wrong";
|
||||
|
||||
scheduled = new GameMusic(app, asset.getPath(), getMusicVolume() * getMainVolume(), asset.getLoop());
|
||||
scheduled = new GameMusic(app, asset, getMusicVolume() * getMainVolume(), asset.getLoop());
|
||||
}
|
||||
|
||||
private float lerp(float start, float end, float t) {
|
||||
@@ -160,7 +189,7 @@ private void updateGameTracks() {
|
||||
|
||||
MusicAsset nextTrack = gameTracks.remove(0);
|
||||
|
||||
scheduled = new GameMusic(app, nextTrack.getPath(), getMusicVolume() * getMainVolume(), nextTrack.getLoop());
|
||||
scheduled = new GameMusic(app, nextTrack, getMusicVolume() * getMainVolume(), nextTrack.getLoop());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ public class GameMusic {
|
||||
private float volume;
|
||||
private AudioNode music;
|
||||
|
||||
GameMusic(MdgaApp app, String path, float volume, boolean loop) {
|
||||
GameMusic(MdgaApp app, MusicAsset asset, float volume, boolean loop) {
|
||||
this.app = app;
|
||||
this.volume = volume;
|
||||
|
||||
loadMusic(path);
|
||||
loadMusic(asset.getPath());
|
||||
|
||||
music.setLooping(loop);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,39 @@
|
||||
package pp.mdga.client.Acoustic;
|
||||
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
import com.jme3.audio.AudioSource;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public class GameSound {
|
||||
|
||||
private final MdgaApp app;
|
||||
|
||||
private float volume;
|
||||
private SoundAsset asset;
|
||||
|
||||
private AudioNode sound;
|
||||
|
||||
GameSound(MdgaApp app, SoundAsset asset, float volume) {
|
||||
this.app = app;
|
||||
this.volume = volume;
|
||||
|
||||
loadMusic(asset.getPath());
|
||||
}
|
||||
|
||||
void play() {
|
||||
sound.play();
|
||||
}
|
||||
|
||||
boolean isPlaying() {
|
||||
return sound != null && sound.getStatus() == AudioSource.Status.Playing;
|
||||
}
|
||||
|
||||
private void loadMusic(String path) {
|
||||
sound = new AudioNode(app.getAssetManager(), path, AudioData.DataType.Buffer);
|
||||
sound.setVolume(volume);
|
||||
sound.setPositional(false);
|
||||
sound.setDirectional(false);
|
||||
sound.setLooping(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package pp.mdga.client.Acoustic;
|
||||
|
||||
public enum MusicAsset {
|
||||
enum MusicAsset {
|
||||
MAIN_MENU("Spaceship.wav"),
|
||||
LOBBY("DeadPlanet.wav"),
|
||||
CEREMONY("80s,Disco,Life.wav"),
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package pp.mdga.client.Acoustic;
|
||||
|
||||
public enum Sound {
|
||||
DICE_ROLL,
|
||||
TURN_START,
|
||||
TURN_END,
|
||||
PIECE_END,
|
||||
PIECE_MOVE,
|
||||
PIECE_LOST,
|
||||
SELECT,
|
||||
DESELECT,
|
||||
HURRY,
|
||||
VICTORY,
|
||||
LOST;
|
||||
}
|
||||
@@ -1,4 +1,25 @@
|
||||
package pp.mdga.client.Acoustic;
|
||||
|
||||
public enum SoundAsset {
|
||||
enum SoundAsset {
|
||||
DICE_ROLL(""),
|
||||
TURN_START(""),
|
||||
TURN_END(""),
|
||||
PIECE_END(""),
|
||||
PIECE_MOVE(""),
|
||||
PIECE_LOST(""),
|
||||
SELECT(""),
|
||||
DESELECT(""),
|
||||
HURRY(""),
|
||||
VICTORY("LevelUp2.wav"),
|
||||
LOST("GameOver.wav");
|
||||
|
||||
private final String path;
|
||||
|
||||
SoundAsset(String name) {
|
||||
this.path = "sound/" + name;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package pp.mdga.client.Board;
|
||||
|
||||
public class BoardCamera {
|
||||
}
|
||||
@@ -22,15 +22,12 @@ public class BoardView {
|
||||
private ArrayList<NodeControl> infield = new ArrayList<NodeControl>(40);
|
||||
private ArrayList<PieceControl> pieces;
|
||||
|
||||
public BoardView(int playerCount, MdgaApp mdgaApp) {
|
||||
assert(2 <= playerCount && playerCount <= 4) : "invalid player count";
|
||||
public BoardView(MdgaApp mdgaApp) {
|
||||
assert(mdgaApp != null) : "app is null";
|
||||
|
||||
|
||||
this.mdgaApp = mdgaApp;
|
||||
|
||||
pieces = new ArrayList<PieceControl>(4 * playerCount);
|
||||
|
||||
pieces = new ArrayList<PieceControl>(4 * 4);
|
||||
|
||||
initMap();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
package pp.mdga.client.Dialog;
|
||||
|
||||
public class DialogView {
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public class DialogView {
|
||||
private MdgaApp app;
|
||||
|
||||
private DialogManager dialogManager = new DialogManager(app);
|
||||
|
||||
private MainMenuDialog dialog;
|
||||
|
||||
public DialogView(MdgaApp app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
DialogManager getDialogManager() {
|
||||
return dialogManager;
|
||||
}
|
||||
|
||||
public void mainMenu() {
|
||||
//dialogManager = new DialogManager(app);
|
||||
//di
|
||||
//MainMenuDialog mainMenuDialog = new MainMenuDialog(app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
package pp.mdga.client.Dialog;
|
||||
|
||||
public class MainMenuDialog {
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.dialog.SimpleDialog;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
|
||||
public class MainMenuDialog extends SimpleDialog {
|
||||
MainMenuDialog(MdgaApp app) {
|
||||
super(app.getDialogView().getDialogManager());
|
||||
|
||||
Checkbox serverHost = new Checkbox("sdgfsdg");
|
||||
serverHost.setChecked(false);
|
||||
//serverHost.addClickCommands(s -> toggleServerHost());
|
||||
|
||||
final Container input = new Container(new SpringGridLayout());
|
||||
input.addChild(new Label("sdgsgsdg"));
|
||||
//input.addChild(host, 1);
|
||||
input.addChild(new Label("sdfdsgsdgsdg"));
|
||||
//input.addChild(port, 1);
|
||||
input.addChild(serverHost);
|
||||
|
||||
DialogBuilder.simple(app.getDialogView().getDialogManager())
|
||||
.setTitle("server.dialog")
|
||||
.setOkButton("button.connect")
|
||||
.setNoButton("button.cancel")
|
||||
.setOkClose(false)
|
||||
.setNoClose(false)
|
||||
.build(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.system.NanoTimer;
|
||||
import pp.mdga.client.Acoustic.AcousticHandler;
|
||||
import pp.mdga.client.Acoustic.Sound;
|
||||
import pp.mdga.client.Animation.AnimationHandler;
|
||||
import com.jme3.light.AmbientLight;
|
||||
import com.jme3.light.DirectionalLight;
|
||||
@@ -17,6 +18,7 @@
|
||||
import pp.mdga.client.Board.AssetOnMap;
|
||||
import pp.mdga.client.Board.BoardView;
|
||||
import pp.mdga.client.Board.MapLoader;
|
||||
import pp.mdga.client.Dialog.DialogView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,6 +26,7 @@ public class MdgaApp extends SimpleApplication {
|
||||
private AnimationHandler animationHandler;
|
||||
private AcousticHandler acousticHandler;
|
||||
private BoardView boardView;
|
||||
private DialogView dialogView;
|
||||
|
||||
NanoTimer test = new NanoTimer();
|
||||
private MdgaState testState = MdgaState.MAIN;
|
||||
@@ -45,9 +48,14 @@ public static void main(String[] args) {
|
||||
public void simpleInitApp() {
|
||||
animationHandler = new AnimationHandler(this);
|
||||
acousticHandler = new AcousticHandler(this);
|
||||
boardView = new BoardView(4,this);
|
||||
boardView = new BoardView(this);
|
||||
dialogView = new DialogView(this);
|
||||
|
||||
acousticHandler.playState(MdgaState.GAME);
|
||||
//dialogView.mainMenu();
|
||||
//acousticHandler.playState(MdgaState.GAME);
|
||||
|
||||
acousticHandler.playSound(Sound.LOST);
|
||||
acousticHandler.playSound(Sound.VICTORY);
|
||||
|
||||
flyCam.setEnabled(true);
|
||||
int zoom = 20;
|
||||
@@ -73,7 +81,7 @@ public void simpleInitApp() {
|
||||
public void simpleUpdate(float tpf) {
|
||||
acousticHandler.update();
|
||||
|
||||
test.reset();
|
||||
//test.reset();
|
||||
if(test.getTimeInSeconds() > 10){
|
||||
if(testState == MdgaState.MAIN) {
|
||||
testState = MdgaState.LOBBY;
|
||||
@@ -102,4 +110,8 @@ public AcousticHandler getAcousticHandler() {
|
||||
public BoardView getBoardView() {
|
||||
return boardView;
|
||||
}
|
||||
|
||||
public DialogView getDialogView() {
|
||||
return dialogView;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Projekte/mdga/client/src/main/resources/sound/GameOver.wav
Normal file
BIN
Projekte/mdga/client/src/main/resources/sound/GameOver.wav
Normal file
Binary file not shown.
BIN
Projekte/mdga/client/src/main/resources/sound/LevelUp2.wav
Normal file
BIN
Projekte/mdga/client/src/main/resources/sound/LevelUp2.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user