Skip to content

Commit 50a0598

Browse files
committed
fix: oops edge of map crash
1 parent 6d38bf2 commit 50a0598

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/game/GameMap.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,12 @@ export class GameMapImpl implements GameMap {
300300
): Set<TileRef> {
301301
const center = { x: this.x(tile), y: this.y(tile) };
302302
const tiles: Set<TileRef> = new Set<TileRef>();
303-
for (let i = center.x - radius; i <= center.x + radius; ++i) {
304-
for (let j = center.y - radius; j <= center.y + radius; j++) {
303+
const minX = Math.max(0, center.x - radius);
304+
const maxX = Math.min(this.width_ - 1, center.x + radius);
305+
const minY = Math.max(0, center.y - radius);
306+
const maxY = Math.min(this.height_ - 1, center.y + radius);
307+
for (let i = minX; i <= maxX; ++i) {
308+
for (let j = minY; j <= maxY; j++) {
305309
const t = this.ref(i, j);
306310
const d2 = this.euclideanDistSquared(tile, t);
307311
if (d2 > radius * radius) continue;

0 commit comments

Comments
 (0)