DeanLogic.java
package io.github.some_example_name;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
public class DeanLogic {
private final Vector2 position;
private final Vector2 startPosition;
private boolean repelled = false;
private final float speed;
public DeanLogic(float x, float y, float speed) {
this.position = new Vector2(x, y);
this.startPosition = new Vector2(x, y);
this.speed = speed;
}
public void update(Vector2 playerPos, float delta, CellBlockChecker checker) {
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) {
if (repelled) return false;
Rectangle deanRect = new Rectangle(position.x, position.y, 16, 16);
Rectangle playerRect = new Rectangle(playerPos.x, playerPos.y, 16, 16);
return deanRect.overlaps(playerRect);
}
public void resetToStart() {
position.set(startPosition);
}
public void setRepelled(boolean repelled) {
this.repelled = repelled;
}
public Vector2 getPosition() {
return position;
}
}