Ejemplo n.º 1
0
        public void Search_BackwardPath_PathFound()
        {
            /*
             ##__
             * 10#_
             * 2#6_
             * 345_
             */
            var target = new WeightedGridGraph(10, 10);

            target.Walls.Add(new Point(1, 2));
            target.Walls.Add(new Point(2, 1));
            target.Walls.Add(new Point(1, 0));
            target.Walls.Add(new Point(0, 0));
            var result = WeightedPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(7, result.Count());
            Assert.AreEqual(new Point(1, 1), result[0]);
            Assert.AreEqual(new Point(0, 1), result[1]);
            Assert.AreEqual(new Point(0, 2), result[2]);
            Assert.AreEqual(new Point(0, 3), result[3]);
            Assert.AreEqual(new Point(1, 3), result[4]);
            Assert.AreEqual(new Point(2, 3), result[5]);
            Assert.AreEqual(new Point(2, 2), result[6]);
        }
 public EnemyController(TiledTileLayer collisionLayer) : base()
 {
     _grid = new WeightedGridGraph(collisionLayer);
     this.collisionState = new TiledMapMover.CollisionState();
     _dir        = new Vector2();
     maxVelocity = 1f;
 }
Ejemplo n.º 3
0
 public Punk(String inEntityType, int inTotalLife, Nez.Tiled.TiledMap inMap, bool enemyHasGun, int ntargetPositionRange) : base(inEntityType, inTotalLife, inMap, enemyHasGun, ntargetPositionRange)
 {
     EntityType          = inEntityType;
     TileMap             = inMap;
     TotalLife           = inTotalLife;
     CurrentLife         = TotalLife;
     CollisionLayer      = TileMap.getLayer <TiledTileLayer>("collisionLayer");
     WeightedGraph       = new WeightedGridGraph(CollisionLayer);
     Start               = new Point(1, 1);
     End                 = new Point(10, 10);
     WeightedSearchPath  = WeightedGraph.search(Start, End);
     EnemyCanShootGun    = enemyHasGun;
     TargetPositionRange = ntargetPositionRange;
 }
Ejemplo n.º 4
0
        public Pathfinder(TiledMap tilemap)
        {
            _tilemap = tilemap;
            var layer = tilemap.getLayer <TiledTileLayer>("main");

            _start = new Point(1, 1);
            _end   = new Point(10, 10);

            _gridGraph         = new UnweightedGridGraph(layer);
            _breadthSearchPath = _gridGraph.search(_start, _end);

            _astarGraph      = new WeightedGridGraph(layer);
            _astarSearchPath = _astarGraph.search(_start, _end);

            Debug.drawTextFromBottom = true;
        }
Ejemplo n.º 5
0
        public void Search_ForwardPath_PathFound()
        {
            /*
             * ____
             * _01_
             * _#2_
             */
            var target = new WeightedGridGraph(10, 10);

            target.Walls.Add(new Point(1, 2));
            var result = WeightedPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(3, result.Count());
            Assert.AreEqual(new Point(1, 1), result[0]);
            Assert.AreEqual(new Point(2, 1), result[1]);
            Assert.AreEqual(new Point(2, 2), result[2]);
        }
Ejemplo n.º 6
0
        public void Search_NoWay_PathNull()
        {
            /*
             * _#__
             #0#_
             * _#x_
             * ____
             */
            var target = new WeightedGridGraph(10, 10);

            target.Walls.Add(new Point(1, 2));
            target.Walls.Add(new Point(2, 1));
            target.Walls.Add(new Point(1, 0));
            target.Walls.Add(new Point(0, 1));
            var result = WeightedPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(null, result);
        }
Ejemplo n.º 7
0
        public void UpdateScene()
        {
            ShakeCamera();
            UpdateUIText();
            _healthBar.setValue(_player.Health - 1);
            if (_player.Dead)
            {
                _healthBar.setStyle(ProgressBarStyle.create(Color.Black, Color.Black));
                var transition = new SquaresTransition(PlayerDeath);
                Core.startSceneTransition(transition);
                Core.scene = PlayerDeath();
            }
            Physics.gravity.Y = 250f;
            CheckGrounded();
            //Console.WriteLine(playerEntity.transform.position.X + ", " + playerEntity.transform.position.Y);
            CheckDoors();

            var graph = new WeightedGridGraph(_tileCollLayer);
        }
Ejemplo n.º 8
0
        public void Search_AllowDiagonal_PathFound()
        {
            /*
             ##__
             * _0#_
             * _#1_
             * ____
             */
            var target = new WeightedGridGraph(10, 10, true);

            target.Walls.Add(new Point(1, 2));
            target.Walls.Add(new Point(2, 1));
            target.Walls.Add(new Point(1, 0));
            target.Walls.Add(new Point(0, 0));
            var result = WeightedPathfinder.Search(target, new Point(1, 1), new Point(2, 2));

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(new Point(1, 1), result[0]);
            Assert.AreEqual(new Point(2, 2), result[1]);
        }
        protected bool InitPath()
        {
            // If the path isn't currently set, then set it
            // The path will be set & unset many times over the course of a single chase
            if (Path == null)
            {
                // If the collisions layer hasn't been set yet, set it
                // We need that to find paths around
                if (Layer == null)
                {
                    // First, get the main map
                    Entity Map = Core.scene.findEntity("map");

                    // If the map doesn't exist, there's nothing to find paths around
                    // Just quit, this should never happen
                    if (Map == null)
                    {
                        return(false);
                    }

                    // Get the map data
                    // We use Tiled in this game
                    TiledMapComponent MapData = Map.getComponent <TiledMapComponent>();

                    // If there is no map data, then there's no use
                    // Just quit, this should never happen
                    if (MapData == null)
                    {
                        return(false);
                    }

                    // Set the collision layer
                    Layer = MapData.collisionLayer;

                    // If the collision layer is null, there's no use
                    // Just quit, this should never happen
                    if (Layer == null)
                    {
                        return(false);
                    }
                }

                // If the graph hasn't been set, set it
                // The graph is the object that sets the path
                if (graph == null)
                {
                    graph = new WeightedGridGraph(Layer);

                    // If graph didn't properly set, there's no use
                    // Just quit, this should never happen
                    if (graph == null)
                    {
                        return(false);
                    }
                }

                // Set the path
                SetPath();

                // If the path is somehow still null, it's no use
                // Just quit, this should never happen
                if (Path == null)
                {
                    return(false);
                }

                // If the path is more-or-less empty, make it null, then quit
                // (The first node is usually useless)
                // This should never happen
                if (Path.Count < 1)
                {
                    ChosenPatrolStalkPoint = null;

                    Player = null;

                    Path = null;

                    return(false);
                }

                // Set the place on the map we want to go to
                // We make it a Vector2 as opposed to a Point. It's easier for us to use it that way
                // We also multiply it by the map's tilesize, as the Point it gives us is coordinates
                NextPoint = new Vector2((Path[1].X * 8) + 4, (Path[1].Y * 8) - 4);
            }

            return(true);
        }