This commit is contained in:
parent
5c5084f211
commit
a92a0c021e
20 changed files with 281 additions and 12 deletions
|
|
@ -199,6 +199,21 @@ public class Map {
|
|||
float yf = (POS_SIZE*y);
|
||||
return new Vector2f(xf,yf);
|
||||
}
|
||||
public static Vector2f getPixelByPos(int x, int y, int size){
|
||||
if(size%2!=0) {
|
||||
size = (size/2)+1;
|
||||
float xf = (POS_SIZE)*(x+size);
|
||||
float yf = (POS_SIZE)*(y+size);
|
||||
return new Vector2f(xf,yf);
|
||||
}
|
||||
size = (size/2)-1;
|
||||
float xDiff = Math.abs((getPixelByPos(x+size, 0).getX())-(getPixelByPos(size+x+1, 0).getX()))/2;
|
||||
float yDiff = Math.abs((getPixelByPos(0, size+y).getY())-(getPixelByPos(0, size+y+1).getY()))/2;
|
||||
|
||||
return new Vector2f(getPixelByPos(x+size, 0).getX()+xDiff, getPixelByPos(0, y+size).getY()+yDiff);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the pos inthe map is empty
|
||||
|
|
@ -213,6 +228,24 @@ public class Map {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns true if the pos in the map is empty
|
||||
* @param x pos
|
||||
* @param y pos
|
||||
* @param size, size to check
|
||||
* @return true if pos is empty, else false
|
||||
*/
|
||||
public boolean isPosEmpty(int x, int y, int size) {
|
||||
for(int i=x; i<size+x; i++) {
|
||||
for(int j=y; j<size+y; j++) {
|
||||
if(posExist(i,j) && map[i][j] == null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given pos exists on the map
|
||||
|
|
@ -247,7 +280,36 @@ public class Map {
|
|||
public void setPos(GameEntity e, int x, int y){
|
||||
map[x][y] = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object in a rectangle of size*size, starting at x,y
|
||||
* @param e object
|
||||
* @param x pos
|
||||
* @param y pos
|
||||
* @param size
|
||||
*/
|
||||
public void setBuildPos(GameEntity e, int x, int y, int size) {
|
||||
if(isPosEmpty(x, y, size)) {
|
||||
for(int i=x; i<size+x; i++) {
|
||||
for(int j=y; j<size+y; j++) {
|
||||
map[i][j] = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove an object from this position
|
||||
* @param e, the object
|
||||
* @param x pos of object
|
||||
* @param y pos of object
|
||||
* @param size of object
|
||||
*/
|
||||
public void removeBuildPos(int x, int y, int size) {
|
||||
for(int i=x; i<size+x; i++) {
|
||||
for(int j=y; j<size+y; j++) {
|
||||
map[i][j] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes a object from that pos
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue