예제 #1
0
        public static void RemoveCreeps(this GameLevel level)
        {
            var allCreeps = EntitiesRunner.Current.GetEntitiesOfType <Creep>();

            foreach (Creep creep in allCreeps)
            {
                creep.Dispose();
            }
        }
예제 #2
0
 private static void CheckForPlayerSuccess(this GameLevel gameLevel)
 {
     if (gameLevel.DeadCreepCount + gameLevel.ExitReachedCreepCount <
         gameLevel.WaveGenerator.TotalCreepsInLevel)
     {
         return;
     }
     gameLevel.FinishChapter();
 }
예제 #3
0
        public static void RemoveModel(this GameLevel level)
        {
            var models = EntitiesRunner.Current.GetEntitiesOfType <Model>();

            foreach (Model model in models)
            {
                model.Dispose();
            }
        }
예제 #4
0
        private void PlaceTowerMarkers()
        {
            var placeableTiles = GameLevel.GetAllTilesOfType(LevelTileType.Placeable);

            foreach (Vector2D tile in placeableTiles)
            {
                GameLevel.buildSpotMarkers.Add(new Billboard(new Vector3D(tile, 0.01f), Size.One,
                                                             ContentLoader.Load <Material>("TowerBuildingSpotMat"), BillboardMode.Ground));
            }
        }
예제 #5
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));
            }
        }
예제 #6
0
 private static void ReduceOneLife(this GameLevel gameLevel)
 {
     Player.Current.LivesLeft--;
     gameLevel.ExitReachedCreepCount++;
     if (IsPlayerLifeLessThan20Percent())
     {
         PlaySound(GameSounds.LowHealth);
     }
     gameLevel.UpdateLife();
     gameLevel.CheckChapterCompletion();
 }
예제 #7
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();
        }
예제 #8
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();
 }
예제 #9
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);
        }
예제 #10
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);
 }
예제 #11
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);
        }
예제 #12
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();
     }
 }
예제 #13
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;
 }
예제 #14
0
		public GameLevel ()
		{
            layerInstance = this;

			// enable touches
#if XBOX || OUYA
            TouchEnabled = false;
            GamePadEnabled = true;
#else
			TouchEnabled = true;
#endif

			// enable accelerometer
			AccelerometerEnabled = false;

			// ask director for the window size
			var screenSize = CCDirector.SharedDirector.WinSize;

			// create and initialize a Label
			var label = new CCLabelTTF("Game Layer", "MarkerFelt", 22);

			// position the label on the center of the screen
			label.Position = CCDirector.SharedDirector.WinSize.Center;

			// add the label as a child to this Layer
			AddChild(label);

			menuStartPosition = new CCPoint( 70 , screenSize.Height-24);

			var gameMenuLabel = new CCLabelTTF("Game Menu", "MarkerFelt", 18);
			var button1 = new CCMenuItemLabel (gameMenuLabel, ShowMenu);

			MenuButton = new CCMenu (button1);
			MenuButton.Position = menuStartPosition;

			AddChild (MenuButton, 10);

			openWithMenuInsteadOfGame = false;

            if (GameData.SharedData.FirstRunEver && openWithMenuInsteadOfGame)
            {
                CCLog.Log("First run ever");
                Schedule(ShowMenuFromSelector, 2f);
                GameData.SharedData.FirstRunEver = false;
            }

        }
예제 #15
0
        public GameLevel()
        {
            layerInstance = this;

            // enable touches
#if XBOX || OUYA
            TouchEnabled   = false;
            GamePadEnabled = true;
#else
            TouchEnabled = true;
#endif

            // enable accelerometer
            AccelerometerEnabled = false;

            // ask director for the window size
            var screenSize = CCDirector.SharedDirector.WinSize;

            // create and initialize a Label
            var label = new CCLabelTTF("Game Layer", "MarkerFelt", 22);

            // position the label on the center of the screen
            label.Position = CCDirector.SharedDirector.WinSize.Center;

            // add the label as a child to this Layer
            AddChild(label);

            menuStartPosition = new CCPoint(70, screenSize.Height - 24);

            var gameMenuLabel = new CCLabelTTF("Game Menu", "MarkerFelt", 18);
            var button1       = new CCMenuItemLabel(gameMenuLabel, ShowMenu);

            MenuButton          = new CCMenu(button1);
            MenuButton.Position = menuStartPosition;

            AddChild(MenuButton, 10);

            openWithMenuInsteadOfGame = false;

            if (GameData.SharedData.FirstRunEver && openWithMenuInsteadOfGame)
            {
                CCLog.Log("First run ever");
                Schedule(ShowMenuFromSelector, 2f);
                GameData.SharedData.FirstRunEver = false;
            }
        }
예제 #16
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);
        }
예제 #17
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);
 }
예제 #18
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);
        }
예제 #19
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;
            }
        }
예제 #20
0
 private void AddWaves()
 {
     GameLevel.AddCreepWaveToWaveGenerator(new CreepWave(2.0f, 3.0f, "Wood"));
     GameLevel.AddCreepWaveToWaveGenerator(new CreepWave(2.0f, 3.0f, "Plastic"));
     GameLevel.AddCreepWaveToWaveGenerator(new CreepWave(2.0f, 3.0f, "Iron"));
 }
예제 #21
0
 protected override void InitializeLevel()
 {
     base.InitializeLevel();
     Level.Current.MapData = LivingRoomLevelInfo.MapInfo(GameLevel.Size);
     GameLevel.InitializeGameGraph();
 }
예제 #22
0
 private void AddWaves()
 {
     GameLevel.AddCreepWaveToWaveGenerator(new CreepWave(2.0f, 3.0f, "Sand"));
     GameLevel.AddCreepWaveToWaveGenerator(new CreepWave(2.0f, 3.0f, "Glass"));
 }
예제 #23
0
 public static void AddCreepWaveToWaveGenerator(this GameLevel gameLevel, CreepWave wave)
 {
     gameLevel.WaveGenerator.waveList.Add(wave);
     gameLevel.WaveGenerator.UpdateTotalCreepCountForLevel();
     gameLevel.UpdateWave();
 }