added "card_shuffled" and "card_played" sounds

dev
Jonah Bauer 3 years ago
parent c5debe13e8
commit f8ef429a9c

@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen; import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen;
import eu.jonahbauer.wizard.client.libgdx.util.SavedData; import eu.jonahbauer.wizard.client.libgdx.util.SavedData;
import eu.jonahbauer.wizard.client.libgdx.util.SoundManager;
import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager;
import lombok.Getter; import lombok.Getter;
@ -19,6 +20,8 @@ public class WizardGame extends Game {
public SpriteBatch batch; public SpriteBatch batch;
public WizardAssetManager assets; public WizardAssetManager assets;
public SoundManager sounds;
public final SavedData storage = new SavedData(); public final SavedData storage = new SavedData();
private boolean fullscreenToggle; private boolean fullscreenToggle;
@ -35,6 +38,8 @@ public class WizardGame extends Game {
assets.loadShared(); assets.loadShared();
assets.finishLoading(); assets.finishLoading();
sounds = new SoundManager(assets);
// background music // background music
Music backgroundMusic = assets.get(WizardAssetManager.MUSIC_BACKGROUND, Music.class); Music backgroundMusic = assets.get(WizardAssetManager.MUSIC_BACKGROUND, Music.class);
backgroundMusic.setLooping(true); backgroundMusic.setLooping(true);
@ -77,6 +82,7 @@ public class WizardGame extends Game {
@Override @Override
public void dispose () { public void dispose () {
batch.dispose(); batch.dispose();
sounds.dispose();
assets.dispose(); assets.dispose();
client.shutdownNow(); client.shutdownNow();
var socket = client.getSocket(); var socket = client.getSocket();

@ -0,0 +1,21 @@
package eu.jonahbauer.wizard.client.libgdx.listeners;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.util.SoundManager;
public class ButtonClickListener extends ChangeListener {
private final SoundManager sounds;
public ButtonClickListener(SoundManager sounds) {
this.sounds = sounds;
}
@Override
public void changed(ChangeEvent event, Actor actor) {
if (actor instanceof Button) {
sounds.sfxClick();
}
}
}

@ -29,7 +29,6 @@ public class ConnectScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonBack) { if (actor == buttonBack) {
game.getClient().execute(Menu.class, Menu::showMenuScreen); game.getClient().execute(Menu.class, Menu::showMenuScreen);
sfxClick();
} else if (actor == buttonConnect) { } else if (actor == buttonConnect) {
try { try {
var uriString = ConnectScreen.this.uriField.getText(); var uriString = ConnectScreen.this.uriField.getText();
@ -39,8 +38,6 @@ public class ConnectScreen extends MenuScreen {
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
uriField.setStyle(getTextFieldErrorStyle()); uriField.setStyle(getTextFieldErrorStyle());
} }
sfxClick();
} }
} }
}; };

@ -31,10 +31,8 @@ public class CreateGameScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonBack) { if (actor == buttonBack) {
game.getClient().execute(Lobby.class, Lobby::showListScreen); game.getClient().execute(Lobby.class, Lobby::showListScreen);
sfxClick();
} else if (actor == buttonContinue) { } else if (actor == buttonContinue) {
create(); create();
sfxClick();
} }
} }
}; };

@ -18,7 +18,6 @@ public class ErrorScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonBack) { if (actor == buttonBack) {
game.getClient().execute(BaseState.class, BaseState::dismissErrorScreen); game.getClient().execute(BaseState.class, BaseState::dismissErrorScreen);
sfxClick();
} }
} }
}; };

@ -22,10 +22,7 @@ import eu.jonahbauer.wizard.client.libgdx.actors.CardsGroup;
import eu.jonahbauer.wizard.client.libgdx.actors.PadOfTruth; import eu.jonahbauer.wizard.client.libgdx.actors.PadOfTruth;
import eu.jonahbauer.wizard.client.libgdx.state.Game; import eu.jonahbauer.wizard.client.libgdx.state.Game;
import eu.jonahbauer.wizard.client.libgdx.state.Session; import eu.jonahbauer.wizard.client.libgdx.state.Session;
import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings; import eu.jonahbauer.wizard.client.libgdx.util.*;
import eu.jonahbauer.wizard.client.libgdx.util.CardUtil;
import eu.jonahbauer.wizard.client.libgdx.util.Pair;
import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager;
import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage;
import eu.jonahbauer.wizard.common.model.Card; import eu.jonahbauer.wizard.common.model.Card;
import lombok.Getter; import lombok.Getter;
@ -421,6 +418,13 @@ public class GameScreen extends WizardScreen {
execute(new StartRoundOverlay(this, round)); execute(new StartRoundOverlay(this, round));
} }
public void deal() {
execute(parallel(
run(() -> game.sounds.sfxShuffle()),
delay(SoundManager.CARD_SHUFFLE_DURATION)
));
}
public void startTrick() { public void startTrick() {
clearActivePlayer(); clearActivePlayer();
execute(() -> cardStack.clearChildren()); execute(() -> cardStack.clearChildren());
@ -531,6 +535,8 @@ public class GameScreen extends WizardScreen {
cardStack.add(seat, actor); cardStack.add(seat, actor);
sequence.addAction(delay(actor)); sequence.addAction(delay(actor));
sequence.addAction(delay(AnimationTimings.STACK_HOLD)); sequence.addAction(delay(AnimationTimings.STACK_HOLD));
game.sounds.sfxPlayCard();
})); }));
execute(sequence); execute(sequence);
} }

