コード例 #1
0
ファイル: Player.cs プロジェクト: MJahanzaibAlam/ShadowMaze
 // Checks if a point is in a traversable node.
 private bool LegalPosition(Vector2 v2NewPos, GridLayer grid)
 {
     if (grid.GetNode(ToPoint(v2NewPos)).Traversable&& grid.GetNode(ToPoint(v2NewPos + new Vector2(RectEntityWidth, 0))).Traversable &&
         grid.GetNode(ToPoint(v2NewPos + new Vector2(0, RectEntityHeight))).Traversable&& grid.GetNode(ToPoint(v2NewPos + new Vector2(RectEntityWidth, RectEntityHeight))).Traversable)
     {
         return(true);
     }
     return(false);
 }
コード例 #2
0
        // Finds the position where the line has intersected a non-traversable object (where the line has ended).
        private Vector2 IntersectionPoint(GridLayer grid, Point PointStart, Point PointEnd)
        {
            // Creates a line of points using the Bresenham's line algorithm.
            List <Point> Line = BresenhamLine(PointStart.X, PointStart.Y, PointEnd.X, PointEnd.Y);

            listPoints = new List <Point>();

            Vector2 EndPoint = new Vector2(PointEnd.X, PointEnd.Y); // Contains the position where the line has ended.

            for (int intPointIndex = 0; intPointIndex < Line.Count(); intPointIndex++)
            {
                Node nodeToCheck = grid.GetNode(Line[intPointIndex]); // Retrieve the node which the current point is within.

                if (!nodeToCheck.Traversable)
                { // If the node within which the point is located is not traversable, the intersection point has been found.
                    EndPoint = new Vector2(Line[intPointIndex].X, Line[intPointIndex].Y);

                    Line.RemoveRange(intPointIndex, Line.Count - intPointIndex); // Remove any excess points past the end point.
                    break;
                    // Then exit the loop as a point of intersection has been found (where the line must end).
                }
            }

            // Adds one point for every 40 points in the original list.
            for (int intListIndex = 0; intListIndex < Line.Count(); intListIndex += 40)
            {
                listPoints.Add(Line[intListIndex]);
            }

            return(EndPoint);
        }
コード例 #3
0
 // Raises the brightness of nodes which are visible and detects if a player is within field of vision.
 public bool InLineOfSight(GridLayer grid, Player player)
 {
     boolFound = false;
     foreach (LightRay line in LRRays)
     {
         foreach (Point point in line.Points)
         {
             // Loop through each point in each line, make the node which the point is within visible.
             grid.GetNode(point).Colour = Color.White;
             // Then check if the node at the point intersects the closest player's rectangle (is within line of sight).
             if (grid.GetNode(point).Tile.Intersects(player.RectEntity))
             {
                 boolFound = true;
             }
         }
     }
     return(boolFound);
 }
コード例 #4
0
ファイル: Player.cs プロジェクト: MJahanzaibAlam/ShadowMaze
 // Checks if a shadow copy is within the range of a light beam and removes it if it is.
 public void BeamKillCopy(GridLayer grid, LightRay lightBeam, AddShadowCopy[] addShadowCopies, ShadowCopy[] shadowCopies)
 { // Check each point in the beam, if the point is in the same node as a copy, remove the shadow copy.
     foreach (Point point in lightBeam.Points)
     {
         for (int intCopyIndex = 0; intCopyIndex < shadowCopies.GetLength(0); intCopyIndex++)
         {
             if (shadowCopies[intCopyIndex] != null && shadowCopies[intCopyIndex].RectEntity.Intersects(grid.GetNode(point).Tile))
             {                   // Only check and remove the copy if it actually exists.
                 shadowCopies[intCopyIndex] = null;
                 strItem = null; // Removes the player's item after use.
             }
         }
         for (int intCopyIndex = 0; intCopyIndex < addShadowCopies.GetLength(0); intCopyIndex++)
         {
             if (addShadowCopies[intCopyIndex] != null && addShadowCopies[intCopyIndex].RectEntity.Intersects(grid.GetNode(point).Tile))
             {                   // Only check and remove the copy if it actually exists.
                 addShadowCopies[intCopyIndex] = null;
                 strItem = null; // Removes the player's item after use.
             }
         }
         grid.GetNode(point).Colour = Color.White; // Makes any nodes in the beam brighter.
     }
 }