コード例 #1
0
ファイル: Node.cs プロジェクト: wiilinkpds/Wotrn
        public Node(Node copie, NodePos direction, MapData map, Vector2 size)
        {
            CanGo = true;
            Start = copie.Start;
            Arrival = copie.Arrival;

            switch (direction)
            {
                case NodePos.U:
                    Position = new Vector2(copie.Position.X, copie.Position.Y - 32);
                    break;
                case NodePos.D:
                    Position = new Vector2(copie.Position.X, copie.Position.Y + 32);
                    break;
                case NodePos.R:
                    Position = new Vector2(copie.Position.X + 32, copie.Position.Y);
                    break;
                case NodePos.L:
                    Position = new Vector2(copie.Position.X - 32, copie.Position.Y);
                    break;
            }

            Update(map);
            if (Id < 0 || Id > map.MapWidth * map.MapHeight || !Can(direction, map, size))
                CanGo = false;
        }
コード例 #2
0
ファイル: Ia.cs プロジェクト: wiilinkpds/Wotrn
        public Ia(GameTime gameTime, Vector2 player, Entity monster, MapData map)
        {
            this.monster = monster;
            OpenedList = new List<Node>();
            ClosedList = new List<Node>();

            mapData = map;
            start = new Node(monster.Position, monster.Position, player, mapData) { Parent = null };
            arrival = new Node(player, monster.Position, player, mapData);

            OpenedList.Add(start);
            PathFinding(gameTime);
        }
コード例 #3
0
ファイル: Pathfinding.cs プロジェクト: wiilinkpds/Wotrn
        public Pathfinding(GameTime gameTime, Vector2 player, Entity monster, MapData map)
        {
            this.monster = monster;

            openedList = new List<Node>();
            closedList = new List<Node>();
            mapData = map;

            if (player.X < 0 || player.X > mapData.MapWidth * 32 || player.Y < 0 || player.Y > mapData.MapHeight * 32 || mapData.Accessibility[ConversionManager.VectToId(map, player)] == 1)
                return;

            start = new Node(monster.Position, monster.Position, player, mapData) { Parent = null };
            arrival = new Node(player, monster.Position, player, mapData);

            openedList.Add(start);
            PathFind(gameTime, map);
        }
コード例 #4
0
ファイル: Node.cs プロジェクト: wiilinkpds/Wotrn
        public Node(Node copie, NodePos direction, MapData map, Vector2 Size)
        {
            Start = copie.Start;
            Arrival = copie.Arrival;

            switch (direction)
            {
                case NodePos.U:
                    Position = new Vector2(copie.Position.X, copie.Position.Y - 32);
                    break;
                case NodePos.D:
                    Position = new Vector2(copie.Position.X, copie.Position.Y + 32);
                    break;
                case NodePos.R:
                    Position = new Vector2(copie.Position.X + 32, copie.Position.Y);
                    break;
                case NodePos.L:
                    Position = new Vector2(copie.Position.X - 32, copie.Position.Y);
                    break;
            }
            Update(map);
            if (Id < 0 || Id + (int)(Size.Y / 32) * map.MapWidth + (int)(Size.X / 32) >= map.Accessibility.Length || map.Accessibility[Id] == 1)
                Id = -1;
        }
コード例 #5
0
ファイル: Pathfinding.cs プロジェクト: wiilinkpds/Wotrn
        private void FindNode(Node curr)
        {
            Node u = new Node(curr, NodePos.U, mapData, monster.TextureSize);
            Node d = new Node(curr, NodePos.D, mapData, monster.TextureSize);
            Node r = new Node(curr, NodePos.R, mapData, monster.TextureSize);
            Node l = new Node(curr, NodePos.L, mapData, monster.TextureSize);

            if (l.CanGo && !Contains(l, closedList))
            {
                if (!Contains(l, openedList))
                {
                    l.Parent = curr;
                    l.DistanceParcourue = curr.DistanceParcourue + 32;
                    openedList.Add(l);
                }
            }
            if (r.CanGo && !Contains(r, closedList))
            {
                if (!Contains(r, openedList))
                {
                    r.Parent = curr;
                    r.DistanceParcourue = curr.DistanceParcourue + 32;
                    openedList.Add(r);
                }
            }
            if (u.CanGo && !Contains(u, closedList))
            {
                if (!Contains(u, openedList))
                {
                    u.Parent = curr;
                    u.DistanceParcourue = curr.DistanceParcourue + 32;
                    openedList.Add(u);
                }
            }
            if (d.CanGo && !Contains(d, closedList))
            {
                if (!Contains(d, openedList))
                {
                    d.Parent = curr;
                    d.DistanceParcourue = curr.DistanceParcourue + 32;
                    openedList.Add(d);
                }
            }
        }
コード例 #6
0
ファイル: Pathfinding.cs プロジェクト: wiilinkpds/Wotrn
 private bool Contains(Node node, List<Node> nodes)
 {
     foreach (Node n in nodes)
         if (n.Id == node.Id)
             return true;
     return false;
 }
