Example #1
0
 private static void CheckForPlayerSuccess(this GameLevel gameLevel)
 {
     if (gameLevel.DeadCreepCount + gameLevel.ExitReachedCreepCount <
         gameLevel.WaveGenerator.TotalCreepsInLevel)
     {
         return;
     }
     gameLevel.FinishChapter();
 }
Example #2
0
        public static void RemoveCreeps(this GameLevel level)
        {
            var allCreeps = EntitiesRunner.Current.GetEntitiesOfType <Creep>();

            foreach (Creep creep in allCreeps)
            {
                creep.Dispose();
            }
        }
Example #3
0
        public static void RemoveModel(this GameLevel level)
        {
            var models = EntitiesRunner.Current.GetEntitiesOfType <Model>();

            foreach (Model model in models)
            {
                model.Dispose();
            }
        }
Example #4
0
        public static void SpawnCreepInGame(this GameLevel gameLevel, CreepType type)
        {
            var path  = gameLevel.GetPathForCreep().ToList();
            var creep = gameLevel.CreateAndShowCreep(type, path[0], path[path.Count - 1]);

            foreach (var position in path)
            {
                creep.Path.Add(new Vector2D(position.X, position.Y));
            }
        }
Example #5
0
 private static void ReduceOneLife(this GameLevel gameLevel)
 {
     Player.Current.LivesLeft--;
     gameLevel.ExitReachedCreepCount++;
     if (IsPlayerLifeLessThan20Percent())
     {
         PlaySound(GameSounds.LowHealth);
     }
     gameLevel.UpdateLife();
     gameLevel.CheckChapterCompletion();
 }
Example #6
0
        private static void UpdateGridAndExistingCreeps(this GameLevel level, Vector2D gridPosition)
        {
            var index = level.GetIndexForMapData(gridPosition);

            level.MapData[index] = LevelTileType.Placeable;
            level.GetPathFinding().SetReachableAndUpdate(index);
            foreach (var creep in EntitiesRunner.Current.GetEntitiesOfType <Creep>())
            {
                level.IsTherePossibleExitPath(creep);
            }
            level.UpdatePathsIfPossible();
        }
Example #7
0
 protected virtual void RenderLevel()
 {
     if (GameLevel == null)
     {
         return;
     }
     //levelGrid = new Grid3D(new Vector3D(GameLevel.Size / 2), GameLevel.Size);
     //levelGrid.RenderLayer = -10;
     //levelGrid.IsVisible = false;
     new LevelDebugRenderer(GameLevel);
     GameLevel.RenderLevel();
 }
Example #8
0
        private static bool IsPossibleAddTower(this GameLevel level, Vector2D gridPosition)
        {
            var index = level.GetIndexForMapData(gridPosition);

            if (level.UpdateExistingCreeps(gridPosition + Vector2D.Half) &&
                level.UpdatePathsIfPossible())
            {
                return(true);
            }
            level.MapData[index] = LevelTileType.Placeable;
            level.GetPathFinding().SetReachableAndUpdate(index);
            return(false);
        }
Example #9
0
 private static bool UpdateExistingCreeps(this GameLevel gameLevel, Vector2D position)
 {
     foreach (var creep in EntitiesRunner.Current.GetEntitiesOfType <Creep>())
     {
         if (creep.Path.Count == 0 || !creep.Path.Contains(position))
         {
             continue;
         }
         if (!IsTherePossibleExitPath(gameLevel, creep))
         {
             return(false);
         }
     }
     return(true);
 }
Example #10
0
        private static void SetUnreacheableTile(this GameLevel level, Vector2D position,
                                                TowerType type)
        {
            var pathfinding = level.GetPathFinding();
            var index       = (int)(position.X + position.Y * level.Size.Width);

            level.MapData[index] = LevelTileType.Blocked;
            pathfinding.SetUnreachableAndUpdate(index);
            var towerProperties = ContentLoader.Load <TowerPropertiesXml>(Xml.TowerProperties.ToString());
            var buff            = new BuffEffect(Player.Current.Avatar.GetType().Name + "RangeMultiplier");
            var range           = towerProperties.Get(type).Range;

            range *= buff.Multiplier > 0.0f ? buff.Multiplier : 1.0f;
            pathfinding.UpdateWeightInAdjacentNodes(position, (int)range, 100);
        }
