Remade PanicAI.

This commit is contained in:
Jeasonfire 2015-05-18 04:20:09 +03:00
parent 5ccb90911d
commit 4a38199b09
1 changed files with 45 additions and 28 deletions

View File

@ -27,53 +27,70 @@ import java.util.ArrayList;
public class PanicAI implements AIListener { public class PanicAI implements AIListener {
private float swingCd = 0; private float stateChange = 0;
private final float swingInterval; private final float stateChangeInterval;
public PanicAI() { public PanicAI() {
swingInterval = 0.75f; stateChangeInterval = 1;
} }
public PanicAI(float swingInterval) { public PanicAI(float stateChangeInterval) {
this.swingInterval = swingInterval; this.stateChangeInterval = stateChangeInterval;
} }
@Override @Override
public void react(ArrayList<Entity> closeEntities, Entity host) { public void react(ArrayList<Entity> closeEntities, Entity host) {
stateChange += Gdx.graphics.getDeltaTime();
if (stateChange > stateChangeInterval) {
stateChange = 0;
} else {
return;
}
if (closeEntities.isEmpty()) {
return;
}
CPhysics po = host.getComponent(CPhysics.class); CPhysics po = host.getComponent(CPhysics.class);
CCombat co = host.getComponent(CCombat.class); CCombat co = host.getComponent(CCombat.class);
po.movingLeft = false;
po.movingRight = false;
po.jumping = false;
po.setMoveSpeed(16);
co.inputs.put(Direction.UP, false); co.inputs.put(Direction.UP, false);
co.inputs.put(Direction.DOWN, false); co.inputs.put(Direction.DOWN, false);
co.inputs.put(Direction.RIGHT, false); co.inputs.put(Direction.RIGHT, false);
co.inputs.put(Direction.LEFT, false); co.inputs.put(Direction.LEFT, false);
if (closeEntities.isEmpty()) {
po.jumping = false; switch ((int) Math.ceil(Math.random() * 4)) {
return; case 1:
po.movingLeft = true;
break;
case 2:
po.movingRight = true;
break;
} }
if (po.isGrounded()) { switch ((int) Math.ceil(Math.random() * 3)) {
po.jumping = true; case 1:
po.jumping = true;
break;
} }
if (swingCd < swingInterval) { switch ((int) Math.ceil(Math.random() * 8)) {
swingCd += Gdx.graphics.getDeltaTime(); case 1:
} else { co.inputs.put(Direction.UP, true);
swingCd = 0; break;
switch ((int) Math.ceil(Math.random() * 6)) { case 2:
case 1: co.inputs.put(Direction.DOWN, true);
co.inputs.put(Direction.LEFT, true); break;
break; case 3:
case 2: co.inputs.put(Direction.RIGHT, true);
co.inputs.put(Direction.RIGHT, true); break;
break; case 4:
case 3: co.inputs.put(Direction.LEFT, true);
co.inputs.put(Direction.DOWN, true); break;
break;
case 4:
co.inputs.put(Direction.UP, true);
break;
}
} }
} }
} }