@ -31,15 +31,12 @@ public class InstructionScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonBack) { if (actor == buttonBack) {
game.getClient().execute(Menu.class, Menu::showMenuScreen); game.getClient().execute(Menu.class, Menu::showMenuScreen);
sfxClick();
} else if (actor == nextPageButton) { } else if (actor == nextPageButton) {
currentPage = MathUtils.clamp(currentPage + 1, 0, MAX_PAGE); currentPage = MathUtils.clamp(currentPage + 1, 0, MAX_PAGE);
showPage(currentPage); showPage(currentPage);
sfxClick();
} else if (actor == previousPageButton) { } else if (actor == previousPageButton) {
currentPage = MathUtils.clamp(currentPage - 1, 0, MAX_PAGE); currentPage = MathUtils.clamp(currentPage - 1, 0, MAX_PAGE);
showPage(currentPage); showPage(currentPage);
sfxClick();
} }
} }
}; };

@ -1,6 +1,5 @@
package eu.jonahbauer.wizard.client.libgdx.screens; package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.WizardGame;

@ -37,17 +37,14 @@ public class LobbyScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonBack) { if (actor == buttonBack) {
game.getClient().execute(Lobby.class, Lobby::disconnect); game.getClient().execute(Lobby.class, Lobby::disconnect);
sfxClick();
} else if (actor == buttonJoin) { } else if (actor == buttonJoin) {
if (rejoin) { if (rejoin) {
game.getClient().execute(Lobby.class, Lobby::showRejoinScreen); game.getClient().execute(Lobby.class, Lobby::showRejoinScreen);
} else { } else {
join(); join();
} }
sfxClick();
} else if (actor == buttonCreate) { } else if (actor == buttonCreate) {
game.getClient().execute(Lobby.class, Lobby::showCreateScreen); game.getClient().execute(Lobby.class, Lobby::showCreateScreen);
sfxClick();
} }
} }
}; };

@ -23,13 +23,10 @@ public class MainMenuScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonPlay) { if (actor == buttonPlay) {
game.getClient().execute(Menu.class, Menu::showConnectScreen); game.getClient().execute(Menu.class, Menu::showConnectScreen);
sfxClick();
} else if (actor == buttonQuit) { } else if (actor == buttonQuit) {
sfxClick();
Gdx.app.exit(); Gdx.app.exit();
} else if (actor == buttonInstruction) { } else if (actor == buttonInstruction) {
game.getClient().execute(Menu.class, Menu::showInstructionScreen); game.getClient().execute(Menu.class, Menu::showInstructionScreen);
sfxClick();
} }
} }
}; };

@ -26,10 +26,8 @@ public class RejoinScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonBack) { if (actor == buttonBack) {
game.getClient().execute(Lobby.class, Lobby::showListScreen); game.getClient().execute(Lobby.class, Lobby::showListScreen);
sfxClick();
} else if (actor == buttonContinue) { } else if (actor == buttonContinue) {
rejoin(); rejoin();
sfxClick();
} }
} }
}; };

@ -31,10 +31,8 @@ public class SessionScreen extends MenuScreen {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (actor == buttonLeave) { if (actor == buttonLeave) {
game.getClient().execute(Session.class, Session::leave); game.getClient().execute(Session.class, Session::leave);
sfxClick();
} else if (actor == buttonReady) { } else if (actor == buttonReady) {
game.getClient().execute(Session.class, Session::toggleReady); game.getClient().execute(Session.class, Session::toggleReady);
sfxClick();
} }
} }
}; };

@ -2,7 +2,6 @@ package eu.jonahbauer.wizard.client.libgdx.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
@ -16,6 +15,7 @@ import com.badlogic.gdx.utils.viewport.Viewport;
import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas; import eu.jonahbauer.wizard.client.libgdx.UiskinAtlas;
import eu.jonahbauer.wizard.client.libgdx.WizardGame; import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.listeners.AutoFocusListener; import eu.jonahbauer.wizard.client.libgdx.listeners.AutoFocusListener;
import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonClickListener;
import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonKeyListener; import eu.jonahbauer.wizard.client.libgdx.listeners.ButtonKeyListener;
import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager; import eu.jonahbauer.wizard.client.libgdx.util.WizardAssetManager;
import org.jetbrains.annotations.MustBeInvokedByOverriders; import org.jetbrains.annotations.MustBeInvokedByOverriders;
@ -31,7 +31,6 @@ public abstract class WizardScreen implements Screen {
protected Viewport viewport; protected Viewport viewport;
private Image background; private Image background;
private Sound sfxClick;
protected float offsetX; protected float offsetX;
protected float offsetY; protected float offsetY;
@ -56,11 +55,10 @@ public abstract class WizardScreen implements Screen {
stage = new Stage(viewport); stage = new Stage(viewport);
stage.addListener(new ButtonKeyListener()); stage.addListener(new ButtonKeyListener());
stage.addListener(new AutoFocusListener()); stage.addListener(new AutoFocusListener());
stage.addListener(new ButtonClickListener(game.sounds));
stage.setDebugAll(WizardGame.DEBUG); stage.setDebugAll(WizardGame.DEBUG);
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
sfxClick = assets.get(WizardAssetManager.SFX_CLICK);
} }
@Override @Override
@ -110,8 +108,4 @@ public abstract class WizardScreen implements Screen {
public void dispose() { public void dispose() {
stage.dispose(); stage.dispose();
} }
protected void sfxClick() {
sfxClick.play(0.6f);
}
} }

