From 45f48cc8fd4aae9d213850b3e0d6e4b2953b5942 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 25 Sep 2019 21:06:56 +0200 Subject: [PATCH] fixed tile map collisions going out of bounds with big areas --- MLEM.Extended/Tiled/TiledMapCollisions.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MLEM.Extended/Tiled/TiledMapCollisions.cs b/MLEM.Extended/Tiled/TiledMapCollisions.cs index c5daa76..84ff91c 100644 --- a/MLEM.Extended/Tiled/TiledMapCollisions.cs +++ b/MLEM.Extended/Tiled/TiledMapCollisions.cs @@ -43,9 +43,13 @@ namespace MLEM.Extended.Tiled { public IEnumerable GetCollidingTiles(RectangleF area, Func included = null) { var inclusionFunc = included ?? (tile => tile.Collisions.Any(c => c.Intersects(area))); + var minX = Math.Max(0, area.Left.Floor()); + var maxX = Math.Min(this.map.Width - 1, area.Right); + var minY = Math.Max(0, area.Top.Floor()); + var maxY = Math.Min(this.map.Height - 1, area.Bottom); for (var i = 0; i < this.map.TileLayers.Count; i++) { - for (var x = area.Left.Floor(); x <= area.Right; x++) { - for (var y = area.Top.Floor(); y <= area.Bottom; y++) { + for (var x = minX; x <= maxX; x++) { + for (var y = minY; y <= maxY; y++) { var tile = this.collisionInfos[i, x, y]; if (tile == null) continue;