Merge branch 'master' into ai

This commit is contained in:
Jeasonfire 2015-05-18 02:09:32 +03:00
commit db9af3fd05
38 changed files with 367 additions and 21 deletions

View File

@ -1 +1,3 @@
#Gladiator Brawler #Gladiator Brawler
Yay!

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
core/assets/audio/hit01.ogg Normal file

Binary file not shown.

BIN
core/assets/audio/hit02.ogg Normal file

Binary file not shown.

BIN
core/assets/audio/hit03.ogg Normal file

Binary file not shown.

BIN
core/assets/audio/hit04.ogg Normal file

Binary file not shown.

BIN
core/assets/audio/hit05.ogg Normal file

Binary file not shown.

BIN
core/assets/audio/step.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
core/assets/audio/theme.ogg Normal file

Binary file not shown.

View File

@ -18,7 +18,10 @@ import com.saltosion.gladiator.systems.ParticleSystem;
import com.saltosion.gladiator.systems.PhysicsSystem; import com.saltosion.gladiator.systems.PhysicsSystem;
import com.saltosion.gladiator.systems.RenderingSystem; import com.saltosion.gladiator.systems.RenderingSystem;
import com.saltosion.gladiator.util.AppUtil; 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.Log;
import com.saltosion.gladiator.util.SpriteLoader;
public class GladiatorBrawler extends ApplicationAdapter { public class GladiatorBrawler extends ApplicationAdapter {
@ -27,6 +30,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
private LevelFactory levelFactory; private LevelFactory levelFactory;
private GUIManager guiManager; private GUIManager guiManager;
private InputHandler inputHandler; private InputHandler inputHandler;
private Jukebox jukebox;
private BaseState currentState; private BaseState currentState;
@ -50,9 +54,14 @@ public class GladiatorBrawler extends ApplicationAdapter {
// Initialize GUI // Initialize GUI
guiManager = new GUIManager(); guiManager = new GUIManager();
AppUtil.guiManager = this.guiManager; AppUtil.guiManager = this.guiManager;
// Initialize Jukebox
jukebox = new Jukebox();
AppUtil.jukebox = this.jukebox;
// Initialize input // Initialize input
inputHandler = new InputHandler(); inputHandler = new InputHandler();
AppUtil.inputHandler = inputHandler;
Gdx.input.setInputProcessor(inputHandler); Gdx.input.setInputProcessor(inputHandler);
// Initialize states // Initialize states
@ -136,5 +145,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
currentState.destroy(); currentState.destroy();
} }
AppUtil.engine.getSystem(RenderingSystem.class).dispose(); AppUtil.engine.getSystem(RenderingSystem.class).dispose();
SpriteLoader.dispose();
AudioLoader.dispose();
} }
} }

View File

@ -28,6 +28,9 @@ public class CPhysics extends Component {
// Stores information about the direction last time moved in // Stores information about the direction last time moved in
public boolean movedLeftLast = false; 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 * @param movable Toggles if the entity can move by itself

View File

@ -31,10 +31,12 @@ public class GameOverGUICreator implements GUICreator {
SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) { SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) {
@Override @Override
public void pressed(int x, int y, int mouseButton) { public void pressed(int x, int y, int mouseButton) {
playButtonPressSound();
} }
@Override @Override
public void released(int x, int y, int mouseButton) { public void released(int x, int y, int mouseButton) {
playButtonReleaseSound();
shouldReturn = true; shouldReturn = true;
} }
}; };

View File

@ -27,10 +27,12 @@ public class MainMenuGUICreator implements GUICreator {
SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) { SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) {
@Override @Override
public void pressed(int x, int y, int mouseButton) { public void pressed(int x, int y, int mouseButton) {
playButtonPressSound();
} }
@Override @Override
public void released(int x, int y, int mouseButton) { public void released(int x, int y, int mouseButton) {
playButtonReleaseSound();
shouldPlay = true; shouldPlay = true;
} }
}; };

View File

