コード例 #1
0
        public void UnblockRect(Rect blockingBounds)
        {
            Point blockTopLeft     = GeometryUtils.GetChunkPosition(blockingBounds.Left, blockingBounds.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
            Point blockBottomRight = GeometryUtils.GetChunkPosition(blockingBounds.Right, blockingBounds.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

            for (int blockX = blockTopLeft.X; blockX <= blockBottomRight.X; blockX++)
            {
                for (int blockY = blockTopLeft.Y; blockY <= blockBottomRight.Y; blockY++)
                {
                    Point walkableGridChunkPos = GeometryUtils.GetChunkPosition(blockX, blockY, WalkableGridBlockChunkSize.X, WalkableGridBlockChunkSize.Y);

                    if (IsLoaded(GeometryUtils.ConvertPointToLong(walkableGridChunkPos.X, walkableGridChunkPos.Y)))
                    {
                        Point          worldGridChunkPos = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                        WorldGridChunk worldGridChunk    = SimulationGame.World.GetFromChunkPoint(worldGridChunkPos.X, worldGridChunkPos.Y);
                        int            blockType         = worldGridChunk.GetBlockType(blockX, blockY);

                        if (CollisionUtils.IsBlockBlocking(blockType))
                        {
                            continue;
                        }

                        var found = false;

                        if (worldGridChunk.ContainedObjects != null)
                        {
                            foreach (HitableObject interactiveObject in worldGridChunk.ContainedObjects)
                            {
                                if (interactiveObject.IsBlocking() && interactiveObject.BlockingBounds.Intersects(new Rect(blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y)))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }

                        if (worldGridChunk.OverlappingObjects != null)
                        {
                            foreach (HitableObject interactiveObject in worldGridChunk.OverlappingObjects)
                            {
                                if (interactiveObject.IsBlocking() && interactiveObject.BlockingBounds.Intersects(new Rect(blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y)))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }

                        if (!found)
                        {
                            SetBlockNotWalkable(blockX, blockY, false);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void RefreshBlock(int blockX, int blockY)
        {
            Point walkableGridChunkPos = GeometryUtils.GetChunkPosition(blockX, blockY, WalkableGridBlockChunkSize.X, WalkableGridBlockChunkSize.Y);

            if (IsLoaded(GeometryUtils.ConvertPointToLong(walkableGridChunkPos.X, walkableGridChunkPos.Y)))
            {
                Point          worldGridChunkPos = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                WorldGridChunk worldGridChunk    = SimulationGame.World.GetFromChunkPoint(worldGridChunkPos.X, worldGridChunkPos.Y);
                int            blockType         = worldGridChunk.GetBlockType(blockX, blockY);

                if (CollisionUtils.IsBlockBlocking(blockType))
                {
                    SetBlockNotWalkable(blockX, blockY, true);
                    return;
                }

                var found = false;

                if (worldGridChunk.ContainedObjects != null)
                {
                    foreach (HitableObject interactiveObject in worldGridChunk.ContainedObjects)
                    {
                        if (interactiveObject.IsBlocking() && interactiveObject.BlockingBounds.Intersects(new Rect(blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y)))
                        {
                            found = true;
                            break;
                        }
                    }
                }

                if (worldGridChunk.OverlappingObjects != null)
                {
                    foreach (HitableObject interactiveObject in worldGridChunk.OverlappingObjects)
                    {
                        if (interactiveObject.IsBlocking() && interactiveObject.BlockingBounds.Intersects(new Rect(blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y)))
                        {
                            found = true;
                            break;
                        }
                    }
                }

                SetBlockNotWalkable(blockX, blockY, found);
            }
        }