public Animation CreateAnimation(AnimationType animationName, IndexPair startLocation)
        {
            switch (animationName)
            {
                case AnimationType.PlayerAnimation:
                    temp = new PlayerAnimation();
                    break;

                case AnimationType.MonsterAnimation:
                    temp = new MonsterAnimation(); // new MonsterAnimation();
                    temp.AddCollider();
                    //((MonsterAnimation)temp).Collider = new Collider(((MonsterAnimation)temp));
                    break;
                // The animation point will be set when its requested from the pool
                case AnimationType.BulletAnimation:
                    temp = new BulletAnimation();
                    temp.AddCollider();
                    //((BulletAnimation)temp).Collider = new Collider(((BulletAnimation)temp));
                    break;
                // The animation point will be set when its requested from the pool
                case AnimationType.ExplosionAnimation:
                    temp = new ExplosionAnimation();
                    break;

                default:
                    return null;
            }
            return temp;
        }
        public static Animation CreateEmpyAnimation(AnimationType animationName)
        {
            IndexPair startLocation = new IndexPair(0, 0);
            switch (animationName)
            {
                case AnimationType.PlayerAnimation:
                    temp = new PlayerAnimation();
                    temp.AddCollider();
                    break;

                case AnimationType.MonsterAnimation:
                    temp = new MonsterAnimation(); // new MonsterAnimation();
                    temp.AddCollider();
                    //((MonsterAnimation)temp).Collider = new Collider(((MonsterAnimation)temp));
                    break;
                // The animation point will be set when its requested from the pool
                case AnimationType.BulletAnimation:

                    temp = new BulletAnimation();
                    temp.AddCollider();
                    //((BulletAnimation)temp).Collider = new Collider(((BulletAnimation)temp));
                    break;
                // The animation point will be set when its requested from the pool
                case AnimationType.ExplosionAnimation:
                    temp = new ExplosionAnimation();
                    temp.Collider = new Collider(temp, System.Drawing.Rectangle.Empty);
                    break;

                default:
                    return null;
            }
            return temp;
        }
 public static IndexPair GetTileCoordinates(this Point pt, int tileHeight)
 {
     IndexPair tempPt = new IndexPair(0, 0);
     tempPt.I = (int)Math.Floor((double)(pt.X / tileHeight));
     tempPt.J = (int)Math.Floor((double)(pt.Y / tileHeight));
     return tempPt;
 }
示例#4
0
 public PathFinder(RouteInformation informations)
 {
     levelSize = MapLoader.LevelDimensions;
     this.informations = informations;
     initializeMap();
     startNode = Map[informations.StartLocationIndex.I, informations.StartLocationIndex.J];
     startNode.State = NodeState.Open;
     endNode = Map[informations.EndLocationIndex.I, informations.EndLocationIndex.J];
 }
        public static void InitializeController()
        {
            window = Program.MainWindow;

            // Subscribe to the notify event
            window.ViewNotification += Window_ViewNotification;
            player = Player.PlayerInstance;
            player.Initialize();
            // Lazy initialization of projectile pool
            projectilePool = ProjectilePool.Instance;
            projectilePool.Initialize();

            /*for (int i = 0; i < MapLoader.MonstersCount; i++)
            {
                IndexPair startPoint = new IndexPair(MapLoader.Monsters[i].StartPoint.X, MapLoader.Monsters[i].StartPoint.Y);
                IndexPair endPoint = new IndexPair(MapLoader.Monsters[i].EndPoint.X, MapLoader.Monsters[i].EndPoint.Y);
                Monster mon = new Monster(startPoint, endPoint);
                movingObjects.Add(mon);
            }*/

            for (int i = 0; i < MapLoader.BombsCount; i++)
            {
                IndexPair start = new IndexPair(MapLoader.Bombs[i].StartPoint.X, MapLoader.Bombs[i].StartPoint.Y);
                BombA bomb = new BombA(start);
                constantObjects.Add(bomb);
            }

            for (int i = 0; i < MapLoader.CoinsCount; i++)
            {
                IndexPair start = new IndexPair(MapLoader.Coins[i].StartPoint.X, MapLoader.Coins[i].StartPoint.Y);
                CoinGift coin = new CoinGift(start);
                constantObjects.Add(coin);
            }

            for (int i = 0; i < MapLoader.BulletsCount; i++)
            {
                IndexPair start = new IndexPair(MapLoader.Bullets[i].StartPoint.X, MapLoader.Bullets[i].StartPoint.Y);
                BulletGift bullet = new BulletGift(start);
                constantObjects.Add(bullet);
            }

            movingObjects.Add(player);
            backgroundIllusionTimer.Interval = 100;
            backgroundIllusionTimer.Elapsed += BackgroundIllusionTimer_Elapsed;
            backgroundIllusionTimer.Enabled = true;

#if !DEBUG

#endif
            drawGraphics += DrawMovingBackground;
            drawGraphics += MapLoader.DrawGameFlares;
            drawGraphics += MapLoader.DrawLevelFloor;
            drawGraphics += MapLoader.DrawLevelObstacles;
            drawGraphics += player.UpdateGraphics;
            drawGraphics += UpdateTiles;
            drawGraphics += DrawShots;
        }
