Esempio n. 1
0
 public void AddNeighbor(NavNode n)
 {
     if (!Neighbors.Contains(n))
     {
         Neighbors.Add(n);
         Costs.Add(EdgeCost(n));
     }
 }
Esempio n. 2
0
 private float EdgeCost(NavNode n)
 {
     float x, y;
     x = Math.Abs(n.Position.X - this.Position.X);
     y = this.Position.Y - n.Position.Y; // negative if the neighbor is above
     // We will probably adjust this:
     return 1;// x + y * 1.2f;
 }
Esempio n. 3
0
 // Index by which bot is searching (prevents conflicts)
 public void SetPrevious(NavAgent agent, NavNode node)
 {
     Previous[agent] = node;
 }
Esempio n. 4
0
 public override void Update(GameTime gameTime)
 {
     if (bot == null || mesh == null) this.Delete();
     else
     {
         int tick = 1;// gameTime.ElapsedGameTime.Milliseconds;
         idlecooldown -= tick;
         if (bot.Target == null)
         {
             // stall
             //    Console.WriteLine("stalling...");
         }
         else if (state == States.idle)
         {
             //  Console.WriteLine("idle...");
             if (idlecooldown >= 0) idlecooldown -= tick;
             else state = States.start;
         }
         else if (state == States.start)
         {
             //Console.WriteLine("starting...");
             Clear();
             path.Add(bot.Position);
             path.Add(bot.Target.Position);
             ncurrent = mesh.GetNearestNode(bot.Position);
             ngoal = mesh.GetNearestNode(bot.Target.Position);
             openSet.Add(ncurrent);
             costs[ncurrent] = 0;
             state = States.getnext; // initialize
         }
         else if (state == States.getnext)
         {
             //Console.WriteLine("get next");
             if (openSet.Count == 0) Reset();
             else
             {
                 // next node has the minimum cost in the open set
                 float minTotalCost = float.MaxValue;
                 foreach (NavNode n in openSet)
                 {
                     if (costs[n] < minTotalCost)
                     {
                         ncurrent = n;
                         minTotalCost = costs[n];
                     }
                 }
                 if (ncurrent == ngoal)
                 {
                     state = States.done;
                 }
                 else
                 {
                     closedSet.Add(ncurrent);
                     openSet.Remove(ncurrent);
                     // state = States.expand;
                 }
             }
             //}
             //else if (state == States.expand)
             //{
             //    //Console.WriteLine("Expand...");
             for (int j = 0; j < ncurrent.Neighbors.Count; j++)
             {
                 NavNode neighbor = ncurrent.Neighbors[j];
                 if (!closedSet.Contains(neighbor) && !openSet.Contains(neighbor))
                 {
                     // Add to open set and calculate costs
                     openSet.Add(neighbor);
                     costs[neighbor] = costs[ncurrent] + ncurrent.Costs[j];
                     neighbor.SetPrevious(this, ncurrent);
                 }
             }
             //state = States.getnext;
         }
         else if (state == States.done)
         {
             //Console.WriteLine("done");
             path.Clear();
             while (ncurrent.GetPrevious(this) != null)
             {
                 path.Insert(0, ncurrent.Position);
                 ncurrent = ncurrent.GetPrevious(this);
             }
             bot.SetDestinations(path);
             Reset();
         }
     }
 }
Esempio n. 5
0
        public static MapData LoadPillar(World w)
        {
            MapData data = new MapData();
            data.walls = new List<Wall>();
            data.walls.Add(new Wall(w, 960, 850, 1530, 130, 0));
            data.walls.Add(new Wall(w, 960, 969, 1406, 222, 0));
            data.walls.Add(new Wall(w, 980, -200, 1404, 128, 0));
            data.walls.Add(new Wall(w, 980, -300, 1404, 128, 0));

            data.spawnPoints = new Vector2[4];
            data.spawnPoints[0] = new Vector2(500, 640);
            data.spawnPoints[1] = new Vector2(820, 640);
            data.spawnPoints[2] = new Vector2(1120, 640);
            data.spawnPoints[3] = new Vector2(1420, 640);

            data.ammoPoints = new Vector3[1];
            data.ammoPoints[0] = new Vector3(960, 440, 1800);

            //TODO
            data.navmesh = new NavMesh();
            NavNode node01 = new NavNode(data.navmesh, 0, 0);
            NavNode node02 = new NavNode(data.navmesh, 1, 1);
            node01.AddNeighbor(node02);
            node02.AddNeighbor(node01);

            data.background = MainGame.tex_bg_pillar;
            data.music = MainGame.mus_pillar;

            return data;
        }
