Knockback on sword collision added.
This commit is contained in:
parent
2c4f2dbfa3
commit
71d1001bbd
@ -8,33 +8,35 @@ import com.saltosion.gladiator.listeners.CombatListener;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
|
||||
public class CCombat extends Component {
|
||||
|
||||
|
||||
public int health = 0;
|
||||
private int maxHealth = 0;
|
||||
private int damage = 0;
|
||||
private float swingForce = 20f;
|
||||
private Vector2 swingsize = new Vector2(4, 3);
|
||||
private CombatListener combatListener;
|
||||
|
||||
|
||||
private Vector2 swinging = new Vector2();
|
||||
private float swingDuration = 0.4f;
|
||||
public float swingCdCounter = 0;
|
||||
|
||||
public HashMap<Direction, Boolean> inputs = new HashMap<Direction, Boolean>();
|
||||
|
||||
|
||||
public CCombat() {
|
||||
this.inputs.put(Direction.UP, false);
|
||||
this.inputs.put(Direction.DOWN, false);
|
||||
this.inputs.put(Direction.LEFT, false);
|
||||
this.inputs.put(Direction.RIGHT, false);
|
||||
}
|
||||
|
||||
|
||||
public CCombat setBaseDamage(int basedmg) {
|
||||
this.damage = basedmg;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets max health for entity and replenishes health.
|
||||
*
|
||||
* @param health
|
||||
* @return
|
||||
*/
|
||||
@ -43,54 +45,63 @@ public class CCombat extends Component {
|
||||
this.maxHealth = health;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CCombat setMaxHealth(int maxHealth) {
|
||||
this.maxHealth = maxHealth;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CCombat setSwingForce(float force) {
|
||||
this.swingForce = force;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CCombat setSwingCD(float cd) {
|
||||
this.swingDuration = cd;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CCombat setSwinging(Vector2 swingdir) {
|
||||
this.swinging = swingdir;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CCombat setSwingSize(Vector2 swingsize) {
|
||||
this.swingsize = swingsize;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public CCombat setCombatListener(CombatListener listener) {
|
||||
this.combatListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public int getMaxHealth() {
|
||||
return this.maxHealth;
|
||||
}
|
||||
|
||||
|
||||
public int getDamage() {
|
||||
float minDmg = damage*0.9f;
|
||||
float maxDmg = damage*1.1f;
|
||||
int randomdamage = (int) (Math.random()*(maxDmg-minDmg)+minDmg);
|
||||
float minDmg = damage * 0.9f;
|
||||
float maxDmg = damage * 1.1f;
|
||||
int randomdamage = (int) (Math.random() * (maxDmg - minDmg) + minDmg);
|
||||
if (Math.random() > 0.7) {
|
||||
randomdamage *= 1.5;
|
||||
}
|
||||
return randomdamage;
|
||||
}
|
||||
|
||||
|
||||
public float getSwingForce() {
|
||||
return swingForce;
|
||||
}
|
||||
|
||||
public float getSwingDuration() {
|
||||
return this.swingDuration;
|
||||
}
|
||||
|
||||
|
||||
public Vector2 getSwing() {
|
||||
return this.swinging;
|
||||
}
|
||||
|
||||
|
||||
public Direction getSwingDirection() {
|
||||
if (swinging.x > 0) {
|
||||
return Direction.RIGHT;
|
||||
@ -103,11 +114,11 @@ public class CCombat extends Component {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Vector2 getSwingSize() {
|
||||
return this.swingsize;
|
||||
}
|
||||
|
||||
|
||||
public CombatListener getCombatListener() {
|
||||
return this.combatListener;
|
||||
}
|
||||
|
@ -9,8 +9,9 @@ public class CPhysics extends Component {
|
||||
|
||||
private final Vector2 position = new Vector2();
|
||||
private final Vector2 velocity = new Vector2();
|
||||
private final Vector2 simVelocity = new Vector2();
|
||||
private final Vector2 size = new Vector2();
|
||||
private float movespeed = 15f, jumpForce = 35f, gravity = 100f;
|
||||
private float movespeed = 15f, jumpForce = 35f, gravity = 100f, drag = 30f;
|
||||
private CollisionListener collisionListener = null;
|
||||
private float zParallax = 1;
|
||||
|
||||
@ -90,8 +91,33 @@ public class CPhysics extends Component {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CPhysics setVelocity(Vector2 pos) {
|
||||
this.velocity.set(pos);
|
||||
public CPhysics setVelocity(Vector2 vel) {
|
||||
this.velocity.set(vel);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This velocity can be set externally and will always end up being 0 after
|
||||
* some time that depends on the value of the drag variable
|
||||
*
|
||||
* @param x The x part of the new sim velocity
|
||||
* @param y The y part of the new sim velocity
|
||||
* @return The host component
|
||||
*/
|
||||
public CPhysics setSimVelocity(float x, float y) {
|
||||
this.simVelocity.set(x, y);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This velocity can be set externally and will always end up being 0 after
|
||||
* some time that depends on the value of the drag variable
|
||||
*
|
||||
* @param simVel The new sim velocity
|
||||
* @return The host component
|
||||
*/
|
||||
public CPhysics setSimVelocity(Vector2 simVel) {
|
||||
this.simVelocity.set(simVel);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -108,7 +134,11 @@ public class CPhysics extends Component {
|
||||
public CPhysics setGravity(float gravity) {
|
||||
this.gravity = gravity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CPhysics setDrag(float drag) {
|
||||
this.drag = drag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CPhysics setCollisionListener(CollisionListener collisionListener) {
|
||||
@ -139,6 +169,10 @@ public class CPhysics extends Component {
|
||||
return this.velocity;
|
||||
}
|
||||
|
||||
public Vector2 getSimVelocity() {
|
||||
return this.simVelocity;
|
||||
}
|
||||
|
||||
public Vector2 getSize() {
|
||||
return this.size;
|
||||
}
|
||||
@ -155,6 +189,10 @@ public class CPhysics extends Component {
|
||||
return this.gravity;
|
||||
}
|
||||
|
||||
public float getDrag() {
|
||||
return this.drag;
|
||||
}
|
||||
|
||||
public CollisionListener getCollisionListener() {
|
||||
return this.collisionListener;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.saltosion.gladiator.level.Level;
|
||||
import com.saltosion.gladiator.util.AppUtil;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
import com.saltosion.gladiator.util.Global;
|
||||
import com.saltosion.gladiator.util.Log;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Round1Level implements Level {
|
||||
|
@ -39,14 +39,16 @@ public class SwingHitboxListener implements CollisionListener {
|
||||
CPhysics otherPhysics = pm.get(other);
|
||||
if (otherPhysics != null && otherPhysics.getCollisionListener() != null
|
||||
&& otherPhysics.getCollisionListener() instanceof SwingHitboxListener) {
|
||||
Log.info("Clash!");
|
||||
float x = 0;
|
||||
float x = 0, y = 0;
|
||||
if (direction == Direction.LEFT) {
|
||||
x = -1;
|
||||
}
|
||||
if (direction == Direction.RIGHT) {
|
||||
x = 1;
|
||||
} else if (direction == Direction.RIGHT) {
|
||||
x = -1;
|
||||
} else if (direction == Direction.DOWN) {
|
||||
y = 1;
|
||||
}
|
||||
float force = cm.get(source).getSwingForce();
|
||||
pm.get(source).setSimVelocity(x * force, y * force / 8f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,12 @@ public class PhysicsSystem extends EntitySystem {
|
||||
obj.setGrounded(false);
|
||||
obj.getVelocity().y = obj.getJumpForce();
|
||||
}
|
||||
|
||||
obj.getVelocity().x += obj.getSimVelocity().x;
|
||||
obj.getVelocity().y += obj.getSimVelocity().y;
|
||||
|
||||
obj.getSimVelocity().x -= obj.getDrag() * deltaTime * Math.signum(obj.getSimVelocity().x);
|
||||
obj.getSimVelocity().y -= obj.getDrag() * deltaTime * Math.signum(obj.getSimVelocity().y);
|
||||
}
|
||||
|
||||
// Gravity
|
||||
|
Loading…
Reference in New Issue
Block a user