diff --git a/README.md b/README.md index a287fd2..b97cc60 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ #Gladiator Brawler + +Yay! \ No newline at end of file diff --git a/core/assets/attributions.md b/core/assets/attributions.md new file mode 100644 index 0000000..d2ac5c1 --- /dev/null +++ b/core/assets/attributions.md @@ -0,0 +1,46 @@ +Attributions +============ + +Matthew Pablo +------------- + +- Music + - theme.ogg + - Source: http://opengameart.org/content/you-were-my-brother-live-orchestra + - Original Name/Format(s): Tropic Strike - 1M2 - _You Were My Brother_.mp3 + - Additional info: http://www.matthewpablo.com/ + +Zefs +==== + +- Music + - battle_music.ogg + - Source: http://opengameart.org/content/orchestral-battle-music + - Original Name/Format(s): TheLoomingBattle.OGG + - Additional Info: - + +Iwan Gabovitch +-------------- + +- SFX + - hit01.ogg ... hit05.ogg + - Source: http://opengameart.org/content/15-vocal-male-strainhurtpainjump-sounds + - Original Name/Format(s): slightscream-03.flac, slightscream-04.flac, slightscream-05.flac, slightscream-10.flac, slightscream-14.flac + - Additional info: - + +Ogrebane +======== + +- SFX + - clang01.ogg .. clang04.ogg + - Source: http://opengameart.org/content/metal-and-wood-impact-sound-effects + - Original Name/Format(s): metal10.aif .. metal14.aif + - Additional info: - + +Kenney +====== +- SFX + - button_press.ogg, button_release.ogg + - Source: http://opengameart.org/content/51-ui-sound-effects-buttons-switches-and-clicks + - Original Name/Format(s): switch31.wav, swich32.wav + - Additional info: www.kenney.nl diff --git a/core/assets/audio/battle_music.ogg b/core/assets/audio/battle_music.ogg new file mode 100644 index 0000000..c35e8c6 Binary files /dev/null and b/core/assets/audio/battle_music.ogg differ diff --git a/core/assets/audio/button_press.ogg b/core/assets/audio/button_press.ogg new file mode 100644 index 0000000..272be07 Binary files /dev/null and b/core/assets/audio/button_press.ogg differ diff --git a/core/assets/audio/button_release.ogg b/core/assets/audio/button_release.ogg new file mode 100644 index 0000000..2a5605a Binary files /dev/null and b/core/assets/audio/button_release.ogg differ diff --git a/core/assets/audio/clang01.ogg b/core/assets/audio/clang01.ogg new file mode 100644 index 0000000..3c1f28b Binary files /dev/null and b/core/assets/audio/clang01.ogg differ diff --git a/core/assets/audio/clang02.ogg b/core/assets/audio/clang02.ogg new file mode 100644 index 0000000..765e77b Binary files /dev/null and b/core/assets/audio/clang02.ogg differ diff --git a/core/assets/audio/clang03.ogg b/core/assets/audio/clang03.ogg new file mode 100644 index 0000000..408cd14 Binary files /dev/null and b/core/assets/audio/clang03.ogg differ diff --git a/core/assets/audio/clang04.ogg b/core/assets/audio/clang04.ogg new file mode 100644 index 0000000..2a3ffbc Binary files /dev/null and b/core/assets/audio/clang04.ogg differ diff --git a/core/assets/audio/hit01.ogg b/core/assets/audio/hit01.ogg new file mode 100644 index 0000000..4ada46c Binary files /dev/null and b/core/assets/audio/hit01.ogg differ diff --git a/core/assets/audio/hit02.ogg b/core/assets/audio/hit02.ogg new file mode 100644 index 0000000..318b6b4 Binary files /dev/null and b/core/assets/audio/hit02.ogg differ diff --git a/core/assets/audio/hit03.ogg b/core/assets/audio/hit03.ogg new file mode 100644 index 0000000..ac01938 Binary files /dev/null and b/core/assets/audio/hit03.ogg differ diff --git a/core/assets/audio/hit04.ogg b/core/assets/audio/hit04.ogg new file mode 100644 index 0000000..478c54b Binary files /dev/null and b/core/assets/audio/hit04.ogg differ diff --git a/core/assets/audio/hit05.ogg b/core/assets/audio/hit05.ogg new file mode 100644 index 0000000..f08b68d Binary files /dev/null and b/core/assets/audio/hit05.ogg differ diff --git a/core/assets/audio/step.ogg b/core/assets/audio/step.ogg new file mode 100644 index 0000000..fdb94f6 Binary files /dev/null and b/core/assets/audio/step.ogg differ diff --git a/core/assets/audio/swing01.ogg b/core/assets/audio/swing01.ogg new file mode 100644 index 0000000..256b6cb Binary files /dev/null and b/core/assets/audio/swing01.ogg differ diff --git a/core/assets/audio/swing02.ogg b/core/assets/audio/swing02.ogg new file mode 100644 index 0000000..e428f21 Binary files /dev/null and b/core/assets/audio/swing02.ogg differ diff --git a/core/assets/audio/swing03.ogg b/core/assets/audio/swing03.ogg new file mode 100644 index 0000000..3c3fb1b Binary files /dev/null and b/core/assets/audio/swing03.ogg differ diff --git a/core/assets/audio/theme.ogg b/core/assets/audio/theme.ogg new file mode 100644 index 0000000..da9b970 Binary files /dev/null and b/core/assets/audio/theme.ogg differ diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index ac79032..4e0cde6 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -18,7 +18,10 @@ import com.saltosion.gladiator.systems.ParticleSystem; import com.saltosion.gladiator.systems.PhysicsSystem; import com.saltosion.gladiator.systems.RenderingSystem; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; +import com.saltosion.gladiator.util.Jukebox; import com.saltosion.gladiator.util.Log; +import com.saltosion.gladiator.util.SpriteLoader; public class GladiatorBrawler extends ApplicationAdapter { @@ -27,6 +30,7 @@ public class GladiatorBrawler extends ApplicationAdapter { private LevelFactory levelFactory; private GUIManager guiManager; private InputHandler inputHandler; + private Jukebox jukebox; private BaseState currentState; @@ -50,9 +54,14 @@ public class GladiatorBrawler extends ApplicationAdapter { // Initialize GUI guiManager = new GUIManager(); AppUtil.guiManager = this.guiManager; + + // Initialize Jukebox + jukebox = new Jukebox(); + AppUtil.jukebox = this.jukebox; // Initialize input inputHandler = new InputHandler(); + AppUtil.inputHandler = inputHandler; Gdx.input.setInputProcessor(inputHandler); // Initialize states @@ -136,5 +145,7 @@ public class GladiatorBrawler extends ApplicationAdapter { currentState.destroy(); } AppUtil.engine.getSystem(RenderingSystem.class).dispose(); + SpriteLoader.dispose(); + AudioLoader.dispose(); } } diff --git a/core/src/com/saltosion/gladiator/components/CPhysics.java b/core/src/com/saltosion/gladiator/components/CPhysics.java index 2f3ac03..27ca2d8 100644 --- a/core/src/com/saltosion/gladiator/components/CPhysics.java +++ b/core/src/com/saltosion/gladiator/components/CPhysics.java @@ -28,6 +28,9 @@ public class CPhysics extends Component { // Stores information about the direction last time moved in public boolean movedLeftLast = false; + + // Stores a float that tells how long the physics object must wait until it can play sounds with it's walking again. + public float stepCD = 0; /** * @param movable Toggles if the entity can move by itself diff --git a/core/src/com/saltosion/gladiator/gui/creators/GameOverGUICreator.java b/core/src/com/saltosion/gladiator/gui/creators/GameOverGUICreator.java index 3153fd4..017031a 100644 --- a/core/src/com/saltosion/gladiator/gui/creators/GameOverGUICreator.java +++ b/core/src/com/saltosion/gladiator/gui/creators/GameOverGUICreator.java @@ -31,10 +31,12 @@ public class GameOverGUICreator implements GUICreator { SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) { @Override public void pressed(int x, int y, int mouseButton) { + playButtonPressSound(); } @Override public void released(int x, int y, int mouseButton) { + playButtonReleaseSound(); shouldReturn = true; } }; diff --git a/core/src/com/saltosion/gladiator/gui/creators/MainMenuGUICreator.java b/core/src/com/saltosion/gladiator/gui/creators/MainMenuGUICreator.java index 958feb1..174376d 100644 --- a/core/src/com/saltosion/gladiator/gui/creators/MainMenuGUICreator.java +++ b/core/src/com/saltosion/gladiator/gui/creators/MainMenuGUICreator.java @@ -27,10 +27,12 @@ public class MainMenuGUICreator implements GUICreator { SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) { @Override public void pressed(int x, int y, int mouseButton) { + playButtonPressSound(); } @Override public void released(int x, int y, int mouseButton) { + playButtonReleaseSound(); shouldPlay = true; } }; diff --git a/core/src/com/saltosion/gladiator/gui/creators/WinGUICreator.java b/core/src/com/saltosion/gladiator/gui/creators/WinGUICreator.java index 743bdb1..7f1d117 100644 --- a/core/src/com/saltosion/gladiator/gui/creators/WinGUICreator.java +++ b/core/src/com/saltosion/gladiator/gui/creators/WinGUICreator.java @@ -31,10 +31,12 @@ public class WinGUICreator implements GUICreator { SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) { @Override public void pressed(int x, int y, int mouseButton) { + playButtonPressSound(); } @Override public void released(int x, int y, int mouseButton) { + playButtonReleaseSound(); shouldReturn = true; } }; diff --git a/core/src/com/saltosion/gladiator/gui/nodes/ButtonNode.java b/core/src/com/saltosion/gladiator/gui/nodes/ButtonNode.java index ed6cad2..829acb8 100644 --- a/core/src/com/saltosion/gladiator/gui/nodes/ButtonNode.java +++ b/core/src/com/saltosion/gladiator/gui/nodes/ButtonNode.java @@ -4,6 +4,9 @@ import com.saltosion.gladiator.gui.properties.ImageProperty; import com.saltosion.gladiator.gui.properties.InteractiveProperty; import com.saltosion.gladiator.gui.nodes.GUINode; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; +import com.saltosion.gladiator.util.Name; public abstract class ButtonNode extends GUINode implements InteractiveProperty, ImageProperty { private final Sprite onHover; @@ -15,6 +18,16 @@ public abstract class ButtonNode extends GUINode implements InteractiveProperty, this.onHover = onHover; this.normal = normal; } + + public void playButtonPressSound() { + AppUtil.jukebox.playSound(AudioLoader.getSound(Name.SOUND_BUTTON_PRESS), + AppUtil.sfxVolume/2); + } + + public void playButtonReleaseSound() { + AppUtil.jukebox.playSound(AudioLoader.getSound(Name.SOUND_BUTTON_RELEASE), + AppUtil.sfxVolume/2); + } @Override public void mouseEnter(float x, float y) { diff --git a/core/src/com/saltosion/gladiator/input/InputHandler.java b/core/src/com/saltosion/gladiator/input/InputHandler.java index b05a6c4..ec0b1ca 100644 --- a/core/src/com/saltosion/gladiator/input/InputHandler.java +++ b/core/src/com/saltosion/gladiator/input/InputHandler.java @@ -20,23 +20,33 @@ public class InputHandler implements InputProcessor { public HashMap keys = new HashMap(); private final Array hoveredUIElements = new Array(); + private final HashMap activatedInputs = new HashMap(); public InputHandler() { - keys.put(Keys.A, Name.MOVE_LEFT); - keys.put(Keys.D, Name.MOVE_RIGHT); - keys.put(Keys.SPACE, Name.JUMP); - keys.put(Keys.LEFT, Name.SWING_LEFT); - keys.put(Keys.RIGHT, Name.SWING_RIGHT); - keys.put(Keys.UP, Name.SWING_UP); - keys.put(Keys.DOWN, Name.SWING_DOWN); - keys.put(Keys.F2, Name.DEBUG); + addInput(Keys.A, Name.MOVE_LEFT, false); + addInput(Keys.D, Name.MOVE_RIGHT, false); + addInput(Keys.SPACE, Name.JUMP, false); + addInput(Keys.LEFT, Name.SWING_LEFT, false); + addInput(Keys.RIGHT, Name.SWING_RIGHT, false); + addInput(Keys.UP, Name.SWING_UP, false); + addInput(Keys.DOWN, Name.SWING_DOWN, false); + addInput(Keys.F2, Name.DEBUG, false); + } + + private void addInput(int key, String action, boolean activated) { + keys.put(key, action); + activatedInputs.put(action, activated); + } + + public void setInputEnabled(String action, boolean enabled) { + activatedInputs.put(action, enabled); } @Override public boolean keyDown(int keycode) { if (!keys.containsKey(keycode)) { return false; - } + } if (!activatedInputs.get(keys.get(keycode))) { return false; } String actionName = keys.get(keycode); return InputReceivers.getReceiver(actionName).pressed(); } @@ -45,7 +55,7 @@ public class InputHandler implements InputProcessor { public boolean keyUp(int keycode) { if (!keys.containsKey(keycode)) { return false; - } + } if (!activatedInputs.get(keys.get(keycode))) { return false; } String actionName = keys.get(keycode); return InputReceivers.getReceiver(actionName).released(); } diff --git a/core/src/com/saltosion/gladiator/level/LevelFactory.java b/core/src/com/saltosion/gladiator/level/LevelFactory.java index 4e4fc50..599a175 100644 --- a/core/src/com/saltosion/gladiator/level/LevelFactory.java +++ b/core/src/com/saltosion/gladiator/level/LevelFactory.java @@ -79,14 +79,14 @@ public class LevelFactory { Entity borderLeft = new Entity(); CPhysics borderLeftPhysics = new CPhysics().setMovable(false).setGravityApplied(false) - .setProcessCollisions(false).setSize(0.1f, 20); - borderLeftPhysics.setPosition(-xClamp - borderLeftPhysics.getSize().x, 0); + .setProcessCollisions(false).setSize(1f, 20); + borderLeftPhysics.setPosition(-xClamp - borderLeftPhysics.getSize().x / 2, 0); borderLeft.add(borderLeftPhysics); AppUtil.engine.addEntity(borderLeft); Entity borderRight = new Entity(); CPhysics borderRightPhysics = new CPhysics().setMovable(false).setGravityApplied(false) - .setProcessCollisions(false).setSize(0.1f, 20); - borderRightPhysics.setPosition(xClamp + borderRightPhysics.getSize().x, 0); + .setProcessCollisions(false).setSize(1f, 20); + borderRightPhysics.setPosition(xClamp + borderRightPhysics.getSize().x / 2, 0); borderRight.add(borderRightPhysics); AppUtil.engine.addEntity(borderRight); } diff --git a/core/src/com/saltosion/gladiator/listeners/BasicDeathListener.java b/core/src/com/saltosion/gladiator/listeners/BasicDeathListener.java index 8e3660d..320fb79 100644 --- a/core/src/com/saltosion/gladiator/listeners/BasicDeathListener.java +++ b/core/src/com/saltosion/gladiator/listeners/BasicDeathListener.java @@ -1,10 +1,13 @@ package com.saltosion.gladiator.listeners; import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.audio.Sound; import com.saltosion.gladiator.components.CParticle; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; import com.saltosion.gladiator.util.Global; +import com.saltosion.gladiator.util.Name; public class BasicDeathListener implements CombatListener { @@ -16,6 +19,14 @@ public class BasicDeathListener implements CombatListener { target.flags &= ~Global.FLAG_ALIVE; CPhysics cp = target.getComponent(CPhysics.class); + + Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_HIT01), + AudioLoader.getSound(Name.SOUND_HIT02), + AudioLoader.getSound(Name.SOUND_HIT03), + AudioLoader.getSound(Name.SOUND_HIT04), + AudioLoader.getSound(Name.SOUND_HIT05)); + s.play(AppUtil.sfxVolume); + for (int i = 0; i < FX_DEAD_AMT; i++) { Entity fx = new Entity(); fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV) @@ -31,6 +42,14 @@ public class BasicDeathListener implements CombatListener { @Override public void damageTaken(Entity source, Entity target, int damageTaken) { CPhysics cp = target.getComponent(CPhysics.class); + + Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_HIT01), + AudioLoader.getSound(Name.SOUND_HIT02), + AudioLoader.getSound(Name.SOUND_HIT03), + AudioLoader.getSound(Name.SOUND_HIT04), + AudioLoader.getSound(Name.SOUND_HIT05)); + s.play(AppUtil.sfxVolume); + for (int i = 0; i < FX_HIT_AMT; i++) { Entity fx = new Entity(); fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV) diff --git a/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java b/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java index d9dcabd..8698a44 100644 --- a/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java +++ b/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java @@ -4,10 +4,14 @@ import java.util.ArrayList; import com.badlogic.ashley.core.ComponentMapper; import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.audio.Sound; import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.systems.CombatSystem; +import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; import com.saltosion.gladiator.util.Direction; +import com.saltosion.gladiator.util.Name; public class SwingHitboxListener implements CollisionListener { @@ -46,6 +50,12 @@ public class SwingHitboxListener implements CollisionListener { } float force = cm.get(source).getSwingForce(); pm.get(source).setSimVelocity(x * force, 0); + + Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_CLANG01), + AudioLoader.getSound(Name.SOUND_CLANG02), + AudioLoader.getSound(Name.SOUND_CLANG03), + AudioLoader.getSound(Name.SOUND_CLANG04)); + s.play(AppUtil.sfxVolume); } } diff --git a/core/src/com/saltosion/gladiator/state/InGameState.java b/core/src/com/saltosion/gladiator/state/InGameState.java index 5c20461..ba1716e 100644 --- a/core/src/com/saltosion/gladiator/state/InGameState.java +++ b/core/src/com/saltosion/gladiator/state/InGameState.java @@ -7,6 +7,8 @@ import com.saltosion.gladiator.level.premade.Round2Level; import com.saltosion.gladiator.level.premade.Round3Level; import com.saltosion.gladiator.level.premade.Round4Level; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; +import com.saltosion.gladiator.util.Name; public class InGameState extends BaseState { @@ -32,6 +34,10 @@ public class InGameState extends BaseState { @Override public void create() { + // Play music + AppUtil.jukebox.playMusic(AudioLoader.getMusic(Name.MUSIC_BATTLE)); + AppUtil.jukebox.setMusicVolume(AppUtil.musicVolume/2); + // Start from a clean slate AppUtil.engine.removeAllEntities(); AppUtil.guiManager.clearGUI(); @@ -42,6 +48,15 @@ public class InGameState extends BaseState { guiCreator = new InGameGUICreator(); guiCreator.create(); + + // Activate inputs + AppUtil.inputHandler.setInputEnabled(Name.JUMP, true); + AppUtil.inputHandler.setInputEnabled(Name.MOVE_LEFT, true); + AppUtil.inputHandler.setInputEnabled(Name.MOVE_RIGHT, true); + AppUtil.inputHandler.setInputEnabled(Name.SWING_DOWN, true); + AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, true); + AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, true); + AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, true); } @Override @@ -88,6 +103,16 @@ public class InGameState extends BaseState { @Override public void destroy() { + + // Deactivate inputs + AppUtil.inputHandler.setInputEnabled(Name.JUMP, false); + AppUtil.inputHandler.setInputEnabled(Name.MOVE_LEFT, false); + AppUtil.inputHandler.setInputEnabled(Name.MOVE_RIGHT, false); + AppUtil.inputHandler.setInputEnabled(Name.SWING_DOWN, false); + AppUtil.inputHandler.setInputEnabled(Name.SWING_LEFT, false); + AppUtil.inputHandler.setInputEnabled(Name.SWING_RIGHT, false); + AppUtil.inputHandler.setInputEnabled(Name.SWING_UP, false); + // Clear all entities that are left as they are no longer needed AppUtil.engine.removeAllEntities(); // Clear GUI so there's nothing leftover for the next state diff --git a/core/src/com/saltosion/gladiator/state/MainMenuState.java b/core/src/com/saltosion/gladiator/state/MainMenuState.java index 221bc15..f7e6c27 100644 --- a/core/src/com/saltosion/gladiator/state/MainMenuState.java +++ b/core/src/com/saltosion/gladiator/state/MainMenuState.java @@ -2,6 +2,8 @@ package com.saltosion.gladiator.state; import com.saltosion.gladiator.gui.creators.MainMenuGUICreator; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; +import com.saltosion.gladiator.util.Name; public class MainMenuState extends BaseState { @@ -9,6 +11,10 @@ public class MainMenuState extends BaseState { @Override public void create() { + // Play music + AppUtil.jukebox.playMusic(AudioLoader.getMusic(Name.MUSIC_THEME)); + AppUtil.jukebox.setMusicVolume(AppUtil.musicVolume); + // Start from a clean slate AppUtil.guiManager.clearGUI(); diff --git a/core/src/com/saltosion/gladiator/systems/CombatSystem.java b/core/src/com/saltosion/gladiator/systems/CombatSystem.java index a3d4734..c3fbc82 100644 --- a/core/src/com/saltosion/gladiator/systems/CombatSystem.java +++ b/core/src/com/saltosion/gladiator/systems/CombatSystem.java @@ -6,6 +6,7 @@ import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.EntitySystem; import com.badlogic.ashley.core.Family; import com.badlogic.ashley.utils.ImmutableArray; +import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.math.Vector2; import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CDestructive; @@ -13,7 +14,9 @@ import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.listeners.CombatListener; import com.saltosion.gladiator.listeners.SwingHitboxListener; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; import com.saltosion.gladiator.util.Direction; +import com.saltosion.gladiator.util.Name; public class CombatSystem extends EntitySystem { @@ -54,6 +57,8 @@ public class CombatSystem extends EntitySystem { } if (!combat.getSwing().isZero() && combat.swingCdCounter <= 0) { + + // Swinging Vector2 pos = obj.getPosition().cpy(); if (combat.getSwingDirection() == Direction.LEFT) { @@ -67,6 +72,13 @@ public class CombatSystem extends EntitySystem { } createSwingHitbox(e, combat.getSwingDirection(), pos); + // SFX + Sound s = AppUtil.jukebox.returnRandomSound(AudioLoader.getSound(Name.SOUND_SWING01), + AudioLoader.getSound(Name.SOUND_SWING02), + AudioLoader.getSound(Name.SOUND_SWING03)); + s.play(AppUtil.sfxVolume); + + // After-swing combat.swingCdCounter = combat.getSwingDuration(); } } diff --git a/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java b/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java index 6d5a6e8..26f31a5 100644 --- a/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java +++ b/core/src/com/saltosion/gladiator/systems/PhysicsSystem.java @@ -8,12 +8,15 @@ import com.badlogic.ashley.core.Family; import com.badlogic.ashley.utils.ImmutableArray; import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CPhysics; +import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Log; +import com.saltosion.gladiator.util.Name; public class PhysicsSystem extends EntitySystem { - private static final float MAX_VEL = 1.75f, COLLISION_PRECISION = 12f, UPDATES_PER_SECOND = 240f; + private static final float MAX_VEL = 1.75f, COLLISION_PRECISION = 12f, UPDATES_PER_SECOND = 300f; private static final ComponentMapper pm = ComponentMapper.getFor(CPhysics.class); private static final ComponentMapper cm = ComponentMapper.getFor(CCombat.class); @@ -58,6 +61,9 @@ public class PhysicsSystem extends EntitySystem { if (obj.jumping && obj.isGrounded()) { obj.setGrounded(false); obj.getVelocity().y = obj.getJumpForce(); + + // Sound effect! + AppUtil.jukebox.playSound(AudioLoader.getSound(Name.SOUND_STEP), AppUtil.sfxVolume); } obj.getVelocity().x += obj.getSimVelocity().x; diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 7bd1b94..8216231 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -28,6 +28,7 @@ import com.saltosion.gladiator.gui.properties.ImageProperty; import com.saltosion.gladiator.gui.nodes.TextNode; import com.saltosion.gladiator.gui.properties.TextProperty; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.AudioLoader; import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Name; import com.saltosion.gladiator.util.SpriteLoader; @@ -101,7 +102,7 @@ public class RenderingSystem extends EntitySystem { Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - updateEntityAnimations(); + updateEntityAnimations(deltaTime); renderEntities(deltaTime); renderParticles(); renderDebug(); @@ -134,13 +135,13 @@ public class RenderingSystem extends EntitySystem { return deltaString; } - private void updateEntityAnimations() { + private void updateEntityAnimations(float deltaTime) { for (int i = 0; i < entities.size(); i++) { - updateEntityAnimation(entities.get(i)); + updateEntityAnimation(entities.get(i), deltaTime); } } - private void updateEntityAnimation(Entity entity) { + private void updateEntityAnimation(Entity entity, float deltaTime) { CRenderedObject ro = rom.get(entity); CPhysics po = pm.get(entity); CCombat co = cm.get(entity); @@ -184,21 +185,35 @@ public class RenderingSystem extends EntitySystem { } } - // Play animations + // Play animations & play sounds + if (po.stepCD > 0) { + po.stepCD -= deltaTime; + } + if (moving && combat) { ro.playAnimation("torso", "Torso-Combat-" + dirSwing); ro.playAnimation("legs", "Legs-Run-" + dirMove); + tryToMakeStepSound(po); } else if (combat) { ro.playAnimation("torso", "Torso-Combat-" + dirSwing); ro.playAnimation("legs", "Legs-Idle-" + dirMove); } else if (moving) { ro.playAnimation("torso", "Torso-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove); + tryToMakeStepSound(po); } else { ro.playAnimation("torso", "Torso-Idle-" + dirMove); ro.playAnimation("legs", "Legs-Idle-" + dirMove); } } + + private void tryToMakeStepSound(CPhysics po) { + if (po.stepCD > 0 || !po.isGrounded()) { + return; + } + po.stepCD = 0.3f; + AppUtil.jukebox.playSound(AudioLoader.getSound(Name.SOUND_STEP), AppUtil.sfxVolume/3*2); + } private void renderEntities(float deltaTime) { if (AppUtil.player == null) { @@ -425,7 +440,6 @@ public class RenderingSystem extends EntitySystem { debugRenderer.dispose(); particleRenderer.dispose(); font.dispose(); - SpriteLoader.dispose(); } private class TextObject { diff --git a/core/src/com/saltosion/gladiator/util/AppUtil.java b/core/src/com/saltosion/gladiator/util/AppUtil.java index 03f5c87..e7a5a36 100644 --- a/core/src/com/saltosion/gladiator/util/AppUtil.java +++ b/core/src/com/saltosion/gladiator/util/AppUtil.java @@ -4,6 +4,7 @@ import com.badlogic.ashley.core.Engine; import com.badlogic.ashley.core.Entity; import com.badlogic.gdx.math.Vector2; import com.saltosion.gladiator.gui.GUIManager; +import com.saltosion.gladiator.input.InputHandler; import com.saltosion.gladiator.level.EntityFactory; import com.saltosion.gladiator.level.LevelFactory; @@ -11,11 +12,16 @@ public class AppUtil { public static Entity player; public static Engine engine; + public static Jukebox jukebox; public static EntityFactory entityFactory; public static LevelFactory levelFactory; public static GUIManager guiManager; + public static InputHandler inputHandler; public static final int VPHEIGHT_CONST = 24; + + public static float sfxVolume = 0.3f; + public static float musicVolume = 0.7f; public static final Vector2 JUMP_FORCE = new Vector2(0, 12000); } diff --git a/core/src/com/saltosion/gladiator/util/AudioLoader.java b/core/src/com/saltosion/gladiator/util/AudioLoader.java new file mode 100644 index 0000000..c87561b --- /dev/null +++ b/core/src/com/saltosion/gladiator/util/AudioLoader.java @@ -0,0 +1,60 @@ +package com.saltosion.gladiator.util; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Sound; +import java.util.HashMap; + +public class AudioLoader { + + private static HashMap sounds = new HashMap(); + private static HashMap musics = new HashMap(); + + static { + // Import all the sounds & musix + AudioLoader.musics.put(Name.MUSIC_THEME, loadMusic("audio/theme.ogg")); + AudioLoader.musics.put(Name.MUSIC_BATTLE, loadMusic("audio/battle_music.ogg")); + AudioLoader.sounds.put(Name.SOUND_SWING01, loadSound("audio/swing01.ogg")); + AudioLoader.sounds.put(Name.SOUND_SWING02, loadSound("audio/swing02.ogg")); + AudioLoader.sounds.put(Name.SOUND_SWING03, loadSound("audio/swing03.ogg")); + AudioLoader.sounds.put(Name.SOUND_HIT01, loadSound("audio/hit01.ogg")); + AudioLoader.sounds.put(Name.SOUND_HIT02, loadSound("audio/hit02.ogg")); + AudioLoader.sounds.put(Name.SOUND_HIT03, loadSound("audio/hit03.ogg")); + AudioLoader.sounds.put(Name.SOUND_HIT04, loadSound("audio/hit04.ogg")); + AudioLoader.sounds.put(Name.SOUND_HIT05, loadSound("audio/hit05.ogg")); + AudioLoader.sounds.put(Name.SOUND_CLANG01, loadSound("audio/clang01.ogg")); + AudioLoader.sounds.put(Name.SOUND_CLANG02, loadSound("audio/clang02.ogg")); + AudioLoader.sounds.put(Name.SOUND_CLANG03, loadSound("audio/clang03.ogg")); + AudioLoader.sounds.put(Name.SOUND_CLANG04, loadSound("audio/clang04.ogg")); + AudioLoader.sounds.put(Name.SOUND_STEP, loadSound("audio/step.ogg")); + AudioLoader.sounds.put(Name.SOUND_BUTTON_PRESS, loadSound("audio/button_press.ogg")); + AudioLoader.sounds.put(Name.SOUND_BUTTON_RELEASE, loadSound("audio/button_release.ogg")); + } + + private static Music loadMusic(String path) { + return Gdx.audio.newMusic(Gdx.files.internal(path)); + } + + private static Sound loadSound(String path) { + return Gdx.audio.newSound(Gdx.files.internal(path)); + } + + public static Sound getSound(String id) { + return sounds.get(id); + } + + public static Music getMusic(String id) { + return musics.get(id); + } + + public static void dispose() { + Log.info("Disposed sounds and musics!"); + for (String s : sounds.keySet()) { + sounds.get(s).dispose(); + } + for (String s : musics.keySet()) { + musics.get(s).dispose(); + } + } + +} diff --git a/core/src/com/saltosion/gladiator/util/Jukebox.java b/core/src/com/saltosion/gladiator/util/Jukebox.java new file mode 100644 index 0000000..d4dc4eb --- /dev/null +++ b/core/src/com/saltosion/gladiator/util/Jukebox.java @@ -0,0 +1,79 @@ + +package com.saltosion.gladiator.util; + +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Sound; + +public class Jukebox { + + private Music currentMusic; + private float volume = 1; + + /** + * Plays the musix like a baws. + * @param music + * @return boolean if the musix failed to play + */ + public boolean playMusic(Music music) { + if (music == null) { + currentMusic.stop(); + currentMusic = null; + } + if (music.equals(currentMusic)) { + return false; + } if (currentMusic != null) { currentMusic.stop(); }; + music.play(); + music.setVolume(volume); + music.setLooping(true); + currentMusic = music; + return true; + } + + public Music getCurrentMusic() { + return this.currentMusic; + } + + public void setMusicVolume(float volume) { + this.volume = volume; + if (currentMusic == null) {return;} + this.currentMusic.setVolume(volume); + } + + /** + * Simply plays the sound + * @param sound + * @return long returns sound's id + */ + public long playSound(Sound sound) { + return sound.play(); + } + + /** + * Play sound and set it's volume + * @param sound + * @param volume 0-1f + * @return long returns sound's id + */ + public long playSound(Sound sound, float volume) { + long id = playSound(sound); + sound.setVolume(id, volume); + return id; + } + + /** + * Play sound and set it's volume & pan + * @param sound + * @param volume 0-1f + * @param pan ? + * @return long returns sound's id + */ + public long playSound(Sound sound, float volume, float pan) { + long id = playSound(sound); + sound.setPan(id, pan, volume); + return id; + } + + public Sound returnRandomSound(Sound ... args) { + return args[(int) Math.floor(Math.random()*args.length)]; + } +} diff --git a/core/src/com/saltosion/gladiator/util/Name.java b/core/src/com/saltosion/gladiator/util/Name.java index 8cb9cfc..068cdf2 100644 --- a/core/src/com/saltosion/gladiator/util/Name.java +++ b/core/src/com/saltosion/gladiator/util/Name.java @@ -35,4 +35,22 @@ public class Name { public static final String SWING_UP = "SWING_UP"; public static final String SWING_DOWN = "SWING_DOWN"; + public static final String MUSIC_THEME = "MUSIC_THEME"; + public static final String MUSIC_BATTLE = "MUSIC_BATTLE"; + public static final String SOUND_SWING01 = "SOUND_SWING01"; + public static final String SOUND_SWING02 = "SOUND_SWING02"; + public static final String SOUND_SWING03 = "SOUND_SWING03"; + public static final String SOUND_HIT01 = "SOUND_HIT01"; + public static final String SOUND_HIT02 = "SOUND_HIT02"; + public static final String SOUND_HIT03 = "SOUND_HIT03"; + public static final String SOUND_HIT04 = "SOUND_HIT04"; + public static final String SOUND_HIT05 = "SOUND_HIT05"; + public static final String SOUND_CLANG01 = "SOUND_CLANG01"; + public static final String SOUND_CLANG02 = "SOUND_CLANG02"; + public static final String SOUND_CLANG03 = "SOUND_CLANG03"; + public static final String SOUND_CLANG04 = "SOUND_CLANG04"; + public static final String SOUND_STEP = "SOUND_STEP"; + public static final String SOUND_BUTTON_PRESS = "SOUND_BUTTON_PRESS"; + public static final String SOUND_BUTTON_RELEASE = "SOUND_BUTTON_RELEASE"; + }