This commit is contained in:
simon 2017-12-30 10:30:18 -05:00
parent 9e402fe8a1
commit fd73a47796
4 changed files with 32 additions and 8 deletions

View File

@ -40,7 +40,7 @@ public class ComPort extends CpuHardware {
//Get object directly in front of the Cubot //Get object directly in front of the Cubot
Point frontTile = cubot.getFrontTile(); Point frontTile = cubot.getFrontTile();
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y); ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y);
if (objects.size() > 0 && objects.get(0) instanceof Programmable) { if (objects.size() > 0 && objects.get(0) instanceof Programmable) {

View File

@ -46,7 +46,7 @@ public class CubotLaser extends CpuHardware {
Point frontTile = cubot.getFrontTile(); Point frontTile = cubot.getFrontTile();
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y); ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y);
if (cubot.getCurrentAction() == Action.IDLE && objects.size() > 0) { if (cubot.getCurrentAction() == Action.IDLE && objects.size() > 0) {

View File

@ -17,7 +17,7 @@ public class WorldUtils {
Random random = new Random(); Random random = new Random();
int blobCount = random.nextInt(maxCount - minCount) + minCount; int blobCount = random.nextInt(maxCount - minCount) + minCount;
ArrayList<BiomassBlob> biomassBlobs = new ArrayList<>(maxCount); ArrayList<BiomassBlob> biomassBlobs = new ArrayList<>(blobCount);
//Count number of plain tiles. If there is less plain tiles than desired amount of blobs, //Count number of plain tiles. If there is less plain tiles than desired amount of blobs,
//set the desired amount of blobs to the plain tile count //set the desired amount of blobs to the plain tile count
@ -45,7 +45,7 @@ public class WorldUtils {
//Don't block worlds //Don't block worlds
int counter = 0; int counter = 0;
while (p.x == 0 || p.y == 0 || p.x == World.WORLD_SIZE - 1 || p.y == World.WORLD_SIZE - 1 || while (p.x == 0 || p.y == 0 || p.x == World.WORLD_SIZE - 1 || p.y == World.WORLD_SIZE - 1 ||
world.isTileBlocked(p.x, p.y)) { world.getGameObjectsAt(p.x, p.y).size() != 0) {
p = world.getTileMap().getRandomPlainTile(); p = world.getTileMap().getRandomPlainTile();
counter++; counter++;

View File

@ -54,7 +54,7 @@ public class World implements JSONSerialisable {
*/ */
public boolean isTileBlocked(int x, int y) { public boolean isTileBlocked(int x, int y) {
return getGameObjectsAt(x, y).size() > 0 || tileMap.getTileAt(x, y) == TileMap.WALL_TILE; return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y) == TileMap.WALL_TILE;
} }
@ -245,13 +245,13 @@ public class World implements JSONSerialisable {
} }
/** /**
* Get the list of game objects at a location * Get the list of game objects that are blocking a tile at a set of coordinates
* *
* @param x X coordinate on the World * @param x X coordinate on the World
* @param y Y coordinate on the World * @param y Y coordinate on the World
* @return the list of game objects at a location * @return the list of game objects blocking a location
*/ */
public ArrayList<GameObject> getGameObjectsAt(int x, int y) { public ArrayList<GameObject> getGameObjectsBlockingAt(int x, int y) {
ArrayList<GameObject> gameObjects = new ArrayList<>(2); ArrayList<GameObject> gameObjects = new ArrayList<>(2);
@ -266,6 +266,30 @@ public class World implements JSONSerialisable {
return gameObjects; return gameObjects;
} }
/**
* Get the list of game objects that are exactly at a given location
* <br>
* Note: Objects like the Factory that are more than 1x1 tiles wide will only be returned
* when their exact coordinates are specified
*
* @param x X coordinate on the World
* @param y Y coordinate on the World
* @return the list of game objects at a location
*/
public ArrayList<GameObject> getGameObjectsAt(int x, int y) {
ArrayList<GameObject> gameObjects = new ArrayList<>(2);
for (GameObject obj : this.gameObjects) {
if (obj.getX() == x && obj.getY() == y) {
gameObjects.add(obj);
}
}
return gameObjects;
}
public void incUpdatable() { public void incUpdatable() {
updatable++; updatable++;
} }