Esempio n. 6
0
        public static MapData LoadCircus(World w)
        {
            MapData data = new MapData();
            data.walls = new List<Wall>();
            data.walls.Add(new Wall(w, -12, 476, 24, 1000, 0));
            data.walls.Add(new Wall(w, 1932, 476, 24, 1000, 0));
            data.walls.Add(new Wall(w, 1038, 960, 2174, 282, 0));
            data.walls.Add(new Wall(w, 933, 729, 525, 164, 0));
            data.walls.Add(new Wall(w, 1390, 481, 139, 31, 0));
            data.walls.Add(new Wall(w, 980, -200, 1404, 128, 0));

            data.spawnPoints = new Vector2[4];
            data.spawnPoints[0] = new Vector2(250, 690);
            data.spawnPoints[1] = new Vector2(1422, 348);
            data.spawnPoints[2] = new Vector2(550, 690);
            data.spawnPoints[3] = new Vector2(1370, 690);

            data.ammoPoints = new Vector3[1];
            data.ammoPoints[0] = new Vector3(950, 405, 1800);

            data.navmesh = new NavMesh();
            NavNode node01 = new NavNode(data.navmesh, 0, 0);
            NavNode node02 = new NavNode(data.navmesh, 1, 1);
            node01.AddNeighbor(node02);
            node02.AddNeighbor(node01);

            data.background = MainGame.tex_bg_circus;
            data.music = MainGame.mus_circus;
            data.foreground = MainGame.tex_fg_circus;

            return data;
        }
Esempio n. 7
0
        public static MapData LoadCastle(World w)
        {
            MapData data = new MapData();
            data.walls = new List<Wall>();
            data.walls.Add(new Wall(w, 980, 880, 1404, 128, 0));
            data.walls.Add(new Wall(w, 319, 368, 152, 976, 0));
            data.walls.Add(new Wall(w, 1564, 359, 108, 915, 0));
            data.walls.Add(new Wall(w, 980, -200, 1404, 128, 0));
            data.walls.Add(new Wall(w, 450, 518, 209, 47, 0));
            data.walls.Add(new Wall(w, 1402, 518, 216, 55, 0));
            data.walls.Add(new Wall(w, 963, 256, 172, 44, 0));

            data.spawnPoints = new Vector2[4];
            data.spawnPoints[0] = new Vector2(468, 366);
            data.spawnPoints[1] = new Vector2(1383, 375);
            data.spawnPoints[2] = new Vector2(486, 699);
            data.spawnPoints[3] = new Vector2(1380, 704);

            data.ammoPoints = new Vector3[1];
            data.ammoPoints[0] = new Vector3(960, 170, 1800); // (x, y, respawn time)

            data.navmesh = new NavMesh();
            NavNode node01 = new NavNode(data.navmesh, 470, 700);
            NavNode node02 = new NavNode(data.navmesh, 630, 700);
            NavNode node03 = new NavNode(data.navmesh, 790, 700);
            NavNode node04 = new NavNode(data.navmesh, 950, 700);
            NavNode node05 = new NavNode(data.navmesh, 1110, 700);
            NavNode node06 = new NavNode(data.navmesh, 1270, 700);
            NavNode node07 = new NavNode(data.navmesh, 1430, 700);
            NavNode node08 = new NavNode(data.navmesh, 470, 370);
            NavNode node09 = new NavNode(data.navmesh, 630, 370);
            NavNode node10 = new NavNode(data.navmesh, 790, 370);
            NavNode node11 = new NavNode(data.navmesh, 950, 370);
            NavNode node12 = new NavNode(data.navmesh, 1110, 370);
            NavNode node13 = new NavNode(data.navmesh, 1270, 370);
            NavNode node14 = new NavNode(data.navmesh, 1430, 370);
            NavNode node15 = new NavNode(data.navmesh, 470, 170);
            NavNode node16 = new NavNode(data.navmesh, 630, 170);
            NavNode node17 = new NavNode(data.navmesh, 790, 170);
            NavNode node18 = new NavNode(data.navmesh, 950, 170);
            NavNode node19 = new NavNode(data.navmesh, 1110, 170);
            NavNode node20 = new NavNode(data.navmesh, 1270, 170);
            NavNode node21 = new NavNode(data.navmesh, 1430, 170);

            node01.AddNeighbors(node02);
            node02.AddNeighbors(node01, node03, node09, node10);
            node03.AddNeighbors(node02, node04, node10, node11);
            node04.AddNeighbors(node03, node05, node10, node11, node12);
            node05.AddNeighbors(node04, node06, node11, node12);
            node06.AddNeighbors(node05, node07, node12, node13);
            node07.AddNeighbors(node06);
            node08.AddNeighbors(node09, node15, node16);
            node09.AddNeighbors(node02, node08, node10, node15, node16, node17);
            node10.AddNeighbors(node02, node03, node04, node09, node11);
            node11.AddNeighbors(node03, node04, node05, node10, node12);
            node12.AddNeighbors(node04, node05, node06, node11, node13);
            node13.AddNeighbors(node06, node12, node14, node19, node20, node21);
            node14.AddNeighbors(node13, node20, node21);
            node15.AddNeighbors(node08, node09, node16);
            node16.AddNeighbors(node08, node09, node10, node15, node17);
            node17.AddNeighbors(node09, node16, node18);
            node18.AddNeighbors(node17, node19);
            node19.AddNeighbors(node13, node18, node20);
            node20.AddNeighbors(node12, node13, node14, node19, node21);
            node21.AddNeighbors(node13, node14, node20);

            data.background = MainGame.tex_bg_castle;
            data.music = MainGame.mus_castle;

            return data;
        }