@ -31,10 +31,12 @@ public class WinGUICreator implements GUICreator {
SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) { SpriteLoader.loadSprite(Name.BUTTON_BIG_HOVER)) {
@Override @Override
public void pressed(int x, int y, int mouseButton) { public void pressed(int x, int y, int mouseButton) {
playButtonPressSound();
} }
@Override @Override
public void released(int x, int y, int mouseButton) { public void released(int x, int y, int mouseButton) {
playButtonReleaseSound();
shouldReturn = true; shouldReturn = true;
} }
}; };

View File

@ -4,6 +4,9 @@ import com.saltosion.gladiator.gui.properties.ImageProperty;
import com.saltosion.gladiator.gui.properties.InteractiveProperty; import com.saltosion.gladiator.gui.properties.InteractiveProperty;
import com.saltosion.gladiator.gui.nodes.GUINode; import com.saltosion.gladiator.gui.nodes.GUINode;
import com.badlogic.gdx.graphics.g2d.Sprite; 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 { public abstract class ButtonNode extends GUINode implements InteractiveProperty, ImageProperty {
private final Sprite onHover; private final Sprite onHover;
@ -15,6 +18,16 @@ public abstract class ButtonNode extends GUINode implements InteractiveProperty,
this.onHover = onHover; this.onHover = onHover;
this.normal = normal; 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 @Override
public void mouseEnter(float x, float y) { public void mouseEnter(float x, float y) {

View File

@ -20,23 +20,33 @@ public class InputHandler implements InputProcessor {
public HashMap<Integer, String> keys = new HashMap<Integer, String>(); public HashMap<Integer, String> keys = new HashMap<Integer, String>();
private final Array<String> hoveredUIElements = new Array<String>(); private final Array<String> hoveredUIElements = new Array<String>();
private final HashMap<String, Boolean> activatedInputs = new HashMap<String, Boolean>();
public InputHandler() { public InputHandler() {
keys.put(Keys.A, Name.MOVE_LEFT); addInput(Keys.A, Name.MOVE_LEFT, false);
keys.put(Keys.D, Name.MOVE_RIGHT); addInput(Keys.D, Name.MOVE_RIGHT, false);
keys.put(Keys.SPACE, Name.JUMP); addInput(Keys.SPACE, Name.JUMP, false);
keys.put(Keys.LEFT, Name.SWING_LEFT); addInput(Keys.LEFT, Name.SWING_LEFT, false);
keys.put(Keys.RIGHT, Name.SWING_RIGHT); addInput(Keys.RIGHT, Name.SWING_RIGHT, false);
keys.put(Keys.UP, Name.SWING_UP); addInput(Keys.UP, Name.SWING_UP, false);
keys.put(Keys.DOWN, Name.SWING_DOWN); addInput(Keys.DOWN, Name.SWING_DOWN, false);
keys.put(Keys.F2, Name.DEBUG); 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 @Override
public boolean keyDown(int keycode) { public boolean keyDown(int keycode) {
if (!keys.containsKey(keycode)) { if (!keys.containsKey(keycode)) {
return false; return false;
} } if (!activatedInputs.get(keys.get(keycode))) { return false; }
String actionName = keys.get(keycode); String actionName = keys.get(keycode);
return InputReceivers.getReceiver(actionName).pressed(); return InputReceivers.getReceiver(actionName).pressed();
} }
@ -45,7 +55,7 @@ public class InputHandler implements InputProcessor {
public boolean keyUp(int keycode) { public boolean keyUp(int keycode) {
if (!keys.containsKey(keycode)) { if (!keys.containsKey(keycode)) {
return false; return false;
} } if (!activatedInputs.get(keys.get(keycode))) { return false; }
String actionName = keys.get(keycode); String actionName = keys.get(keycode);
return InputReceivers.getReceiver(actionName).released(); return InputReceivers.getReceiver(actionName).released();
} }

View File

@ -79,14 +79,14 @@ public class LevelFactory {
Entity borderLeft = new Entity(); Entity borderLeft = new Entity();
CPhysics borderLeftPhysics = new CPhysics().setMovable(false).setGravityApplied(false) CPhysics borderLeftPhysics = new CPhysics().setMovable(false).setGravityApplied(false)
.setProcessCollisions(false).setSize(0.1f, 20); .setProcessCollisions(false).setSize(1f, 20);
borderLeftPhysics.setPosition(-xClamp - borderLeftPhysics.getSize().x, 0); borderLeftPhysics.setPosition(-xClamp - borderLeftPhysics.getSize().x / 2, 0);
borderLeft.add(borderLeftPhysics); borderLeft.add(borderLeftPhysics);
AppUtil.engine.addEntity(borderLeft); AppUtil.engine.addEntity(borderLeft);
Entity borderRight = new Entity(); Entity borderRight = new Entity();
CPhysics borderRightPhysics = new CPhysics().setMovable(false).setGravityApplied(false) CPhysics borderRightPhysics = new CPhysics().setMovable(false).setGravityApplied(false)
.setProcessCollisions(false).setSize(0.1f, 20); .setProcessCollisions(false).setSize(1f, 20);
borderRightPhysics.setPosition(xClamp + borderRightPhysics.getSize().x, 0); borderRightPhysics.setPosition(xClamp + borderRightPhysics.getSize().x / 2, 0);
borderRight.add(borderRightPhysics); borderRight.add(borderRightPhysics);
AppUtil.engine.addEntity(borderRight); AppUtil.engine.addEntity(borderRight);
} }

View File

@ -1,10 +1,13 @@
package com.saltosion.gladiator.listeners; package com.saltosion.gladiator.listeners;
import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.audio.Sound;
import com.saltosion.gladiator.components.CParticle; import com.saltosion.gladiator.components.CParticle;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.AudioLoader;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
import com.saltosion.gladiator.util.Name;
public class BasicDeathListener implements CombatListener { public class BasicDeathListener implements CombatListener {
@ -16,6 +19,14 @@ public class BasicDeathListener implements CombatListener {
target.flags &= ~Global.FLAG_ALIVE; target.flags &= ~Global.FLAG_ALIVE;
CPhysics cp = target.getComponent(CPhysics.class); 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++) { for (int i = 0; i < FX_DEAD_AMT; i++) {
Entity fx = new Entity(); Entity fx = new Entity();
fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV) 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 @Override
public void damageTaken(Entity source, Entity target, int damageTaken) { public void damageTaken(Entity source, Entity target, int damageTaken) {
CPhysics cp = target.getComponent(CPhysics.class); 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++) { for (int i = 0; i < FX_HIT_AMT; i++) {
Entity fx = new Entity(); Entity fx = new Entity();
fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV) fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV)

View File

@ -4,10 +4,14 @@ import java.util.ArrayList;
import com.badlogic.ashley.core.ComponentMapper; import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.audio.Sound;
import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.systems.CombatSystem; 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.Direction;
import com.saltosion.gladiator.util.Name;
public class SwingHitboxListener implements CollisionListener { public class SwingHitboxListener implements CollisionListener {
@ -46,6 +50,12 @@ public class SwingHitboxListener implements CollisionListener {
} }
float force = cm.get(source).getSwingForce(); float force = cm.get(source).getSwingForce();
pm.get(source).setSimVelocity(x * force, 0); 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);
} }
} }

View File

@ -7,6 +7,8 @@ import com.saltosion.gladiator.level.premade.Round2Level;
import com.saltosion.gladiator.level.premade.Round3Level; import com.saltosion.gladiator.level.premade.Round3Level;
import com.saltosion.gladiator.level.premade.Round4Level; import com.saltosion.gladiator.level.premade.Round4Level;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.AudioLoader;
import com.saltosion.gladiator.util.Name;
public class InGameState extends BaseState { public class InGameState extends BaseState {
@ -32,6 +34,10 @@ public class InGameState extends BaseState {
@Override @Override
public void create() { public void create() {
// Play music
AppUtil.jukebox.playMusic(AudioLoader.getMusic(Name.MUSIC_BATTLE));
AppUtil.jukebox.setMusicVolume(AppUtil.musicVolume/2);
// Start from a clean slate // Start from a clean slate
AppUtil.engine.removeAllEntities(); AppUtil.engine.removeAllEntities();
AppUtil.guiManager.clearGUI(); AppUtil.guiManager.clearGUI();
@ -42,6 +48,15 @@ public class InGameState extends BaseState {
guiCreator = new InGameGUICreator(); guiCreator = new InGameGUICreator();
guiCreator.create(); 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 @Override
@ -88,6 +103,16 @@ public class InGameState extends BaseState {
@Override @Override
public void destroy() { 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 // Clear all entities that are left as they are no longer needed
AppUtil.engine.removeAllEntities(); AppUtil.engine.removeAllEntities();
// Clear GUI so there's nothing leftover for the next state // Clear GUI so there's nothing leftover for the next state

View File

@ -2,6 +2,8 @@ package com.saltosion.gladiator.state;
import com.saltosion.gladiator.gui.creators.MainMenuGUICreator; import com.saltosion.gladiator.gui.creators.MainMenuGUICreator;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.AudioLoader;
import com.saltosion.gladiator.util.Name;
public class MainMenuState extends BaseState { public class MainMenuState extends BaseState {
@ -9,6 +11,10 @@ public class MainMenuState extends BaseState {
@Override @Override
public void create() { public void create() {
// Play music
AppUtil.jukebox.playMusic(AudioLoader.getMusic(Name.MUSIC_THEME));
AppUtil.jukebox.setMusicVolume(AppUtil.musicVolume);
// Start from a clean slate // Start from a clean slate
AppUtil.guiManager.clearGUI(); AppUtil.guiManager.clearGUI();

View File

@ -6,6 +6,7 @@ import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem; import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family; import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray; import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CDestructive; 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.CombatListener;
import com.saltosion.gladiator.listeners.SwingHitboxListener; import com.saltosion.gladiator.listeners.SwingHitboxListener;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.AudioLoader;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
import com.saltosion.gladiator.util.Name;
public class CombatSystem extends EntitySystem { public class CombatSystem extends EntitySystem {
@ -54,6 +57,8 @@ public class CombatSystem extends EntitySystem {
} }
if (!combat.getSwing().isZero() && combat.swingCdCounter <= 0) { if (!combat.getSwing().isZero() && combat.swingCdCounter <= 0) {
// Swinging
Vector2 pos = obj.getPosition().cpy(); Vector2 pos = obj.getPosition().cpy();
if (combat.getSwingDirection() == Direction.LEFT) { if (combat.getSwingDirection() == Direction.LEFT) {
@ -67,6 +72,13 @@ public class CombatSystem extends EntitySystem {
} }
createSwingHitbox(e, combat.getSwingDirection(), pos); 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(); combat.swingCdCounter = combat.getSwingDuration();
} }
} }

View File

@ -8,12 +8,15 @@ import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray; import com.badlogic.ashley.utils.ImmutableArray;
import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; 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.Direction;
import com.saltosion.gladiator.util.Log; import com.saltosion.gladiator.util.Log;
import com.saltosion.gladiator.util.Name;
public class PhysicsSystem extends EntitySystem { 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<CPhysics> pm = ComponentMapper.getFor(CPhysics.class); private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
private static final ComponentMapper<CCombat> cm = ComponentMapper.getFor(CCombat.class); private static final ComponentMapper<CCombat> cm = ComponentMapper.getFor(CCombat.class);
@ -58,6 +61,9 @@ public class PhysicsSystem extends EntitySystem {
if (obj.jumping && obj.isGrounded()) { if (obj.jumping && obj.isGrounded()) {
obj.setGrounded(false); obj.setGrounded(false);
obj.getVelocity().y = obj.getJumpForce(); obj.getVelocity().y = obj.getJumpForce();
// Sound effect!
AppUtil.jukebox.playSound(AudioLoader.getSound(Name.SOUND_STEP), AppUtil.sfxVolume);
} }
obj.getVelocity().x += obj.getSimVelocity().x; obj.getVelocity().x += obj.getSimVelocity().x;

View File

@ -28,6 +28,7 @@ import com.saltosion.gladiator.gui.properties.ImageProperty;
import com.saltosion.gladiator.gui.nodes.TextNode; import com.saltosion.gladiator.gui.nodes.TextNode;
import com.saltosion.gladiator.gui.properties.TextProperty; import com.saltosion.gladiator.gui.properties.TextProperty;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.AudioLoader;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
import com.saltosion.gladiator.util.Name; import com.saltosion.gladiator.util.Name;
import com.saltosion.gladiator.util.SpriteLoader; import com.saltosion.gladiator.util.SpriteLoader;
@ -101,7 +102,7 @@ public class RenderingSystem extends EntitySystem {
Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
updateEntityAnimations(); updateEntityAnimations(deltaTime);
renderEntities(deltaTime); renderEntities(deltaTime);
renderParticles(); renderParticles();
renderDebug(); renderDebug();
@ -134,13 +135,13 @@ public class RenderingSystem extends EntitySystem {
return deltaString; return deltaString;
} }
private void updateEntityAnimations() { private void updateEntityAnimations(float deltaTime) {
for (int i = 0; i < entities.size(); i++) { 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); CRenderedObject ro = rom.get(entity);
CPhysics po = pm.get(entity); CPhysics po = pm.get(entity);
CCombat co = cm.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) { if (moving && combat) {
ro.playAnimation("torso", "Torso-Combat-" + dirSwing); ro.playAnimation("torso", "Torso-Combat-" + dirSwing);
ro.playAnimation("legs", "Legs-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove);
tryToMakeStepSound(po);
} else if (combat) { } else if (combat) {
ro.playAnimation("torso", "Torso-Combat-" + dirSwing); ro.playAnimation("torso", "Torso-Combat-" + dirSwing);
ro.playAnimation("legs", "Legs-Idle-" + dirMove); ro.playAnimation("legs", "Legs-Idle-" + dirMove);
} else if (moving) { } else if (moving) {
ro.playAnimation("torso", "Torso-Run-" + dirMove); ro.playAnimation("torso", "Torso-Run-" + dirMove);
ro.playAnimation("legs", "Legs-Run-" + dirMove); ro.playAnimation("legs", "Legs-Run-" + dirMove);
tryToMakeStepSound(po);
} else { } else {
ro.playAnimation("torso", "Torso-Idle-" + dirMove); ro.playAnimation("torso", "Torso-Idle-" + dirMove);
ro.playAnimation("legs", "Legs-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) { private void renderEntities(float deltaTime) {
if (AppUtil.player == null) { if (AppUtil.player == null) {
@ -425,7 +440,6 @@ public class RenderingSystem extends EntitySystem {
debugRenderer.dispose(); debugRenderer.dispose();
particleRenderer.dispose(); particleRenderer.dispose();
font.dispose(); font.dispose();
SpriteLoader.dispose();
} }
private class TextObject { private class TextObject {

View File

@ -4,6 +4,7 @@ import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.saltosion.gladiator.gui.GUIManager; import com.saltosion.gladiator.gui.GUIManager;
import com.saltosion.gladiator.input.InputHandler;
import com.saltosion.gladiator.level.EntityFactory; import com.saltosion.gladiator.level.EntityFactory;
import com.saltosion.gladiator.level.LevelFactory; import com.saltosion.gladiator.level.LevelFactory;
@ -11,11 +12,16 @@ public class AppUtil {
public static Entity player; public static Entity player;
public static Engine engine; public static Engine engine;
public static Jukebox jukebox;
public static EntityFactory entityFactory; public static EntityFactory entityFactory;
public static LevelFactory levelFactory; public static LevelFactory levelFactory;
public static GUIManager guiManager; public static GUIManager guiManager;
public static InputHandler inputHandler;
public static final int VPHEIGHT_CONST = 24; 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); public static final Vector2 JUMP_FORCE = new Vector2(0, 12000);
} }

View File

@ -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<String, Sound> sounds = new HashMap<String, Sound>();
private static HashMap<String, Music> musics = new HashMap<String, Music>();
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();
}
}
}

View File

@ -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)];
}
}

View File

@ -35,4 +35,22 @@ public class Name {
public static final String SWING_UP = "SWING_UP"; public static final String SWING_UP = "SWING_UP";
public static final String SWING_DOWN = "SWING_DOWN"; 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";
} }