Creatures are now slowed when attacking

This commit is contained in:
Allexit 2015-05-10 23:33:41 +03:00
parent 82dba2bb39
commit 47a1a193a4
4 changed files with 15 additions and 7 deletions

View File

@ -91,7 +91,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
renderedObject.playAnimation("Idle"); renderedObject.playAnimation("Idle");
player.add(renderedObject); player.add(renderedObject);
player.add(new CPhysics().setSize(2, 4).setPosition(0, 5)); player.add(new CPhysics().setSize(2, 4).setPosition(0, 5));
player.add(new CCombat().setBaseDamage(100).setHealth(1000).setSwingCD(.5f)); player.add(new CCombat().setBaseDamage(100).setHealth(1000));
engine.addEntity(player); engine.addEntity(player);
AppUtil.player = player; AppUtil.player = player;

View File

@ -16,7 +16,7 @@ public class CCombat extends Component {
private CombatListener combatListener; private CombatListener combatListener;
private Vector2 swinging = new Vector2(); private Vector2 swinging = new Vector2();
private float swingCd = 0; private float swingDuration = 0.4f;
public float swingCdCounter = 0; public float swingCdCounter = 0;
public HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>(); public HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>();
@ -50,7 +50,7 @@ public class CCombat extends Component {
} }
public CCombat setSwingCD(float cd) { public CCombat setSwingCD(float cd) {
this.swingCd = cd; this.swingDuration = cd;
return this; return this;
} }
@ -83,8 +83,8 @@ public class CCombat extends Component {
return randomdamage; return randomdamage;
} }
public float getSwingCD() { public float getSwingDuration() {
return this.swingCd; return this.swingDuration;
} }
public Vector2 getSwing() { public Vector2 getSwing() {

View File

@ -68,7 +68,7 @@ public class CombatSystem extends EntitySystem {
} }
createSwingHitbox(e, pos); createSwingHitbox(e, pos);
combat.swingCdCounter = combat.getSwingCD(); combat.swingCdCounter = combat.getSwingDuration();
} }
} }
} }
@ -81,7 +81,7 @@ public class CombatSystem extends EntitySystem {
e.add(new CPhysics().setGhost(true).setGravityApplied(false).setMovable(false) e.add(new CPhysics().setGhost(true).setGravityApplied(false).setMovable(false)
.setSize(combat.getSwingSize())); .setSize(combat.getSwingSize()));
e.getComponent(CPhysics.class).setPosition(position).setCollisionListener(new SwingHitboxListener(source)); e.getComponent(CPhysics.class).setPosition(position).setCollisionListener(new SwingHitboxListener(source));
e.add(new CDestructive(.1f)); e.add(new CDestructive(combat.getSwingDuration()/2));
AppUtil.engine.addEntity(e); AppUtil.engine.addEntity(e);
} }

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.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
@ -17,6 +18,7 @@ public class PhysicsSystem extends EntitySystem {
private static final float MAX_VEL = 0.5f; private static final float MAX_VEL = 0.5f;
private ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class); private ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
private ComponentMapper<CCombat> cm = ComponentMapper.getFor(CCombat.class);
private ImmutableArray<Entity> entities; private ImmutableArray<Entity> entities;
@Override @Override
@ -29,6 +31,7 @@ public class PhysicsSystem extends EntitySystem {
deltaTime = Math.min(deltaTime, 0.033f); deltaTime = Math.min(deltaTime, 0.033f);
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
CPhysics obj = pm.get(entities.get(i)); CPhysics obj = pm.get(entities.get(i));
CCombat combat = cm.get(entities.get(i));
// Apply movement // Apply movement
obj.getPosition().add(obj.getVelocity()); obj.getPosition().add(obj.getVelocity());
@ -43,6 +46,11 @@ public class PhysicsSystem extends EntitySystem {
move++; move++;
} }
obj.getVelocity().x = move * obj.getMovespeed() * deltaTime; obj.getVelocity().x = move * obj.getMovespeed() * deltaTime;
if (combat != null) {
if (combat.swingCdCounter > 0) {
obj.getVelocity().x /= 2;
}
}
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();