コード例 #7
0
ファイル: Pathfinding.cs プロジェクト: wiilinkpds/Wotrn
 public void PathFind(GameTime gameTime, MapData map)
 {
     while (!Contains(arrival, closedList) && openedList.Count != 0)
     {
         current = new Node();
         current = FindMinPoids(openedList);
         openedList.Remove(current);
         if (current.Position.X >= 0 && current.Position.X + monster.TextureSize.X <= mapData.MapWidth*32 && current.Position.Y >= 0 && current.Position.Y + monster.TextureSize.Y <= 32 * mapData.MapHeight)
         {
             closedList.Add(current);
             FindNode(current);
         }
     }
     if (Contains(arrival, closedList))
     {
         list = new List<int>();
         test = new Node();
         test = closedList.Find(node => node.Id == arrival.Id);
         list.Add(test.Id);
         while (test.Parent != null)
         {
             test = test.Parent;
             list.Add(test.Id);
         }
         if (monster is Monster)
             Movement(gameTime, monster, map);
     }
 }
コード例 #8
0
ファイル: Ia.cs プロジェクト: wiilinkpds/Wotrn
        private void FindNode(Node curr)
        {
            // A changer en liste pour des foreachs

            Node u = new Node(curr, NodePos.U, mapData, monster.TextureSize);
            Node d = new Node(curr, NodePos.D, mapData, monster.TextureSize);
            Node r = new Node(curr, NodePos.R, mapData, monster.TextureSize);
            Node l = new Node(curr, NodePos.L, mapData, monster.TextureSize);

            if (l.Id >= 0 && !Contains(l, ClosedList))
            {
                if (mapData.Accessibility[l.Id + mapData.MapWidth] != 1 //Condition de carrer
                    && (mapData.SideAccess[l.Id] & 8) != 8 && (mapData.SideAccess[l.Id + mapData.MapWidth] & 1) != 1) //Condition pour les barres de collision
                    if (!Contains(l, OpenedList))
                    {
                        l.Parent = curr;
                        l.DistanceParcourue = curr.DistanceParcourue + 32;
                        OpenedList.Add(l);
                    }
            }
            if (r.Id >= 0 && !Contains(r, ClosedList))
            {
                if (mapData.Accessibility[r.Id + mapData.MapWidth] != 1 && mapData.Accessibility[r.Id + 1] != 1 //Carrer
                    && (mapData.SideAccess[r.Id] & 4) != 4 && (mapData.SideAccess[r.Id + mapData.MapWidth] & 1) != 1 && (mapData.SideAccess[r.Id + 1] & 4) != 4) //Barre
                    if (!Contains(r, OpenedList))
                    {
                        r.Parent = curr;
                        r.DistanceParcourue = curr.DistanceParcourue + 32;
                        OpenedList.Add(r);
                    }
            }
            if (u.Id >= 0 && !Contains(u, ClosedList))
            {
                if (mapData.Accessibility[u.Id + 1] != 1 //Carrer
                    && (mapData.SideAccess[u.Id] & 2) != 2 && (mapData.SideAccess[u.Id + 1] & 4) != 4)
                    if (!Contains(u, OpenedList))
                    {
                        u.Parent = curr;
                        u.DistanceParcourue = curr.DistanceParcourue + 32;
                        OpenedList.Add(u);
                    }
            }
            if (d.Id >= 0 && !Contains(d, ClosedList))
            {
                if (mapData.Accessibility[d.Id + mapData.MapWidth] != 1 && mapData.Accessibility[d.Id + 1] != 1
                    && (mapData.SideAccess[d.Id] & 1) != 1 && (mapData.SideAccess[d.Id + mapData.MapWidth] & 1) != 1 && (mapData.SideAccess[d.Id + 1] & 4) != 4)
                    if (!Contains(d, OpenedList))
                    {
                        d.Parent = curr;
                        d.DistanceParcourue = curr.DistanceParcourue + 32;
                        OpenedList.Add(d);
                    }
            }
        }
コード例 #9
0
ファイル: Ia.cs プロジェクト: wiilinkpds/Wotrn
 public void PathFinding(GameTime gameTime)
 {
     while (!Contains(arrival, ClosedList) && OpenedList.Count != 0)
     {
         current = new Node();
         current = FindMinPoids(OpenedList);
         OpenedList.Remove(current);
         if (current.Position.X >= 0 && current.Position.X + monster.TextureSize.X <= mapData.MapWidth * 32 && current.Position.Y >= 0 && current.Position.Y + monster.TextureSize.Y <= 32 * mapData.MapHeight)
         {
             ClosedList.Add(current);
             FindNode(current);
         }
     }
     if (Contains(arrival, ClosedList))
     {
         list = new List<Vector2>();
         test = new Node();
         test = ClosedList.Find(node => node.Id == arrival.Id);
         list.Add(test.Position);
         while (test.Parent != null)
         {
             test = test.Parent;
             list.Add(test.Position);
         }
         Mouvement(gameTime);
     }
 }