2015-05-18 02:22:13 +02:00
|
|
|
/**
|
|
|
|
* GladiatorBrawler is a 2D swordfighting game.
|
|
|
|
* Copyright (C) 2015 Jeasonfire/Allexit
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-05-17 00:10:51 +02:00
|
|
|
package com.saltosion.gladiator.listeners;
|
|
|
|
|
|
|
|
import com.badlogic.ashley.core.Entity;
|
2015-05-18 00:10:20 +02:00
|
|
|
import com.badlogic.gdx.audio.Sound;
|
2015-05-17 02:47:45 +02:00
|
|
|
import com.saltosion.gladiator.components.CParticle;
|
|
|
|
import com.saltosion.gladiator.components.CPhysics;
|
|
|
|
import com.saltosion.gladiator.util.AppUtil;
|
2015-05-18 00:10:20 +02:00
|
|
|
import com.saltosion.gladiator.util.AudioLoader;
|
2015-05-17 00:10:51 +02:00
|
|
|
import com.saltosion.gladiator.util.Global;
|
2015-05-18 00:10:20 +02:00
|
|
|
import com.saltosion.gladiator.util.Name;
|
2015-05-17 00:10:51 +02:00
|
|
|
|
|
|
|
public class BasicDeathListener implements CombatListener {
|
|
|
|
|
2015-05-17 02:47:45 +02:00
|
|
|
private static final float FX_FORCE = 16f, FX_GRAV = -40f;
|
|
|
|
|
2015-05-17 00:10:51 +02:00
|
|
|
@Override
|
|
|
|
public void died(Entity source, Entity target, int damageTaken) {
|
|
|
|
target.flags &= ~Global.FLAG_ALIVE;
|
2015-05-17 02:47:45 +02:00
|
|
|
|
|
|
|
CPhysics cp = target.getComponent(CPhysics.class);
|
2015-05-18 01:55:02 +02:00
|
|
|
|
2015-05-18 00:10:20 +02:00
|
|
|
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);
|
2015-05-18 01:55:02 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < getGoreAmount(damageTaken) * 2; i++) {
|
2015-05-17 02:47:45 +02:00
|
|
|
Entity fx = new Entity();
|
|
|
|
fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV)
|
|
|
|
.setVelocity((float) Math.cos(Math.toRadians(Math.random() * 360)) * FX_FORCE,
|
|
|
|
(float) Math.sin(Math.toRadians(Math.random() * 360)) * FX_FORCE)
|
|
|
|
.setPosition(cp.getPosition().x + (float) Math.random() - 0.5f,
|
|
|
|
cp.getPosition().y + (float) Math.random() - 0.5f)
|
|
|
|
.setSize(0.2f, 0.2f));
|
|
|
|
AppUtil.engine.addEntity(fx);
|
|
|
|
}
|
2015-05-17 00:10:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void damageTaken(Entity source, Entity target, int damageTaken) {
|
2015-05-17 02:47:45 +02:00
|
|
|
CPhysics cp = target.getComponent(CPhysics.class);
|
2015-05-18 01:55:02 +02:00
|
|
|
|
2015-05-18 00:10:20 +02:00
|
|
|
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);
|
2015-05-18 01:55:02 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < getGoreAmount(damageTaken); i++) {
|
2015-05-17 02:47:45 +02:00
|
|
|
Entity fx = new Entity();
|
|
|
|
fx.add(new CParticle().setColor(1, 0, 0, 1).setDecayTime(2).setGravity(0, FX_GRAV)
|
|
|
|
.setVelocity((float) Math.cos(Math.toRadians(Math.random() * 360)) * FX_FORCE,
|
|
|
|
(float) Math.sin(Math.toRadians(Math.random() * 360)) * FX_FORCE)
|
|
|
|
.setPosition(cp.getPosition().x + (float) Math.random() - 0.5f,
|
|
|
|
cp.getPosition().y + (float) Math.random() - 0.5f)
|
|
|
|
.setSize(0.2f, 0.2f));
|
|
|
|
AppUtil.engine.addEntity(fx);
|
|
|
|
}
|
2015-05-17 00:10:51 +02:00
|
|
|
}
|
|
|
|
|
2015-05-18 01:55:02 +02:00
|
|
|
public int getGoreAmount(int damage) {
|
|
|
|
return (damage - 89) / 8 * Global.GORE_LEVEL;
|
|
|
|
}
|
|
|
|
|
2015-05-17 00:10:51 +02:00
|
|
|
}
|