Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bridges on other bridges #351

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions server/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,30 @@ export class GameMap {
return;
}

const spawnHitbox = definition.spawnHitbox.toRectangle().clone();

// if the bridge is sideways it rotates the hitbox accordingly
if (!(bestOrientation % 2 == 0)) {
spawnHitbox.min.y = [spawnHitbox.min.x, spawnHitbox.min.x = spawnHitbox.min.y][0];
spawnHitbox.max.y = [spawnHitbox.max.x, spawnHitbox.max.x = spawnHitbox.max.y][0];
}

const hitbox = spawnHitbox.transform(position);

// checks if the bridge hitbox collides with another object and if so does not spawn it
const objects = this.game.grid.intersectsHitbox(hitbox);
for (const object of objects) {
let objectHitbox: Hitbox | undefined;
if ("spawnHitbox" in object) {
objectHitbox = object.spawnHitbox;
}
if (objectHitbox === undefined) continue;

if (hitbox.collidesWith(objectHitbox)) {
return;
}
}

this.occupiedBridgePositions.push(position);
this.generateBuilding(definition, position, bestOrientation);
spawnedCount++;
Expand Down
Loading