Beispiel #1
0
        public static void SpawnTowerInGame(this GameLevel level, TowerType type,
                                            Vector2D gridPosition, float rotation = 0.0f)
        {
            var properties = ContentLoader.Load <TowerPropertiesXml>(Xml.TowerProperties.ToString());

            if (IsCreepInTile(gridPosition) || Player.Current.Gold < properties.Get(type).Cost)
            {
                return;
            }
            var index = level.GetIndexForMapData(gridPosition);

            if (level.MapData[index] != LevelTileType.Placeable)
            {
                return;
            }
            level.SetUnreacheableTile(gridPosition, type);
            if (!level.IsPossibleAddTower(gridPosition))
            {
                return;
            }
            var towerPosInWorldSpace = level.GetWorldCoordinates(gridPosition);
            var tower = new Tower(type, towerPosInWorldSpace, rotation);

            tower.RenderModel();
            level.EarnGold(-properties.Get(type).Cost);
        }
Beispiel #2
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);
        }
Beispiel #3
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;
            }
        }