package se.urmo.game.collision;

import lombok.extern.slf4j.Slf4j;
import se.urmo.game.entities.ghost.Ghost;
import se.urmo.game.map.GameMap;
import se.urmo.game.util.Direction;
import se.urmo.game.util.MyPoint;

import java.util.List;

@Slf4j
public class GhostCollisionChecker {
    private final GameMap map;

    public GhostCollisionChecker(GameMap map) {
        this.map = map;
    }

    public List<Direction> calculateDirectionAlternatives(Ghost ghost, MyPoint position) {
        List<Direction> intersection = map.directionAlternatives(ghost, (int) position.x, (int) position.y);
        log.info("Possible travel directions: {}", intersection);
        return intersection;
    }


    public MyPoint canMoveTo(Ghost ghost, Direction dir, double x, double y) {
        // -1 is because else we endup in next tile
        return !map.isSolidXY(ghost,
                (int) (x) + dir.dx * (GameMap.MAP_TILESIZE/2 - 1),
                (int) (y) + dir.dy * (GameMap.MAP_TILESIZE/2 - 1)) ? new MyPoint(x,y) : null;
    }
}