Esempio n. 8
0
        public static MapData LoadOctopus(World w)
        {
            MapData data = new MapData();
            data.walls = new List<Wall>();
            data.walls.Add(new Wall(w, 1695, 453, 244, 1562, 0));
            data.walls.Add(new Wall(w, 326, 453, 200, 1458, 0));
            data.walls.Add(new Wall(w, 1008, 914, 1296, 240, 0));
            data.walls.Add(new Wall(w, 485, 537, 141, 75, 0));
            data.walls.Add(new Wall(w, 1443, 520, 342, 88, 0));
            data.walls.Add(new Wall(w, 980, -200, 1404, 128, 0));

            data.spawnPoints = new Vector2[4];
            data.spawnPoints[0] = new Vector2(682, 692);
            data.spawnPoints[1] = new Vector2(1216, 692);
            data.spawnPoints[2] = new Vector2(1496, 319);
            data.spawnPoints[3] = new Vector2(508, 389);

            data.ammoPoints = new Vector3[1];
            data.ammoPoints[0] = new Vector3(1000, 300, 1800);

            // TODO
            data.navmesh = new NavMesh();
            NavNode node01 = new NavNode(data.navmesh, 0, 0);
            NavNode node02 = new NavNode(data.navmesh, 1, 1);
            node01.AddNeighbor(node02);
            node02.AddNeighbor(node01);

            data.background = MainGame.tex_bg_octopus;
            data.music = MainGame.mus_octopus;

            return data;
        }
Esempio n. 9
0
        public static MapData LoadGraveyard(World w)
        {
            MapData data = new MapData();
            data.walls = new List<Wall>();
            data.walls.Add(new Wall(w, 965, 974, 1958, 223, 0));
            data.walls.Add(new Wall(w, -12, 476, 24, 1000, 0));
            data.walls.Add(new Wall(w, 1932, 476, 24, 1000, 0));
            data.walls.Add(new Wall(w, 494, 614, 278, 26, 0));
            data.walls.Add(new Wall(w, 1569, 812, 241, 281, -MathHelper.Pi / 6));
            data.walls.Add(new Wall(w, 1497, 684, 229, 86, -MathHelper.Pi / 180 * 11.8f));
            data.walls.Add(new Wall(w, 839, 368, 114, 21, 0));
            data.walls.Add(new Wall(w, 980, -200, 1404, 128, 0));

            data.spawnPoints = new Vector2[4];
            data.spawnPoints[0] = new Vector2(501, 741);
            data.spawnPoints[1] = new Vector2(1468, 554);
            data.spawnPoints[2] = new Vector2(501, 455);
            data.spawnPoints[3] = new Vector2(973, 735);

            data.ammoPoints = new Vector3[1];
            data.ammoPoints[0] = new Vector3(837, 292, 1800);

            data.navmesh = new NavMesh();
            NavNode node01 = new NavNode(data.navmesh, 0, 0);
            NavNode node02 = new NavNode(data.navmesh, 1, 1);
            node01.AddNeighbor(node02);
            node02.AddNeighbor(node01);

            data.background = MainGame.tex_bg_graveyard;
            data.music = MainGame.mus_graveyard;

            return data;
        }
Esempio n. 10
0
        public static MapData LoadClocktower(World w)
        {
            /////
            // These are all wrong
            /////
            MapData data = new MapData();
            data.walls = new List<Wall>();
            data.walls.Add(new Wall(w, -12, 476, 24, 1000, 0));
            data.walls.Add(new Wall(w, 1932, 476, 24, 1000, 0));
            data.walls.Add(new Wall(w, 751, 443, 312, 46, 0));
            data.walls.Add(new RoundWall(w, 758, 999, 114));
            data.walls.Add(new RoundWall(w, -30, 1230, 633));
            data.walls.Add(new RoundWall(w, 573, 1044, 88));
            data.walls.Add(new RoundWall(w, 991, 914, 152));
            data.walls.Add(new RoundWall(w, 1487, 1047, 227));
            data.walls.Add(new RoundWall(w, 1873, 787, 257));
            data.walls.Add(new RoundWall(w, 1196, 1051, 93));
            data.walls.Add(new Wall(w, 980, -200, 1404, 128, 0));

            data.spawnPoints = new Vector2[4];
            data.spawnPoints[0] = new Vector2(586, 654);
            data.spawnPoints[1] = new Vector2(1516, 589);
            data.spawnPoints[2] = new Vector2(981, 580);
            data.spawnPoints[3] = new Vector2(758, 327);

            data.ammoPoints = new Vector3[1];
            data.ammoPoints[0] = new Vector3(1285, 427, 1800);

            data.navmesh = new NavMesh();
            NavNode node01 = new NavNode(data.navmesh, 0, 0);
            NavNode node02 = new NavNode(data.navmesh, 1, 1);
            node01.AddNeighbor(node02);
            node02.AddNeighbor(node01);

            data.background = MainGame.tex_bg_clocktower;
            data.music = MainGame.mus_clocktower;

            return data;
        }
Esempio n. 11
0
 public void AddNode(NavNode pnode)
 {
     nodes.Add(pnode);
 }