fix: prevent getFreeNeighbour from choosing positions outside of the map

This commit is contained in:
punchready 2021-07-06 12:55:53 +02:00
parent a7b0514bd8
commit 70529f04d8

View File

@ -711,8 +711,12 @@ public class GameLogic {
}
for(IntVector2 dir: IntVector2.CardinalDirections) {
if(state.entities.findByPosition(start.add(dir)).size() == 0) {
options.add(start.add(dir));
IntVector2 pos = start.add(dir);
if(pos.getX() < 0 || pos.getX() >= state.mapSize.getX() || pos.getY() < 0 || pos.getY() >= state.mapSize.getY()) {
return options;
}
if(state.entities.findByPosition(pos).size() == 0) {
options.add(pos);
}
}