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); }
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(); }
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); }
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(); } }