/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.maps.utils.movementcalculators;
import transientlibs.maps.tiles.Tile;
import transientlibs.maps.implementation.TilelessMap;
import transientlibs.maps.entities.MapObject;
import transientlibs.maps.utils.movementcalculators.AbstractTileMovementCalculator;
/**
*
* @author kibertoad
*/
public class PlatformMovementCalculator extends AbstractTileMovementCalculator{
public PlatformMovementCalculator (TilelessMap setMap){
super(setMap);
}
@Override
public boolean terrainCollision (double deltaX, double deltaY, MapObject mo){
boolean result = false;
double checkX = mo.mapCoords.x+deltaX;
double checkY = mo.mapCoords.y+deltaY;
// Log.info("SizeX: "+this.mapSizeX);
// Log.info("SizeY: "+this.mapSizeY);
double xSize = mo.mapSizeX-0.1;
double ySize = mo.mapSizeY-0.1;
if (xSize < 0) {
xSize += 0.1;
}
if (ySize < 0) {
ySize += 0.1;
}
double x1 = checkX;
double x2 = x1+xSize;
double y1 = checkY;
double y2 = y1+ySize;
double xStep = Math.min(xSize, 1.0);
double yStep = Math.min(ySize, 1.0);
if (((int)y1 == 0) || ((int)x1 == 0) || ((int)x1>mo.onMap.sizeX) || ((int)y1>mo.onMap.sizeY)){ result = true;} else {
for (double x = x1; x <= x2; x += xStep) {
for (double y = y1; y <= y2; y += yStep) {
int ix = (int) x;
int iy = (int) y;
Tile targetTile = mo.onMap.getTile(ix, iy);
result = result || (targetTile != null && targetTile.terrain.moveCost == -1);
}
}
}
return result;
}
}