Add support for objects that lie within 2 different sectors.

This commit is contained in:
Ryley Kimmel
2015-03-04 00:06:35 -05:00
parent a69431c46c
commit 4cacdc9891
@@ -144,13 +144,17 @@ public final class GameObjectDecoder {
} }
if (block) { if (block) {
for (int width = 0; width < definition.getWidth(); width++) { for (int dx = 0; dx < definition.getWidth(); dx++) {
for (int length = 0; length < definition.getLength(); length++) { for (int dy = 0; dy < definition.getLength(); dy++) {
int localX = (x % Sector.SECTOR_SIZE) + width, localY = (y % Sector.SECTOR_SIZE) + length; int localX = (x % Sector.SECTOR_SIZE) + dx, localY = (y % Sector.SECTOR_SIZE) + dy;
if (localX > 7 || localY > 7) { if (localX > 7 || localY > 7) {
Sector next = REPOSITORY.fromPosition(new Position(x + localX - 7, y + localY - 7)); Position nextPosition = new Position(x + localX - 7, y + localY - 7);
next.getMatrix(height).block(localX, localY); Sector next = REPOSITORY.fromPosition(nextPosition);
int nextX = (nextPosition.getX() % Sector.SECTOR_SIZE) + dx, nextY = (nextPosition.getY() % Sector.SECTOR_SIZE) + dy;
next.getMatrix(height).block(nextX, nextY);
continue; continue;
} }
@@ -212,8 +216,12 @@ public final class GameObjectDecoder {
int localX = (x % Sector.SECTOR_SIZE), localY = (y % Sector.SECTOR_SIZE); int localX = (x % Sector.SECTOR_SIZE), localY = (y % Sector.SECTOR_SIZE);
if (localX > 7 || localY > 7) { if (localX > 7 || localY > 7) {
Sector next = REPOSITORY.fromPosition(new Position(x + localX - 7, y + localY - 7)); Position nextPosition = new Position(x + localX - 7, y + localY - 7);
next.getMatrix(height).block(localX, localY); Sector next = REPOSITORY.fromPosition(nextPosition);
int nextX = (nextPosition.getX() % Sector.SECTOR_SIZE), nextY = (nextPosition.getY() % Sector.SECTOR_SIZE);
next.getMatrix(height).block(nextX, nextY);
return; return;
} }