Ejemplo n.º 1
0
        /// <summary>
        /// In this override notice the setting up of the pathfinder.
        /// This isn't done during construction of our object because our
        /// local _gameWorld from our baseclass is null; it wont be set until this
        /// entity is registered with the game world.
        ///
        /// Once registered, this function will be called when GameWorld calls Start()
        /// Allowing us to finalise any object setup we need that relies on _gameWorld
        /// </summary>
        public override void Start()
        {
            _pathFinder = new AStarPathfinder(_gameWorld);

            Thread doggyUpdateThread = new Thread(Update);

            doggyUpdateThread.Start();
        }
Ejemplo n.º 2
0
        private SwinGameSDK.Vector GetPathVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, Point2D destination, bool selected)
        {
            SwinGameSDK.Vector pathVector = new SwinGameSDK.Vector();

            if (_inControl)
            {
                ///////////////////////ALLOWS CONTROL OF PLAYERS////////////////////////////////
                if (SwinGame.KeyDown(KeyCode.vk_RIGHT) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(0, 8));
                }
                if (SwinGame.KeyDown(KeyCode.vk_DOWN) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(90, 8));
                }
                if (SwinGame.KeyDown(KeyCode.vk_LEFT) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(180, 8));
                }
                if (SwinGame.KeyDown(KeyCode.vk_UP) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(-90, 8));
                }
                ///////////////////////ALLOWS CONTROL OF PLAYERS////////////////////////////////
            }
            else
            {
                if (_toUpdate)
                {
                    _forces    = AStarPathfinder.CalculateForces(playerPos, tileSet, destination);
                    _toUpdate  = false;
                    pathVector = CurrentForce(playerPos, tileSet);
                }
                else
                {
                    pathVector = CurrentForce(playerPos, tileSet);
                }
            }

            if (pathVector.Magnitude > 3)
            {
                pathVector = SwinGame.LimitVector(pathVector, 3);
            }

            return(pathVector);
        }