Пример #1
0
        private void InitializeNodeNetworks()
        {
            nodeNetwork = TileNodeNetworkCreator.CreateFromTypes(
                Map, DirectionalType.Four, new string[] { "Ground", "Mud" });
            // todo - add ground:
            //nodeNetwork = new TileNodeNetwork(Map.X, Map.Y - Map.Height, Map.WidthPerTile.Value,
            //    Map.NumberTilesWide.Value, Map.NumberTilesTall.Value, DirectionalType.Eight);
            //nodeNetwork.LinkColor = Microsoft.Xna.Framework.Color.Gray;
            //nodeNetwork.NodeColor = Microsoft.Xna.Framework.Color.White;

            var names = Map.TileProperties
                        .Where(item => item.Value.Any(subItem =>
                                                      subItem.Name == "Type" &&
                                                      ((subItem.Value as string) == "Wall" || (subItem.Value as string) == "Pit")))
                        .Select(item => item.Key)
                        .ToArray();

            var mapHafSize = Map.WidthPerTile.Value / 2.0f;

            foreach (var layer in Map.MapLayers)
            {
                foreach (var name in names)
                {
                    if (layer.NamedTileOrderedIndexes.ContainsKey(name))
                    {
                        var indexes = layer.NamedTileOrderedIndexes[name];

                        foreach (var index in indexes)
                        {
                            var bottomLeftPosition = layer.Vertices[index * 4].Position;

                            var node = nodeNetwork.TiledNodeAtWorld(
                                bottomLeftPosition.X + mapHafSize,
                                bottomLeftPosition.Y + mapHafSize);
                            if (node != null)
                            {
                                nodeNetwork.Remove(node);
                            }
                        }
                    }
                }
            }

            if (DebuggingVariables.ShowNodeNetwork)
            {
                nodeNetwork.Visible = true;
                nodeNetwork.UpdateShapes();
            }
            else
            {
                nodeNetwork.Visible = false;
            }
        }
        public static void RemoveNodesWithCollisions(ref TileNodeNetwork network,
                                                     PositionedObjectList <TileCollisionRectangle> rectangleCollision,
                                                     PositionedObjectList <TileCollisionCircle> circleCollision)
        {
            foreach (var tileCollisionRectangle in rectangleCollision)
            {
                tileCollisionRectangle.ForceUpdateDependenciesDeep();
            }

            foreach (var tileCollisionCircle in circleCollision)
            {
                tileCollisionCircle.ForceUpdateDependenciesDeep();
            }

            var nodeCircle = new Circle {
                Radius = 20f
            };

            for (var i = network.Nodes.Count - 1; i >= 0; i--)
            {
                var node        = network.Nodes[i];
                var nodeRemoved = false;
                nodeCircle.Position = node.Position;

                if (rectangleCollision.Any(rect => rect.CollideAgainst(nodeCircle)))
                {
                    network.Remove(node);
                    nodeRemoved = true;
                }
                if (!nodeRemoved)
                {
                    if (circleCollision.Any(circle => circle.Altitude == 0 && circle.CollideAgainst(nodeCircle)))
                    {
                        network.Remove(node);
                        nodeRemoved = true;
                    }
                }
            }
        }