示例#1
0
        private void queryCollision(AxisAlignedBox shape, List <MinimumTranslationVector> collisions)
        {
            var screenAABB = shape;
            var wx0        = Math.Floor(screenAABB.X0 / tileSize);
            var wx1        = Math.Ceiling(screenAABB.X1 / tileSize);
            var wy0        = Math.Floor(screenAABB.Y0 / tileSize);
            var wy1        = Math.Ceiling(screenAABB.Y1 / tileSize);

            var minX = (int)Math.Max(0, wx0);
            var maxX = (int)Math.Min(_width.Number, wx1);
            var minY = (int)Math.Max(0, wy0);
            var maxY = (int)Math.Min(_height.Number, wy1);

            var hs   = tileSize * Game.WORLD_SCALE * Vector2.One;
            var aabb = AxisAlignedBox.FromRect(Vector2.Zero, hs);
            var mtv  = MinimumTranslationVector.Zero;

            for (var y = minY; y < maxY; y++)
            {
                for (var x = minX; x < maxX; x++)
                {
                    if (tiles[x, y].tileType != MapTileType.Room)
                    {
                        aabb.Center = new Vector2(x, y) * tileSize * Game.WORLD_SCALE + hs / 2;

                        var testmtv = shape.collide(aabb);
                        if (testmtv.intersects)
                        {
                            if (!mtv.intersects || testmtv.overlap < mtv.overlap)
                            {
                                mtv = testmtv;
                            }
                        }
                    }
                }
            }

            if (mtv.intersects)
            {
                collisions.Add(mtv);
            }
        }