@ -117,6 +117,7 @@ public final class Game extends BaseState {
case "starting_round" -> { case "starting_round" -> {
return onStartRound(client); return onStartRound(client);
} }
case "dealing" -> onDealing();
case "starting_trick" -> onStartTrick(); case "starting_trick" -> onStartTrick();
case "juggling" -> onJuggle(); case "juggling" -> onJuggle();
case "finishing_round" -> onFinishingRound(); case "finishing_round" -> onFinishingRound();
@ -189,6 +190,10 @@ public final class Game extends BaseState {
return Optional.empty(); return Optional.empty();
} }
private void onDealing() {
if (gameScreen != null) gameScreen.deal();
}
private void onStartTrick() { private void onStartTrick() {
log.info("Trick {} is starting...", trick + 1); log.info("Trick {} is starting...", trick + 1);
trick ++; trick ++;

@ -0,0 +1,47 @@
package eu.jonahbauer.wizard.client.libgdx.util;
import com.badlogic.gdx.audio.Sound;
import lombok.Setter;
public class SoundManager {
public static final float CARD_SHUFFLE_DURATION = 4.2f;
private final WizardAssetManager assets;
@Setter
private float sfxVolume = 1;
private final Sound click;
private final Sound cardPlayed;
private final Sound cardShuffle;
public SoundManager(WizardAssetManager assets) {
this.assets = assets;
assets.load(WizardAssetManager.SFX_CLICK, Sound.class);
assets.load(WizardAssetManager.SFX_CARD_PLAYED, Sound.class);
assets.load(WizardAssetManager.SFX_CARD_SHUFFLE, Sound.class);
assets.finishLoading();
this.click = assets.get(WizardAssetManager.SFX_CLICK);
this.cardPlayed = assets.get(WizardAssetManager.SFX_CARD_PLAYED);
this.cardShuffle = assets.get(WizardAssetManager.SFX_CARD_SHUFFLE);
}
public void sfxClick() {
this.click.play(sfxVolume);
}
public void sfxShuffle() {
this.cardShuffle.play(sfxVolume);
}
public void sfxPlayCard() {
this.cardPlayed.play(sfxVolume);
}
public void dispose() {
assets.unload(WizardAssetManager.SFX_CLICK);
assets.unload(WizardAssetManager.SFX_CARD_PLAYED);
assets.unload(WizardAssetManager.SFX_CARD_SHUFFLE);
}
}

@ -4,7 +4,6 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.I18NBundleLoader; import com.badlogic.gdx.assets.loaders.I18NBundleLoader;
import com.badlogic.gdx.assets.loaders.SkinLoader; import com.badlogic.gdx.assets.loaders.SkinLoader;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
@ -20,7 +19,9 @@ public class WizardAssetManager {
public static final String ATLAS_SKIN = UiskinAtlas.$PATH; public static final String ATLAS_SKIN = UiskinAtlas.$PATH;
public static final String ATLAS_GAME = GameAtlas.$PATH; public static final String ATLAS_GAME = GameAtlas.$PATH;
public static final String SFX_CLICK = "button_click_s.mp3"; public static final String SFX_CLICK = "sound/button_click.mp3";
public static final String SFX_CARD_PLAYED = "sound/card_played.mp3";
public static final String SFX_CARD_SHUFFLE = "sound/card_shuffle.mp3";
public static final String MUSIC_BACKGROUND = "background.mp3"; public static final String MUSIC_BACKGROUND = "background.mp3";
public static final String CURSOR = "cursor.png"; public static final String CURSOR = "cursor.png";
@ -35,7 +36,6 @@ public class WizardAssetManager {
manager.load(SKIN, Skin.class, new SkinLoader.SkinParameter(ATLAS_SKIN)); manager.load(SKIN, Skin.class, new SkinLoader.SkinParameter(ATLAS_SKIN));
manager.load(MUSIC_BACKGROUND, Music.class); manager.load(MUSIC_BACKGROUND, Music.class);
manager.load(SFX_CLICK, Sound.class);
} }
public void loadGame() { public void loadGame() {

Loading…
Cancel
Save