-
-
Notifications
You must be signed in to change notification settings - Fork 559
Adding AI
Almas Baimagambetov edited this page Jul 14, 2017
·
4 revisions
There are multiple ways of adding AI to your enemy entities.
The most basic AI can be added by attaching a Control
to an entity.
An example of a simple "sensor" AI as follows:
class SensorControl extends Control {
@Override
public void onUpdate(Entity entity, double tpf) {
Entity player = FXGL.getApp().getGameWorld() ...
if (distanceToPlayer(player) < 100) {
// constantly signal other AI that player is close
} else {
// stop signalling
}
}
private double distanceToPlayer(Entity player) {
return player.getComponent(PositionComponent.class).distance(getEntity().getComponent(PositionComponent.class));
}
}
TODO
TODO