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
 /// <summary>
 /// Gets the current game Instance - constructs an <see cref="T:Escapade.Escapade"/>
 /// object if a current one doesn't exist
 /// </summary>
 /// <returns>The Instance</returns>
 public static Escapade GetInstance()
 {
     if (_instance == null)
     {
         _instance = new Escapade();
     }
     return(_instance);
 }
Esempio n. 3
0
 public void EnemySpawnTest()
 {
     //enemy initial location X= 25 and Y = 20
     //Method spawn new enemy, checking their location spawned
     Escapade.SpawnMoreEnemy();
     Assert.AreEqual(25, Escapade.SpawnMoreEnemy().Location.X);
     Assert.AreEqual(20, Escapade.SpawnMoreEnemy().Location.Y);
 }
Esempio n. 4
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. 5
0
        /// <summary>
        /// Cleans the map and removes isolated groups of 1-2
        /// tiles to make the map look much cleaner
        /// </summary>
        void CleanMap()
        {
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (GetNeighbours(x, y) <= 2)
                    {
                        Map [x, y].Type = TileType.Air;
                    }
                }
            }
            Location l = Escapade.GetPlayer().Location;

            if (l != null)
            {
                Map [l.X, l.Y].Type = TileType.Air;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Modifies a tile at a specific location
        /// </summary>
        /// <param name="loc">The location of the tile being modified</param>
        public void ModifyTile(Location loc)
        {
            if (SwinGame.PointPointDistance(new Point2D {
                X = loc.X, Y = loc.Y
            }, new Point2D {
                X = Escapade.GetPlayer().Location.X, Y = Escapade.GetPlayer().Location.Y
            }) > 2)
            {
                return;
            }
            if (loc.X < 1 || loc.X >= Width - 1 || loc.Y < 1 || loc.Y >= Height - 1)
            {
                return;
            }
            Tile tile = Map [loc.X, loc.Y];

            if (tile.Type == TileType.Rock)
            {
                Map[loc.X, loc.Y] = new Tile(TileType.Air);
                if (tile.Mineral != null)
                {
                    Escapade.GetPlayer().Inventory.AddItem(tile.Mineral);
                }
            }
            if (tile.Type == TileType.Air && SwinGame.KeyDown(KeyCode.ShiftKey))
            {
                Map [loc.X, loc.Y] = new Tile(TileType.Rock);
            }
            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (loc.X + x < 0 || loc.Y + y < 0 || loc.X + x > Width - 1 || loc.Y + y > Height - 1)
                    {
                        continue;
                    }
                    Map [loc.X + x, loc.Y + y].Mask = GetTileMask(loc.X + x, loc.Y + y);
                }
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
 /// <summary>
 /// Entry point of the program - starts the game up
 /// </summary>
 public static void Main()
 {
     Escapade.GetInstance().Start();
 }