示例#6
0
 public Node(IndexPair destination, IndexPair index)
 {
     if (MapLoader.IsWalkable(index))
         walkable = true;
     else walkable = false;
     destinationLocation = destination;
     State = NodeState.Untested;
     Location = index;
     G = 0;
     H = GetTraversalCost(index, destination);
 }
示例#7
0
        public LevelTile(Point twoDimPoint, int textureIndex, TileType type, IndexPair tileIndecies)
        {
            if (type == TileType.Corner)
            {
                dimensions = new Size(64, 128);
                twoDimPoint.Y -= 64;
                twoDimPoint.X -= 64;
            }
            else
                dimensions = new Size(64, 64);

            this.texture = Model.TileTextures[textureIndex];
            this.type = type;
            this.twoDimPoint = twoDimPoint;
            this.tileIndecies = tileIndecies;
        }
示例#8
0
 private static List<IndexPair> GetStraighPath(IndexPair firstIndex, IndexPair lastIndex)
 {
     List<IndexPair> newPath = new List<IndexPair>();
     int I = firstIndex.I, J = firstIndex.J, delta;
     if (firstIndex.I == lastIndex.I)
     {
         if (firstIndex.J > lastIndex.J)
             delta = -1;
         else delta = 1;
         newPath.Add(firstIndex);
         while (J != lastIndex.J)
         {
             J += delta;
             newPath.Add(new IndexPair(I, J));
         }
     }
     else if (firstIndex.J == lastIndex.J)
     {
         if (firstIndex.I > lastIndex.I)
             delta = -1;
         else delta = 1;
         newPath.Add(firstIndex);
         while (I != lastIndex.I)
         {
             I += delta;
             newPath.Add(new IndexPair(I, J));
         }
     }
     return newPath;
 }
示例#9
0
 public RouteInformation(IndexPair startLocation, IndexPair endLocation)
 {
     StartLocationIndex = startLocation;
     EndLocationIndex = endLocation;
 }
示例#10
0
 private static bool IsShortCut(IndexPair firstIndex, IndexPair lastIndex)
 {
     if (firstIndex.I != lastIndex.I && firstIndex.J != lastIndex.J) return false;
     if (firstIndex == lastIndex) return false;
     int I = firstIndex.I, J = firstIndex.J, delta;
     if (firstIndex.I == lastIndex.I)
     {
         if (firstIndex.J > lastIndex.J)
             delta = -1;
         else delta = 1;
         while (J != lastIndex.J)
         {
             J += delta;
             if (!MapLoader.IsWalkable(new IndexPair(I, J)))
                 return false;
         }
         return true;
     }
     else if (firstIndex.J == lastIndex.J)
     {
         if (firstIndex.I > lastIndex.I)
             delta = -1;
         else delta = 1;
         while (I != lastIndex.I)
         {
             I += delta;
             if (!MapLoader.IsWalkable(new IndexPair(I, J)))
                 return false;
         }
         return true;
     }
     return false;
 }
