Parrying added. (Sans animations)

This commit is contained in:
Jeasonfire 2015-05-27 15:50:26 +03:00
parent f5e0a40be7
commit c5a3ccd861
4 changed files with 23 additions and 3 deletions

View File

@ -29,13 +29,14 @@ public class CCombat extends Component {
public int health = 0; public int health = 0;
private int maxHealth = 0; private int maxHealth = 0;
private int damage = 0; private int damage = 0;
private float swingForce = 20f; private float swingForce = 15f;
private Vector2 swingsize = new Vector2(3, 3); private Vector2 swingsize = new Vector2(3, 3);
private CombatListener combatListener; private CombatListener combatListener;
private Vector2 swinging = new Vector2(); private Vector2 swinging = new Vector2();
private float swingDuration = 0.4f; private float swingDuration = 0.4f;
public float swingCdCounter = 0; public float swingCdCounter = 0;
public float stunCounter = 0;
private boolean parrying = false; private boolean parrying = false;

View File

@ -43,6 +43,10 @@ public class SwingHitboxListener implements CollisionListener {
this.direction = direction; this.direction = direction;
} }
public CCombat getSourceCombat() {
return cm.get(source);
}
@Override @Override
public void collision(Direction side, Entity host, Entity other) { public void collision(Direction side, Entity host, Entity other) {
if (other.equals(source) || hitEntities.contains(other)) { if (other.equals(source) || hitEntities.contains(other)) {
@ -51,8 +55,7 @@ public class SwingHitboxListener implements CollisionListener {
hitEntities.add(other); hitEntities.add(other);
CCombat sourceCombat = cm.get(source); CCombat sourceCombat = cm.get(source);
CCombat otherCombat = cm.get(other); if (cm.get(other) != null && !sourceCombat.isParrying()) {
if (otherCombat != null && !sourceCombat.isParrying()) {
int damage = cm.get(source).getDamage(); int damage = cm.get(source).getDamage();
CombatSystem.dealDamage(source, other, damage); CombatSystem.dealDamage(source, other, damage);
} }
@ -66,6 +69,7 @@ public class SwingHitboxListener implements CollisionListener {
AudioLoader.getSound(Name.SOUND_CLANG04)); AudioLoader.getSound(Name.SOUND_CLANG04));
s.play(AppUtil.sfxVolume); s.play(AppUtil.sfxVolume);
SwingHitboxListener otherListener = (SwingHitboxListener) otherPhysics.getCollisionListener();
if (!sourceCombat.isParrying()) { if (!sourceCombat.isParrying()) {
// Source isn't parrying, throw back // Source isn't parrying, throw back
float x = 0; float x = 0;
@ -74,6 +78,11 @@ public class SwingHitboxListener implements CollisionListener {
} else if (direction == Direction.RIGHT) { } else if (direction == Direction.RIGHT) {
x = -1; x = -1;
} }
CCombat otherCombat = otherListener.getSourceCombat();
if (otherCombat != null && otherCombat.isParrying()) {
x *= 1.75f;
sourceCombat.stunCounter = otherCombat.getSwingForce() / 10f;
}
pm.get(source).setSimVelocity(x * sourceCombat.getSwingForce(), 0); pm.get(source).setSimVelocity(x * sourceCombat.getSwingForce(), 0);
} }
} }

View File

@ -58,6 +58,10 @@ public class CombatSystem extends EntitySystem {
combat.swingCdCounter -= deltaTime; combat.swingCdCounter -= deltaTime;
continue; continue;
} }
if (combat.stunCounter > 0) {
combat.stunCounter -= deltaTime;
continue;
}
// Ready to swing ! // Ready to swing !
combat.getSwing().setZero(); combat.getSwing().setZero();

View File

@ -74,6 +74,12 @@ public class PhysicsSystem extends EntitySystem {
if (combat.swingCdCounter > 0) { if (combat.swingCdCounter > 0) {
obj.getVelocity().x /= 2; obj.getVelocity().x /= 2;
} }
if (combat.isParrying()) {
obj.getVelocity().x /= 2;
}
if (combat.stunCounter > 0) {
obj.getVelocity().x = 0;
}
} }
if (obj.jumping && obj.isGrounded()) { if (obj.jumping && obj.isGrounded()) {
obj.setGrounded(false); obj.setGrounded(false);