// Constructor
        public PatrolGuard(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize,
            Point sheetSize, Map gameMap, SpriteManager spriteManager , List<Vector2>PatrolOrder)
            : base(textureImage, position, speed, spriteSize, sheetSize, gameMap)
        {
            this.spriteManager = spriteManager;

            patrolReceive = PatrolOrder;
        }
Пример #2
0
 public Sprite(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize, Point sheetSize, Map gameMap,
     int collisionOffset, Point currentFrame, int millisecondsPerFrame)
 {
     this.textureImage = textureImage;
     this.Position = position;
     this.spriteSize = spriteSize;
     this.sheetSize = sheetSize;
     this.collisionOffset = collisionOffset;
     this.currentFrame = currentFrame;
     this.Speed = speed;
     this.millisecondsPerFrame = millisecondsPerFrame;
     this.GameMap = gameMap;
 }
        // Constructor
        public GuardSprite(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize,
            Point sheetSize, Map gameMap, SpriteManager spriteManager, List<String> PatrolPathList, 
            bool initialStateIsPatrol)
            : base(textureImage, position, speed, spriteSize, sheetSize, gameMap)
        {
            this.spriteManager = spriteManager;
            this.PatrolPathList = PatrolPathList;
            this.initialStateIsPatrol = initialStateIsPatrol;
            this.startPosition = position;

            if (PatrolPathList.Count > 0)
            {
                CurrentPatrolDestinationPoint = ParsePatrolInstruction(PatrolPathList[CurrentPatrolPathListIndex++], false);
            }

            if (initialStateIsPatrol)
                CurrentState = GuardState.Patrol;
            else
                CurrentState = GuardState.Roam;

            RenewRoamDestination();
        }
Пример #4
0
 public Sprite(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize, Point sheetSize, Map gameMap,
     int collisionOffset, Point currentFrame)
     : this(textureImage, position, speed, spriteSize, sheetSize, gameMap, collisionOffset,
       currentFrame, defaultMillisecondsPerFrame)
 {
 }
Пример #5
0
 // public abstract Vector2 direction { get; }
 public Sprite(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize, Point sheetSize, Map gameMap)
     : this(textureImage, position, speed, spriteSize, sheetSize, gameMap,
       10, new Point(0, 0), defaultMillisecondsPerFrame)
 {
 }
Пример #6
0
 public GuardSprite(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize, 
     Point sheetSize, Map gameMap, SpriteManager spriteManager)
     : base(textureImage, position, speed, spriteSize, sheetSize, gameMap)
 {
     this.spriteManager = spriteManager;
 }
 public SpriteManager(Game game, Map gameMap )
     : base(game)
 {
     this.gameMap = gameMap;
 }
 public PlayerSprite(Texture2D textureImage, Vector2 position, Vector2 speed, Point spriteSize, 
     Point sheetSize, Map gameMap)
     : base(textureImage, position, speed, spriteSize, sheetSize, gameMap)
 {
 }
