added "card_shuffled" and "card_played" sounds
This commit is contained in:
parent
8bec81c556
commit
bd0a3e091a
@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import eu.jonahbauer.wizard.client.libgdx.screens.MainMenuScreen;
|
||||
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 lombok.Getter;
|
||||
|
||||
@ -19,6 +20,8 @@ public class WizardGame extends Game {
|
||||
|
||||
public SpriteBatch batch;
|
||||
public WizardAssetManager assets;
|
||||
public SoundManager sounds;
|
||||
|
||||
public final SavedData storage = new SavedData();
|
||||
|
||||
private boolean fullscreenToggle;
|
||||
@ -35,6 +38,8 @@ public class WizardGame extends Game {
|
||||
assets.loadShared();
|
||||
assets.finishLoading();
|
||||
|
||||
sounds = new SoundManager(assets);
|
||||
|
||||
// background music
|
||||
Music backgroundMusic = assets.get(WizardAssetManager.MUSIC_BACKGROUND, Music.class);
|
||||
backgroundMusic.setLooping(true);
|
||||
@ -77,6 +82,7 @@ public class WizardGame extends Game {
|
||||
@Override
|
||||
public void dispose () {
|
||||
batch.dispose();
|
||||
sounds.dispose();
|
||||
assets.dispose();
|
||||
client.shutdownNow();
|
||||
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) {
|
||||
if (actor == buttonBack) {
|
||||
game.getClient().execute(Menu.class, Menu::showMenuScreen);
|
||||
sfxClick();
|
||||
} else if (actor == buttonConnect) {
|
||||
try {
|
||||
var uriString = ConnectScreen.this.uriField.getText();
|
||||
@ -39,8 +38,6 @@ public class ConnectScreen extends MenuScreen {
|
||||
} catch (URISyntaxException e) {
|
||||
uriField.setStyle(getTextFieldErrorStyle());
|
||||
}
|
||||
|
||||
sfxClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -31,10 +31,8 @@ public class CreateGameScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonBack) {
|
||||
game.getClient().execute(Lobby.class, Lobby::showListScreen);
|
||||
sfxClick();
|
||||
} else if (actor == buttonContinue) {
|
||||
create();
|
||||
sfxClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -18,7 +18,6 @@ public class ErrorScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonBack) {
|
||||
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.state.Game;
|
||||
import eu.jonahbauer.wizard.client.libgdx.state.Session;
|
||||
import eu.jonahbauer.wizard.client.libgdx.util.AnimationTimings;
|
||||
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.client.libgdx.util.*;
|
||||
import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage;
|
||||
import eu.jonahbauer.wizard.common.model.Card;
|
||||
import lombok.Getter;
|
||||
@ -421,6 +418,13 @@ public class GameScreen extends WizardScreen {
|
||||
execute(new StartRoundOverlay(this, round));
|
||||
}
|
||||
|
||||
public void deal() {
|
||||
execute(parallel(
|
||||
run(() -> game.sounds.sfxShuffle()),
|
||||
delay(SoundManager.CARD_SHUFFLE_DURATION)
|
||||
));
|
||||
}
|
||||
|
||||
public void startTrick() {
|
||||
clearActivePlayer();
|
||||
execute(() -> cardStack.clearChildren());
|
||||
@ -531,6 +535,8 @@ public class GameScreen extends WizardScreen {
|
||||
cardStack.add(seat, actor);
|
||||
sequence.addAction(delay(actor));
|
||||
sequence.addAction(delay(AnimationTimings.STACK_HOLD));
|
||||
|
||||
game.sounds.sfxPlayCard();
|
||||
}));
|
||||
execute(sequence);
|
||||
}
|
||||
|
@ -31,15 +31,12 @@ public class InstructionScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonBack) {
|
||||
game.getClient().execute(Menu.class, Menu::showMenuScreen);
|
||||
sfxClick();
|
||||
} else if (actor == nextPageButton) {
|
||||
currentPage = MathUtils.clamp(currentPage + 1, 0, MAX_PAGE);
|
||||
showPage(currentPage);
|
||||
sfxClick();
|
||||
} else if (actor == previousPageButton) {
|
||||
currentPage = MathUtils.clamp(currentPage - 1, 0, MAX_PAGE);
|
||||
showPage(currentPage);
|
||||
sfxClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
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.VerticalGroup;
|
||||
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
|
||||
|
@ -37,17 +37,14 @@ public class LobbyScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonBack) {
|
||||
game.getClient().execute(Lobby.class, Lobby::disconnect);
|
||||
sfxClick();
|
||||
} else if (actor == buttonJoin) {
|
||||
if (rejoin) {
|
||||
game.getClient().execute(Lobby.class, Lobby::showRejoinScreen);
|
||||
} else {
|
||||
join();
|
||||
}
|
||||
sfxClick();
|
||||
} else if (actor == buttonCreate) {
|
||||
game.getClient().execute(Lobby.class, Lobby::showCreateScreen);
|
||||
sfxClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -23,13 +23,10 @@ public class MainMenuScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonPlay) {
|
||||
game.getClient().execute(Menu.class, Menu::showConnectScreen);
|
||||
sfxClick();
|
||||
} else if (actor == buttonQuit) {
|
||||
sfxClick();
|
||||
Gdx.app.exit();
|
||||
} else if (actor == buttonInstruction) {
|
||||
game.getClient().execute(Menu.class, Menu::showInstructionScreen);
|
||||
sfxClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -26,10 +26,8 @@ public class RejoinScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonBack) {
|
||||
game.getClient().execute(Lobby.class, Lobby::showListScreen);
|
||||
sfxClick();
|
||||
} else if (actor == buttonContinue) {
|
||||
rejoin();
|
||||
sfxClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -31,10 +31,8 @@ public class SessionScreen extends MenuScreen {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
if (actor == buttonLeave) {
|
||||
game.getClient().execute(Session.class, Session::leave);
|
||||
sfxClick();
|
||||
} else if (actor == buttonReady) {
|
||||
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.Screen;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
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.WizardGame;
|
||||
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.util.WizardAssetManager;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
@ -31,7 +31,6 @@ public abstract class WizardScreen implements Screen {
|
||||
protected Viewport viewport;
|
||||
|
||||
private Image background;
|
||||
private Sound sfxClick;
|
||||
|
||||
protected float offsetX;
|
||||
protected float offsetY;
|
||||
@ -56,11 +55,10 @@ public abstract class WizardScreen implements Screen {
|
||||
stage = new Stage(viewport);
|
||||
stage.addListener(new ButtonKeyListener());
|
||||
stage.addListener(new AutoFocusListener());
|
||||
stage.addListener(new ButtonClickListener(game.sounds));
|
||||
stage.setDebugAll(WizardGame.DEBUG);
|
||||
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
|
||||
sfxClick = assets.get(WizardAssetManager.SFX_CLICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,8 +108,4 @@ public abstract class WizardScreen implements Screen {
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
}
|
||||
|
||||
protected void sfxClick() {
|
||||
sfxClick.play(0.6f);
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ public final class Game extends BaseState {
|
||||
case "starting_round" -> {
|
||||
return onStartRound(client);
|
||||
}
|
||||
case "dealing" -> onDealing();
|
||||
case "starting_trick" -> onStartTrick();
|
||||
case "juggling" -> onJuggle();
|
||||
case "finishing_round" -> onFinishingRound();
|
||||
@ -189,6 +190,10 @@ public final class Game extends BaseState {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private void onDealing() {
|
||||
if (gameScreen != null) gameScreen.deal();
|
||||
}
|
||||
|
||||
private void onStartTrick() {
|
||||
log.info("Trick {} is starting...", trick + 1);
|
||||
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.SkinLoader;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
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_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 CURSOR = "cursor.png";
|
||||
@ -35,7 +36,6 @@ public class WizardAssetManager {
|
||||
manager.load(SKIN, Skin.class, new SkinLoader.SkinParameter(ATLAS_SKIN));
|
||||
|
||||
manager.load(MUSIC_BACKGROUND, Music.class);
|
||||
manager.load(SFX_CLICK, Sound.class);
|
||||
}
|
||||
|
||||
public void loadGame() {
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user