Beispiel #1
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);
        }