Remade PanicAI.
This commit is contained in:
parent
5ccb90911d
commit
4a38199b09
@ -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;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (po.isGrounded()) {
|
switch ((int) Math.ceil(Math.random() * 4)) {
|
||||||
po.jumping = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (swingCd < swingInterval) {
|
|
||||||
swingCd += Gdx.graphics.getDeltaTime();
|
|
||||||
} else {
|
|
||||||
swingCd = 0;
|
|
||||||
switch ((int) Math.ceil(Math.random() * 6)) {
|
|
||||||
case 1:
|
case 1:
|
||||||
co.inputs.put(Direction.LEFT, true);
|
po.movingLeft = true;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
co.inputs.put(Direction.RIGHT, true);
|
po.movingRight = true;
|
||||||
break;
|
break;
|
||||||
case 3:
|
}
|
||||||
co.inputs.put(Direction.DOWN, true);
|
|
||||||
|
switch ((int) Math.ceil(Math.random() * 3)) {
|
||||||
|
case 1:
|
||||||
|
po.jumping = true;
|
||||||
break;
|
break;
|
||||||
case 4:
|
}
|
||||||
|
|
||||||
|
switch ((int) Math.ceil(Math.random() * 8)) {
|
||||||
|
case 1:
|
||||||
co.inputs.put(Direction.UP, true);
|
co.inputs.put(Direction.UP, true);
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
co.inputs.put(Direction.DOWN, true);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
co.inputs.put(Direction.RIGHT, true);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
co.inputs.put(Direction.LEFT, true);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user