mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 01:39:23 +01:00
fixed tile map collisions going out of bounds with big areas
This commit is contained in:
parent
edcc7d44b5
commit
45f48cc8fd
1 changed files with 6 additions and 2 deletions
|
@ -43,9 +43,13 @@ namespace MLEM.Extended.Tiled {
|
|||
|
||||
public IEnumerable<TileCollisionInfo> GetCollidingTiles(RectangleF area, Func<TileCollisionInfo, bool> 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;
|
||||
|
|
Loading…
Reference in a new issue