Example #11
0
 public static void RemoveTowers(this GameLevel level)
 {
     foreach (var tower in EntitiesRunner.Current.GetEntitiesOfType <Tower>())
     {
         var towerMapPos = level.GetMapCoordinates(tower.Position.GetVector2D());
         var index       = level.GetIndexForMapData(towerMapPos);
         if (index >= level.MapData.Length)
         {
             return;
         }
         level.MapData[index] = LevelTileType.Placeable;
         level.GetPathFinding().SetReachableAndUpdate(index);
         tower.Dispose();
     }
 }
Example #12
0
 public static void CleanLevel(this GameLevel level)
 {
     if (level == null)
     {
         return;
     }
     level.RemoveTowers();
     level.RemoveCreeps();
     level.GetStoredPaths().Clear();
     level.RemoveCurrentTracers();
     ResetPlayerGoldAndLives();
     level.DeadCreepCount        = 0;
     level.ExitReachedCreepCount = 0;
     level.WaveGenerator.Dispose();
     level.IsCompleted = false;
 }
Example #13
0
        private static Creep CreateAndShowCreep(this GameLevel gameLevel, CreepType type,
                                                Vector2D spawnPoint, Vector2D finalTarget)
        {
            var creep = new Creep(type, spawnPoint)
            {
                FinalTarget = finalTarget
            };

            creep.RenderModel();
            creep.IsDead += () =>
            {
                gameLevel.EarnGold((int)creep.GetStatValue("Gold"));
                gameLevel.DeadCreepCount++;
                gameLevel.CheckChapterCompletion();
            };
            creep.ReachedExit += gameLevel.ReduceOneLife;
            return(creep);
        }
Example #14
0
 public static bool UpdatePathsIfPossible(this GameLevel gameLevel)
 {
     for (int i = 0; i < gameLevel.SpawnPoints.Count; i++)
     {
         for (int j = 0; j < gameLevel.GoalPoints.Count; j++)
         {
             var list = gameLevel.GetPath(gameLevel.SpawnPoints[i], gameLevel.GoalPoints[j]);
             if (list.GetListOfCoordinates().Count == 0)
             {
                 return(false);
             }
             var storedPaths = gameLevel.GetStoredPaths();
             storedPaths[i * gameLevel.SpawnPoints.Count + j] = list;
         }
     }
     gameLevel.UpdateTracers();
     return(true);
 }
Example #15
0
        private static bool IsTherePossibleExitPath(this GameLevel gameLevel, Creep creep)
        {
            var isThereWay = false;

            for (int i = 0; i < gameLevel.GoalPoints.Count; i++)
            {
                var list =
                    gameLevel.GetPath(creep.Position.GetVector2D(), gameLevel.GoalPoints[i]).
                    GetListOfCoordinates();
                if (list.Count == 0)
                {
                    continue;
                }
                creep.Path        = list.Select(element => element + Vector2D.Half).ToList();
                creep.FinalTarget = creep.Path[creep.Path.Count - 1];
                isThereWay        = true;
                break;
            }
            return(isThereWay);
        }
Example #16
0
        public static void SellTower(this GameLevel level, Vector2D position)
        {
            var list = EntitiesRunner.Current.GetEntitiesOfType <Tower>();

            foreach (var tower in list)
            {
                var towerTile = tower.Position - Vector2D.Half;
                if (towerTile != position)
                {
                    continue;
                }
                PlaySound(GameSounds.TowerSell);
                level.EarnGold((int)(tower.GetStatValue("Cost") / 2));
                level.GetPathFinding().UpdateWeightInAdjacentNodes(position,
                                                                   (int)(tower.GetStatValue("Range")), -100);
                tower.Dispose();
                level.UpdateGridAndExistingCreeps(position);
                return;
            }
        }
		private bool IsSpecialAttackPossible()
		{
			level = (GameLevel)Level.Current;
			return level.IsInsideLevelGrid(clickedPosition) &&
				(Player.Current.Avatar.SpecialAttackAIsActivated ||
					Player.Current.Avatar.SpecialAttackBIsActivated);
		}
Example #18
0
 public static void AddCreepWaveToWaveGenerator(this GameLevel gameLevel, CreepWave wave)
 {
     gameLevel.WaveGenerator.waveList.Add(wave);
     gameLevel.WaveGenerator.UpdateTotalCreepCountForLevel();
     gameLevel.UpdateWave();
 }