示例#11
0
 private static IEnumerable<IndexPair> GetAdjacentLocations(IndexPair fromLocation)
 {
     return new IndexPair[]
     {
         new IndexPair(fromLocation.I-1, fromLocation.J  ),
         new IndexPair(fromLocation.I,   fromLocation.J+1),
         new IndexPair(fromLocation.I+1, fromLocation.J  ),
         new IndexPair(fromLocation.I,   fromLocation.J-1)
     };
 }
示例#12
0
 public RouteInformation(LevelTile startLocation, LevelTile endLocation)
 {
     StartLocationIndex = startLocation.TileIndecies;
     EndLocationIndex = endLocation.TileIndecies;
 }
示例#13
0
 public Wrapper(int[,] level, IndexPair playerLocation)
 {
     this.level = level;
     this.MonsterLocations = new Dictionary<IndexPair, IndexPair>();
     this.playerLocation = playerLocation;
 }
示例#14
0
 public static bool IsWalkable(IndexPair pair)
 {
     return level[pair.I, pair.J] == 0 ? true : false;
 }
        public static void InitializeController()
        {
            window = Program.MainWindow;

            // Subscribe to the notify event
            window.ViewNotification += Window_ViewNotification;
            player = Player.PlayerInstance;
            player.Initialize();
            // Lazy initialization of projectile pool
            projectilePool = ProjectilePool.Instance;
            projectilePool.Initialize();

            IndexPair start;

            for (int i = 0; i < MapLoader.MonstersCount; i++)
            {
                start = new IndexPair(MapLoader.Monsters[i].StartPoint.X, MapLoader.Monsters[i].StartPoint.Y);
                IndexPair endPoint = new IndexPair(MapLoader.Monsters[i].EndPoint.X, MapLoader.Monsters[i].EndPoint.Y);
                Monster   mon      = new Monster(start, endPoint);
                movingObjects.Add(mon);
            }

            for (int i = 0; i < MapLoader.BombsCount; i++)
            {
                start = new IndexPair(MapLoader.Bombs[i].StartPoint.X, MapLoader.Bombs[i].StartPoint.Y);
                BombA bomb = new BombA(start.IndexesToCoordinates());
                bomb.AddCollider();
                constantObjects.Add(bomb);
            }

            for (int i = 0; i < MapLoader.CoinsCount; i++)
            {
                start = new IndexPair(MapLoader.Coins[i].StartPoint.X, MapLoader.Coins[i].StartPoint.Y);
                CoinGift coin = new CoinGift(start.IndexesToCoordinates());
                coin.AddCollider();
                constantObjects.Add(coin);
            }

            for (int i = 0; i < MapLoader.BulletsCount; i++)
            {
                start = new IndexPair(MapLoader.Bullets[i].StartPoint.X, MapLoader.Bullets[i].StartPoint.Y);
                BulletGift bullet = new BulletGift(start.IndexesToCoordinates());
                bullet.AddCollider();
                constantObjects.Add(bullet);
            }

            movingObjects.Add(player);
            backgroundIllusionTimer.Interval = 100;
            backgroundIllusionTimer.Elapsed += BackgroundIllusionTimer_Elapsed;
            backgroundIllusionTimer.Enabled  = true;

#if !DEBUG
#endif
            drawGraphics += DrawMovingBackground;
            //drawGraphics += MapLoader.DrawGameFlares;
            //drawGraphics += MapLoader.DrawLevelFloor;
            //drawGraphics += MapLoader.DrawLevelObstacles;
            //drawGraphics += player.UpdateGraphics;
            //drawGraphics += UpdateTiles;
            //drawGraphics += DrawShots;
            //drawGraphics += DrawScore;

            graphicsSynchronizationTimer.Interval = 100;
            graphicsSynchronizationTimer.Enabled  = true;
            graphicsSynchronizationTimer.Elapsed += GraphicsSynchronizationTimer_Elapsed;
            InitializeSortedGraphics();
        }
