mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Fixes #65
This commit is contained in:
parent
9e402fe8a1
commit
fd73a47796
@ -40,7 +40,7 @@ public class ComPort extends CpuHardware {
|
||||
|
||||
//Get object directly in front of the Cubot
|
||||
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) {
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class CubotLaser extends CpuHardware {
|
||||
|
||||
|
||||
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) {
|
||||
|
@ -17,7 +17,7 @@ public class WorldUtils {
|
||||
|
||||
Random random = new Random();
|
||||
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,
|
||||
//set the desired amount of blobs to the plain tile count
|
||||
@ -45,7 +45,7 @@ public class WorldUtils {
|
||||
//Don't block worlds
|
||||
int counter = 0;
|
||||
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();
|
||||
counter++;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class World implements JSONSerialisable {
|
||||
*/
|
||||
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 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);
|
||||
|
||||
@ -266,6 +266,30 @@ public class World implements JSONSerialisable {
|
||||
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() {
|
||||
updatable++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user