Пример #9
0
        /// <summary>
        /// Score = DistanceFromStartPoint (CostFromStart) + DistanceToEndPoint (Heuristic)
        /// </summary>
        public static List<Point> FindPath(Map GameMap, Point StartPoint, Point EndPoint)
        {
            if (StartPoint == EndPoint)
            {
                return new List<Point>();
            }

            List<Point> ExploredPoints = new List<Point>();

            List<Node> ClosedList = new List<Node>();
            List<Node> OpenList = new List<Node>();

            List<Node> ConclusionNodeList = new List<Node>();

            // Initialize StartPoint to be first Node
            int DistanceFromStartPoint = GameMap.DistanceOfPoints(StartPoint, StartPoint);
            int DistanceToEndPoint = GameMap.DistanceOfPoints(StartPoint, EndPoint);
            Node CurrentNode = new Node(StartPoint, DistanceFromStartPoint, DistanceToEndPoint);
            ExploredPoints.Add(CurrentNode.GridPosition);

            int RunTime = 0;

            do
            {
                List<Point> AdjacentGridPositions = GetAdjacentGridPositions(CurrentNode);
                List<Node> AdjacentNodes = ConvertPointListToNodeList(AdjacentGridPositions, GameMap, StartPoint, EndPoint);

                // Add Unexplored and Walkable Nodes into OpenList
                // Also set non-Walkable Nodes to Explored to prevent re-exploring
                foreach (Node AdjacentNode in AdjacentNodes)
                {
                    if (!ExploredPoints.Contains(AdjacentNode.GridPosition))
                    {
                        ExploredPoints.Add(AdjacentNode.GridPosition);

                        AdjacentNode.SetParent(CurrentNode);

                        if (GameMap.CheckTileWalkable(AdjacentNode.GridPosition))
                        {
                            OpenList.Add(AdjacentNode);
                        }
                    }
                }

                // Sort by Node Score and Heuristic (Lowest first)
                OpenList = OpenList.OrderBy(Obj => Obj.Score).ThenBy(Obj => Obj.Heuristic).ToList();
                OpenList = RandomizeSameScoreNodes(OpenList);

                // Debug
                if (false)
                {
                    Console.WriteLine();
                    Console.WriteLine("----- " + RunTime);
                    Console.WriteLine("CurrentNode: " + CurrentNode.GridPosition + " S" + CurrentNode.Score + " H" + CurrentNode.Heuristic);
                    Console.Write("ClosedList:  ");
                    foreach (Node node in ClosedList)
                    {
                        Console.Write(node.GridPosition + " S" + node.Score + " H" + node.Heuristic + " - ");
                    }
                    Console.Write("\n");
                    Console.Write("OpenList:    ");
                    foreach (Node node in OpenList)
                    {
                        Console.Write(node.GridPosition + " S" + node.Score + " H" + node.Heuristic + " - ");
                    }
                    Console.Write("\n");
                    Console.Write("Conclusion:  ");
                    foreach (Node node in ConclusionNodeList)
                    {
                        Console.Write(node.GridPosition + " S" + node.Score + " H" + node.Heuristic + " - ");
                    }
                    Console.WriteLine();
                }

                // Add element to ClosedList
                // Take first lowest element from sorted OpenList
                // Remove element from OpenList
                ClosedList.Add(CurrentNode);
                CurrentNode = OpenList[0];
                OpenList.RemoveAt(0);

            } while (CurrentNode.Heuristic > 0);

            // Get resulting path
            // Cycle from end node to first node
            while (CurrentNode.CostFromStart > 0)
            {
                ConclusionNodeList.Add(CurrentNode);
                CurrentNode = CurrentNode.Parent;
            }

            // Tile Coloring Debug
            if (false)
            {
                GameMap.Reset();
                foreach (Node node in OpenList)
                {
                    GameMap.UpdateTileType(node.GridPosition, GameSetting.TileType.Brown);
                }
                foreach (Node node in ClosedList)
                {
                    GameMap.UpdateTileType(node.GridPosition, GameSetting.TileType.Purple);
                }
                foreach (Node node in ConclusionNodeList)
                {
                    GameMap.UpdateTileType(node.GridPosition, GameSetting.TileType.Yellow);
                }
            }

            List<Point> ConclusionPointList = new List<Point>();
            foreach (Node ConclusionNode in ConclusionNodeList)
            {
                ConclusionPointList.Insert(0, ConclusionNode.GridPosition);
            }

            return ConclusionPointList;
        }
Пример #10
0
 private static List<Node> ConvertPointListToNodeList(List<Point> PointList, Map GameMap, Point StartPoint, Point EndPoint)
 {
     List<Node> NodeList = new List<Node>();
     foreach (Point SinglePoint in PointList)
     {
         int DistanceFromStartPoint = GameMap.DistanceOfPoints(StartPoint, SinglePoint);
         int DistanceToEndPoint = GameMap.DistanceOfPoints(SinglePoint, EndPoint);
         NodeList.Add(new Node(SinglePoint, DistanceFromStartPoint, DistanceToEndPoint));
     }
     return NodeList;
 }