public void FaceTowards(Point2D pos, Point2D nextWaypoint)
 {
     _direction = SwinGame.VectorFromAngle(SwinGame.CalculateAngleBetween(pos, nextWaypoint), 8);
 }
示例#2
0
        private SwinGameSDK.Vector GetDistractionVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, SwinGameSDK.Vector currentMoveVector)
        {
            SwinGameSDK.Vector  distractionVector = new SwinGameSDK.Vector();
            SwinGameSDK.Point2D max = new Point2D();
            SwinGameSDK.Point2D min = new Point2D();


            if (currentMoveVector.Angle <= 0)
            {
                min.Y = playerPos.Y + (currentMoveVector.Y * 7);
                max.Y = playerPos.Y;
            }
            else
            {
                max.Y = playerPos.Y - (currentMoveVector.Y * 7);
                min.Y = playerPos.Y;
            }

            if (currentMoveVector.Angle < 90 && currentMoveVector.Angle > -90)
            {
                max.X = playerPos.X + (currentMoveVector.X * 7);
                min.X = playerPos.X;
            }
            else
            {
                min.X = playerPos.X - (currentMoveVector.X * 7);
                max.X = playerPos.X;
            }

            float normalX = SwinGame.VectorNormal(currentMoveVector).X *(12);
            float normalY = SwinGame.VectorNormal(currentMoveVector).Y *(12);

            int iMax = (int)(Math.Ceiling(max.X / 60) + 1);
            int iMin = (int)(Math.Floor(min.X / 60) - 1);
            int jMax = (int)(Math.Ceiling(max.Y / 60) + 1);
            int jMin = (int)(Math.Floor(min.Y / 60) - 1);

            if (iMax > Game.x_width - 1)
            {
                iMax = Game.x_width - 1;
            }
            if (iMin < 0)
            {
                iMin = 0;
            }
            if (jMax > Game.y_height - 1)
            {
                jMax = Game.y_height - 1;
            }
            if (jMin < 0)
            {
                jMin = 0;
            }

            //loops through each square in the min/max of the rect fov.
            for (int i = iMin; i < iMax; i++)
            {
                for (int j = jMin; j < jMax; j++)
                {
                    if (tileSet[i, j].GetTileType() == TileType.WALL)
                    {
                        // I'm so sorry. It's so ugly.
                        if
                        (
                            SwinGame.LineIntersectsRect(SwinGame.LineFrom(playerPos.X + normalX, playerPos.Y + normalY, playerPos.X + (currentMoveVector.X * 7) + normalX, playerPos.Y + (currentMoveVector.Y * 7) + normalY), tileSet[i, j].GetHitBox())
                            ||
                            SwinGame.LineIntersectsRect(SwinGame.LineFrom(playerPos.X - normalX, playerPos.Y - normalY, playerPos.X + (currentMoveVector.X * 7) - normalX, playerPos.Y + (currentMoveVector.Y * 7) - normalY), tileSet[i, j].GetHitBox())
                        )
                        {
                            SwinGameSDK.Vector thisDistraction = new SwinGameSDK.Vector();

                            float distance = SwinGame.PointPointDistance(playerPos, tileSet[i, j].GetPos());
                            if (distance < 0)
                            {
                                distance = 0;
                            }

                            thisDistraction = SwinGame.VectorFromAngle(SwinGame.CalculateAngleBetween(playerPos, tileSet[i, j].GetPos()), distance);

                            distractionVector = SwinGame.AddVectors(distractionVector, SwinGame.InvertVector(thisDistraction));
                        }
                    }
                }
            }

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

            return(distractionVector);
        }