/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.objects.primitives;
import transientlibs.slick2d.util.Log;
import transientlibs.maps.implementation.TilelessMap;
import transientlibs.maps.entities.Landmark;
import transientlibs.slick2d.geom.Vector2f;
/**
*
* @author Elwin
*/
public class IntCoords {
public int x;
public int y;
public int z;
public IntCoords () {
x = 0;
y = 0;
z = 0;
}
public IntCoords (int setX, int setY) {
x = setX;
y = setY;
z = 0;
}
public void roundValues () {
x = Math.round(x);
y = Math.round(y);
}
public IntCoords (Vector2f vector) {
x = (int)vector.x;
y = (int)vector.y;
z = 0;
}
@Override
public String toString (){
return x+"/"+y;
}
public int getIntX (){
return x;
}
public int getIntY (){
return y;
}
public double returnDistance (IntCoords c) {
double distance;
double x1 = x;
double y1 = y;
double x2 = c.x;
double y2 = c.y;
distance = Math.round(Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)));
return distance;
}
public static void checkIfValidScrolling (TilelessMap mapLink) {
if (mapLink.eye.eyePosition.getIntX() < (mapLink.eye.eyeSizeX * -1)) {
mapLink.eye.eyePosition.x = mapLink.eye.eyeSizeX * -1;
}
if (mapLink.eye.eyePosition.getIntY() < (mapLink.eye.eyeSizeY * -1)) {
mapLink.eye.eyePosition.y = mapLink.eye.eyeSizeY * -1;
}
if (mapLink.eye.eyePosition.getIntX() > mapLink.sizeX) {
mapLink.eye.eyePosition.x = mapLink.sizeX;
}
if (mapLink.eye.eyePosition.getIntY() > mapLink.sizeY) {
mapLink.eye.eyePosition.y = mapLink.sizeY;
}
}
public void move (int dx, int dy) {
x += dx;
y += dy;
}
public void checkIfApproximatelySame (IntCoords otherCoords) {
if (Math.abs(otherCoords.x - x) < 0.1) {x = otherCoords.x;}
if (Math.abs(otherCoords.y - y) < 0.1) {y = otherCoords.y;}
}
public boolean isSame (IntCoords otherCoords) {
return ((x == otherCoords.x) && (y == otherCoords.y));
}
public IntCoords returnAdjustedCoords (int direction) {
IntCoords result = new IntCoords();
//Log.info("Try direction "+direction);
if (direction == 1) {
result.x = x - 1;
result.y = y + 1;
}
if (direction == 2) {
result.x = x;
result.y = y + 1;
}
if (direction == 3) {
result.x = x + 1;
result.y = y + 1;
}
if (direction == 4) {
result.x = x - 1;
result.y = y;
}
if (direction == 5) {
result.x = x;
result.y = y;
}
if (direction == 6) {
result.x = x + 1;
result.y = y;
}
if (direction == 7) {
result.x = x - 1;
result.y = y - 1;
}
if (direction == 8) {
result.x = x;
result.y = y - 1;
}
if (direction == 9) {
result.x = x + 1;
result.y = y - 1;
}
return result;
}
public int calculateVector (int toX, int toY) {
return calculateVector (new IntCoords(toX, toY));
}
public int calculateVector (IntCoords targetCoords) {
if ((targetCoords.x > x) && (targetCoords.y > y)) {
return 3;
} else
if ((targetCoords.x > x) && (targetCoords.y == y)) {
return 6;
} else
if ((targetCoords.x == x) && (targetCoords.y > y)) {
return 2;
} else
if ((targetCoords.x < x) && (targetCoords.y > y)) {
return 7;
} else
if ((targetCoords.x > x) && (targetCoords.y < y)) {
return 9;
} else
if ((targetCoords.x == x) && (targetCoords.y < y)) {
return 8;
} else
if ((targetCoords.x < x) && (targetCoords.y < y)) {
return 1;
} else
if ((targetCoords.x < x) && (targetCoords.y == y)) {
return 4;
}
return -1;
}
// TODO: maybe move Coords to Vector2f?
public Vector2f toVector2f() {
return new Vector2f((float) x, (float) y);
}
public void copyFrom(IntCoords screenCoords) {
x = screenCoords.x;
y = screenCoords.y;
z = screenCoords.z;
Log.info("Set X to "+x);
}
}