public void OnLevelSelected(World.Level level, int step) { if (_game._currentLevelIndex == 0) { _previous.gameObject.SetActive(false); } else { _previous.gameObject.SetActive(true); } if (_game._currentLevelIndex == _game._levels.Length - 1) { _next.gameObject.SetActive(false); } else { _next.gameObject.SetActive(true); } if (step < 0) { StartCoroutine(PunchScale(true)); } else if (step > 0) { StartCoroutine(PunchScale(false)); } if (_game._selectedLevel != null) { _levelName.text = _game._selectedLevel.Name; } // TODO upd num of players ?? //foreach (var display in _playerDisplays) //{ // display.TryChangeState(Player.State.Disabled); //} }
/// <summary> /// Gracefully-failing vault build for use by console commands. /// </summary> /// <param name="position">Lower-left corner.</param> /// <param name="rotation">Rotation in degrees.</param> /// <returns>True if vault build was successful.</returns> public static bool TryBuild( string id, World.Level level, Vector2Int position, float rotation) { if (!Assets.Vaults.TryGetValue(id, out Vault vault)) { return(false); } vault.Initialize(); if (!level.Contains(position + vault.Size)) { return(false); } for (int x = position.x; x < vault.Size.x + position.x; x++) { for (int y = position.y; y < vault.Size.y + position.y; y++) { TerrainDefinition terrain = vault.GetTerrain( x - position.x, y - position.y); if (terrain != null) { Vector2Int rot = new Vector2Int( x - position.x, y - position.y).Rotate(rotation); if (level.TryGetCell(rot + position, out World.Cell cell)) { cell.Terrain = terrain; } } } } return(true); }
/// <summary> /// Safe vault building function for internal use. /// </summary> /// <param name="position">Lower-left corner.</param> /// <param name="rotation">Rotation in degrees.</param> /// <returns>The vault definition so its flags can be consumed.</returns> public static Vault Build( string id, World.Level level, Vector2Int position, float rotation) { if (!Assets.Vaults.TryGetValue(id, out Vault vault)) { throw new ArgumentException($"Vault {id} not found."); } vault.Initialize(); //if (!level.Contains(position + vault.Size)) // throw new ArgumentException // ("Position too close to level bounds."); for (int x = position.x; x < vault.Size.x + position.x; x++) { for (int y = position.y; y < vault.Size.y + position.y; y++) { TerrainDefinition terrain = vault.GetTerrain( x - position.x, y - position.y); if (terrain != null) { Vector2Int rot = new Vector2Int( x - position.x, y - position.y).Rotate(rotation); if (level.TryGetCell(rot + position, out World.Cell cell)) { cell.Terrain = terrain; } } } } return(vault); }