Beispiel #1
0
        private static bool CanSee(Tile[,] tiles, SwinGameSDK.Point2D toSee, int positionX, int positionY)
        {
            // takes the absoloute value of the angle between two vectors. The one between the player and what they're trying to see and the vector in the direction the player is facing.
            // It then checks if this value is less than half the player's fov. This will check if the object is within the player's cone of vision.

            //bool result = true;
            int minX = 0;
            int minY = 0;
            int maxX = 0;
            int maxY = 0;

            if (toSee.X < positionX)
            {
                maxX = positionX;
                minX = (int)toSee.X;
            }
            else
            {
                minX = positionX;
                maxX = (int)toSee.X;
            }

            if (toSee.Y < positionY)
            {
                maxY = positionY;
                minY = (int)toSee.Y;
            }
            else
            {
                minY = positionY;
                maxY = (int)toSee.Y;
            }

            for (int i = minX - 1; i < maxX + 1; i++)
            {
                for (int j = minY - 1; j < maxY + 1; j++)
                {
                    if (i > 0 && j > 0 && i < Game.x_width && j < 18)
                    {
                        if (tiles[i, j].GetTileType() == TileType.WALL && !SwinGame.PointInRect(toSee.X * 60, toSee.Y * 60, tiles[i, j].GetHitBox()) && SwinGame.LineIntersectsRect(SwinGame.LineFrom(positionX * 60, positionY * 60, toSee.X * 60, toSee.Y * 60), tiles[i, j].GetHitBox()))
                        {
                            return(false);
                        }
                    }
                }
                //return result;
            }
            return(true);
        }
Beispiel #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);
        }
Beispiel #3
0
 public override bool IsAt(SwinGameSDK.Point2D pt)
 {
     return(SwinGameSDK.SwinGame.PointInRect(pt, X, Y, (float)_width, (float)_height));
 }
Beispiel #4
0
 public override bool IsAt(SwinGameSDK.Point2D pt)
 {
     return(SwinGameSDK.SwinGame.PointInCircle(pt, X, Y, (float)_radius));
 }