Esempio n. 1
0
        /// <summary>
        /// Draws this player at its current location, and draws a
        /// path to its target location if it has one
        /// </summary>
        public override void Draw()
        {
            int size = Escapade.GetWorld().Size;

            SwinGame.FillRectangle(_playerColor, Location.X * size, Location.Y * size, size, size);
            SwinGame.DrawRectangle(Color.White, Location.X * size, Location.Y * size, size, size);
        }
Esempio n. 2
0
        public Enemy(int id, string name, Location location, int directionX, int directionY) : base(id, name, location)
        {
            _location.X = 25;
            _location.Y = 20;
            _directionX = directionX;
            _directionY = directionY;
            _world      = Escapade.GetWorld();

            // JY- to differentiate between the boss and the spawned ones
            if (name == "Boss Enemy")
            {
                _enemyColor = Color.GreenYellow;
            }
            else
            {
                _enemyColor = Color.MediumVioletRed;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Uses the A* algorithm to find a path from start to target in the shortest distance possible
        /// Stores the found path in targetpath
        /// </summary>
        /// <param name="start">Start location</param>
        /// <param name="target">Target location</param>
        void Pathfind(Location start, Location target)
        {
            #region NodeLists
            List <PathNode> open   = new List <PathNode>();
            List <PathNode> closed = new List <PathNode>();
            #endregion NodeLists

            List <Location> found = new List <Location>();

            #region FindingPath

            PathNode current = new PathNode(start.X, start.Y, start, target);
            current.CalculateScores();

            open.Add(current);

            // While the current location isn't our target
            while (!(current.X == target.X && current.Y == target.Y))
            {
                open = open.OrderBy(x => x.H).ToList();

                //Console.WriteLine ("HEY MAN IM SORTIN HERE");
                //foreach (PathNode n in open)
                //  Console.WriteLine (n.F.ToString ());
                //Console.WriteLine ("~~~~Thanks Matt :)~~~~");

                current = open[0];

                open.Remove(current);
                closed.Add(current);

                #region AddNeighbours

                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        if (x == 0 && y == 0)
                        {
                            continue;
                        }

                        int newX = current.X + x;
                        int newY = current.Y + y;

                        PathNode node = new PathNode(newX, newY, start, target);
                        node.CalculateScores();

                        if (Escapade.GetWorld().Map[newX, newY].Type != TileType.Air)
                        {
                            continue;
                        }

                        //If it's in the closed list, skip it
                        if (closed.Any(Node => Node.X == newX && Node.Y == newY))
                        {
                            continue;
                        }

                        if (!open.Any(Node => Node.X == newX && Node.Y == newY))
                        {
                            node.Parent = current;
                            open.Add(node);
                        }
                    }
                }
                #endregion AddNeighbours
            }
            #endregion FindingPath

            PathNode pn = current;

            while (pn.Parent != null)
            {
                found.Add(pn);
                pn = pn.Parent;
            }
            found.Reverse();
            TargetPath = found;
        }