GooseLogic.java
package io.github.some_example_name;
import com.badlogic.gdx.math.Vector2;
/**
* Handles movement and interaction logic for Goose.
*/
public class GooseLogic {
private Vector2 position;
private float speed;
private float stopDistance;
private boolean fed;
public GooseLogic(float x, float y, float speed, float stopDistance) {
this.position = new Vector2(x, y);
this.speed = speed;
this.stopDistance = stopDistance;
this.fed = false;
}
public void update(Vector2 playerPos, float delta, CellBlockChecker checker) {
if (fed) return;
float distance = position.dst(playerPos);
if (distance <= stopDistance) return;
Vector2 direction = new Vector2(playerPos).sub(position).nor();
float newX = position.x + direction.x * speed * delta;
float newY = position.y + direction.y * speed * delta;
if (!checker.isCellBlocked(newX, newY)) {
position.set(newX, newY);
}
}
public boolean caughtPlayer(Vector2 playerPos) {
return position.dst(playerPos) <= stopDistance;
}
public void feed() {
fed = true;
}
public void reduceStopDistance() {
stopDistance = 5f;
}
public Vector2 getPosition() {
return position;
}
public boolean isFed() {
return fed;
}
}