示例#16
0
 public RouteInformation(LevelTile startLocation, LevelTile endLocation)
 {
     StartLocationIndex = startLocation.TileIndecies;
     EndLocationIndex   = endLocation.TileIndecies;
 }
示例#17
0
 public Wrapper(int[,] level, IndexPair playerLocation, Dictionary<IndexPair, IndexPair> MonsterLocations)
 {
     this.level = level;
     this.MonsterLocations = MonsterLocations;
     this.playerLocation = playerLocation;
 }
示例#18
0
 internal static float GetTraversalCost(IndexPair location, IndexPair otherLocation)
 {
     float deltaX = otherLocation.I - location.I;
     float deltaY = otherLocation.J - location.J;
     return (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
 }
示例#19
0
        static MapLoader()
        {
            loadFromFile();

            flares = Model.FlareAnimation;

            walkableTiles = new List<LevelTile>(256);
            obstacleTiles = new List<LevelTile>(32);

            //TODO LoadLevel
            //  = level.GetLength(1);
            //TODO read binary array From File
            levelRows = level.GetLength(0);
            levelColomns = level.GetLength(1);
            levelDimensions = new IndexPair(levelRows, levelColomns);
            LoadLevel();

            // Determine the player start location
            //playerStartLocation = walkableTiles[0].Position;
        }
示例#20
0
 public RouteInformation(IndexPair startLocation, IndexPair endLocation)
 {
     StartLocationIndex = startLocation;
     EndLocationIndex   = endLocation;
 }
示例#21
0
        public static void ReadLevelFile(string folderPath)
        {
            int rows = -1;
            int cols = -1;
            int[,] level;

            IndexPair playerPosition;

            int monstersCount = -1;
            EscapeRunner.View.MapLoader.Monster[] monsters;

            int bombsCount = -1;
            EscapeRunner.View.MapLoader.StaticObject[] bombs;

            int coinsCount = -1;
            EscapeRunner.View.MapLoader.StaticObject[] coins;

            int bulletsCount = -1;
            EscapeRunner.View.MapLoader.StaticObject[] bullets;

            StreamReader reader = new StreamReader(folderPath);

            /*string json = reader.ReadToEnd();

            var things = JsonConvert.DeserializeObject(json, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.None
            });

            Wrapper wrapper = (Wrapper)things;

            Debugger.Break();*/

            // read player position
            string line = reader.ReadLine();

            if (line != null)
            {
                int[] points = Array.ConvertAll(line.Substring(24, (line.Length - 26)).Split(','), s => int.Parse(s));

                playerPosition = new IndexPair(points[0], points[1]);

                MapLoader.PlayerStartLocation = playerPosition;
            }
            line = reader.ReadLine();

            // read monsters count
            line = reader.ReadLine();

            if (line != null)
            {
                monstersCount = Convert.ToInt32(line.Substring(20, (line.Length - 21)));
            }
            line = reader.ReadLine();

            // read monsters locations
            if (monstersCount > 0)
            {
                line = reader.ReadLine();

                monsters = new Monster[monstersCount];
                int counter = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    if (counter < monstersCount)
                    {
                        line = line.Substring(2, (line.Length - 3));

                        if (counter != (monstersCount - 1))
                            line = line.Substring(0, (line.Length - 2));

                        int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s));

                        Point start = new Point(points[0], points[1]);
                        Point end = new Point(points[2], points[3]);
                        monsters[counter] = new Monster(start, end);
                        counter++;
                    }
                    else
                    {
                        break;
                    }
                }
                MapLoader.MonstersCount = monstersCount;
                MapLoader.Monsters = monsters;
            }
            line = reader.ReadLine();

            // read bombs locations
            line = reader.ReadLine();

            if (line != null)
            {
                bombsCount = Convert.ToInt32(line.Substring(17, (line.Length - 18)));
            }
            line = reader.ReadLine();

            if (bombsCount > 0)
            {
                line = reader.ReadLine();
                bombs = new StaticObject[bombsCount];

                int counter = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    if (counter < bombsCount)
                    {
                        line = line.Substring(2, (line.Length - 3));

                        if (counter != (bombsCount - 1))
                            line = line.Substring(0, (line.Length - 2));

                        int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s));

                        Point start = new Point(points[0], points[1]);
                        bombs[counter] = new StaticObject(start);
                        counter++;
                    }
                    else
                    {
                        break;
                    }
                }
                MapLoader.BombsCount = bombsCount;
                MapLoader.Bombs = bombs;
            }
            line = reader.ReadLine();

            // read coins locations
            line = reader.ReadLine();

            if (line != null)
            {
                coinsCount = Convert.ToInt32(line.Substring(17, (line.Length - 18)));
            }
            line = reader.ReadLine();

            if (coinsCount > 0)
            {
                line = reader.ReadLine();
                coins = new StaticObject[coinsCount];

                int counter = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    if (counter < coinsCount)
                    {
                        line = line.Substring(2, (line.Length - 3));

                        if (counter != (coinsCount - 1))
                            line = line.Substring(0, (line.Length - 2));

                        int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s));

                        Point start = new Point(points[0], points[1]);
                        coins[counter] = new StaticObject(start);
                        counter++;
                    }
                    else
                    {
                        break;
                    }
                }
                MapLoader.CoinsCount = coinsCount;
                MapLoader.Coins = coins;
            }
            line = reader.ReadLine();

            // read bullets locations
            line = reader.ReadLine();

            if (line != null)
            {
                bulletsCount = Convert.ToInt32(line.Substring(19, (line.Length - 20)));
            }
            line = reader.ReadLine();

            if (coinsCount > 0)
            {
                line = reader.ReadLine();
                bullets = new StaticObject[bulletsCount];

                int counter = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    if (counter < bulletsCount)
                    {
                        line = line.Substring(2, (line.Length - 3));

                        if (counter != (bulletsCount - 1))
                            line = line.Substring(0, (line.Length - 2));

                        int[] points = Array.ConvertAll(line.Split(','), s => int.Parse(s));

                        Point start = new Point(points[0], points[1]);
                        bullets[counter] = new StaticObject(start);
                        counter++;
                    }
                    else
                    {
                        break;
                    }
                }
                MapLoader.BulletsCount = bulletsCount;
                MapLoader.Bullets = bullets;
            }
            line = reader.ReadLine();

            // read map dimensions
            line = reader.ReadLine();

            if (line != null)
            {
                cols = Convert.ToInt32(line.Substring(10, (line.Length - 11)));
            }

            line = reader.ReadLine();

            if (line != null)
            {
                rows = Convert.ToInt32(line.Substring(10, (line.Length - 11)));
            }

            // read level
            if (rows > 0 && cols > 0)
            {
                line = reader.ReadLine();
                line = reader.ReadLine();

                level = new int[rows, cols];
                int counter = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    if (counter < rows)
                    {
                        line = line.Substring(2, (line.Length - 3));

                        if (counter != (rows - 1))
                            line = line.Substring(0, (line.Length - 2));

                        int counter2 = 0;

                        string[] lines = line.Split(',');

                        foreach (var item in lines)
                        {
                            if (counter2 < cols)
                                level[counter, counter2++] = int.Parse(item);
                        }
                        counter++;
                        //level[counter++] = Array.ConvertAll(line.Split(','), s => int.Parse(s));
                    }
                    else
                    {
                        break;
                    }
                }
                MapLoader.level = level;
            }

            reader.Close();
        }