Simple mining AI

This commit is contained in:
Anuken
2020-08-12 00:08:23 -04:00
parent 8810cf037e
commit 925b1e3057
11 changed files with 150 additions and 68 deletions

View File

@@ -115,6 +115,41 @@ public class AIController implements UnitController{
}
protected void circle(Position target, float circleLength){
circle(target, circleLength, unit.type().speed);
}
protected void circle(Position target, float circleLength, float speed){
if(target == null) return;
vec.set(target).sub(unit);
if(vec.len() < circleLength){
vec.rotate((circleLength - vec.len()) / circleLength * 180f);
}
vec.setLength(speed * Time.delta);
unit.moveAt(vec);
}
protected void moveTo(Position target, float circleLength){
if(target == null) return;
vec.set(target).sub(unit);
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((unit.dst(target) - circleLength) / 100f, -1f, 1f);
vec.setLength(unit.type().speed * Time.delta * length);
if(length < -0.5f){
vec.rotate(180f);
}else if(length < 0){
vec.setZero();
}
unit.moveAt(vec);
}
@Override
public void unit(Unit unit){
if(this.unit == unit) return;