Beispiel #1
0
        public static NodeMap CreateFromTileMap(TileMap tileMap, SpritePolygon collisionPolygon)
        {
            NodeMap nodeMap = new NodeMap(tileMap.MapWidthTiles, tileMap.MapHeightTiles, tileMap.TileHeight, tileMap.TileWidth);

            nodeMap.generationPolygon = (SpritePolygon)collisionPolygon.Clone();

            for (int i = 0; i < nodeMap.XSize; i++)
            {
                for (int j = 0; j < nodeMap.YSize; j++)
                {
                    Vector2 position = new Vector2
                    {
                        X = nodeMap.Nodes[i, j].X,
                        Y = nodeMap.Nodes[i, j].Y
                    };
                    collisionPolygon.MoveTo(position);
                    Collision collision = tileMap.CheckCollisionWithTerrain(collisionPolygon);
                    if (collision == Collision.Solid || collision == Collision.Water)
                    {
                        nodeMap.Nodes[i, j].IsFree    = false;
                        nodeMap.Nodes[i, j].IsTerrain = true;
                    }
                }
            }

            return(nodeMap);
        }
Beispiel #2
0
        private void RegenerateRectangle(Point max, Point min, List <Polygon> polygons)
        {
            for (int i = min.X; i < max.X; i++)
            {
                for (int j = min.Y; j < max.Y; j++)
                {
                    Vector2 position = new Vector2
                    {
                        X = Nodes[i, j].X,
                        Y = Nodes[i, j].Y
                    };
                    generationPolygon.MoveTo(position);
                    var collision = false;
                    foreach (var polygon in polygons)
                    {
                        if (generationPolygon.Intersects(polygon))
                        {
                            collision = true;
                        }
                    }

                    if (collision)
                    {
                        Nodes[i, j].IsFree = false;
                        if (!Nodes[i, j].IsTerrain)
                        {
                            temporalTerrain.Add(Nodes[i, j]);
                        }
                    }
                }
            }
        }