/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.maps.utils.fov;
import transientlibs.maps.utils.fov.FOVBoard;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import transientlibs.rlforj.los.BresLos;
import transientlibs.rlforj.los.ILosBoard;
import transientlibs.rlforj.math.Point2I;
import transientlibs.bindedobjects.gamecontent.Terrain;
import transientlibs.processors.misc.Detonator;
import transientlibs.maps.container.TransientAssembledMap;
import transientlibs.objects.primitives.Coords;
import transientlibs.preui.objects.gui.interfaces.IImage;
/**
*
* @author kibertoad
*/
public class LOSCalculator {
public IImage greenTile;
public IImage redTile;
public FOVBoard board;
public BresLos BresenhamCalculator = new BresLos(false);
public TransientAssembledMap map;
public Coords fromCoords;
public Coords toCoords;
public int fromScreenX;
public int fromScreenY;
public List<Point2I> path = new ArrayList<Point2I>();
public ArrayList<Coords> cpath = new ArrayList<Coords>();
public void calculatePath(ILosBoard b, Coords setFromCoords, Coords setToCoords) {
board = (FOVBoard)b;
fromCoords = setFromCoords;
toCoords = setToCoords;
calculatePath();
}
public void calculatePath (){
BresenhamCalculator.existsLineOfSight(board, fromCoords.getIntX(), fromCoords.getIntY(), toCoords.getIntX(), toCoords.getIntY(), true);
path = BresenhamCalculator.getProjectPath();
fromScreenX = map.getTileScreenCoords(path.get(0).x, path.get(0).y).getIntX();
fromScreenY = map.getTileScreenCoords(path.get(0).x, path.get(0).y).getIntY();
}
public void renderPath(){
int onX;
int onY;
Iterator<Point2I> it = path.iterator();
it.next();
while (it.hasNext()) {
Point2I coords = it.next();
onX = fromScreenX + ((coords.x - fromCoords.getIntX())*Terrain.tileWidth);
onY = fromScreenY + ((coords.y - fromCoords.getIntY())*Terrain.tileHeight);
if (Detonator.INSTANCE.tileMovementCalculator.isShootingObstacle (coords.x, coords.y)) {
redTile.draw(onX, onY);
} else{
greenTile.draw(onX, onY);
}
}
}
}