public Tile GetNext() { var tileNumber = _random.Next(0, 5); var tile = TileFactory.CreateTile((TileType)tileNumber); return(tile); }
private List <Map.Tile> RecreateTilesFromMatchStatus(MatchStatus matchStatus) { var oldTiles = FindObjectsOfType <Map.Tile>(); foreach (var tile in oldTiles) { Destroy(tile); } var tiles = new List <Map.Tile>(); foreach (var statusTile in matchStatus.Tiles) { var tile = _tileFactory.CreateTile(statusTile.TileType, statusTile.Position.x, statusTile.Position.y, statusTile.Id); if (statusTile.Uncovered) { tile.Uncover(); } if (statusTile.Digged) { tile.Dig(); } tiles.Add(tile); } return(tiles); }
void CreateFromRoomDataTile(Vector3 position, RoomData roomToCreate) { TileType tileTypeLocal; Vector2 currentPosition = new Vector2(position.x, position.y); //reads from roomdata if (roomToCreate.WallTiles.Contains(currentPosition)) { tileTypeLocal = TileType.wall; } else if (roomToCreate.DoorTiles.Contains(currentPosition)) { tileTypeLocal = TileType.door; } else if (roomToCreate.EnemyTiles.Contains(currentPosition)) { tileTypeLocal = TileType.enemySpawner; } else if (roomToCreate.RoomSwitcherTiles.Contains(currentPosition)) { tileTypeLocal = TileType.roomSwitcher; } else if (roomToCreate.DungeonEnterTiles.Contains(currentPosition)) { tileTypeLocal = TileType.dungeonEnter; } else if (roomToCreate.ChestTiles.Contains(currentPosition)) { tileTypeLocal = TileType.chest; } else { tileTypeLocal = TileType.walkable; } Tile tile = _tileFactory.CreateTile(tileTypeLocal, position, this.transform, this, TileManager); TrashController.ObjInTheRoom.Add(tile.gameObject); AddInMap(tileTypeLocal, tile); }
void CreateTileObject(Vector3 position, LevelData levelData, int spriteIndex, GameObject parent, TileData tileData, Dictionary <string, string> tileProperties) { GameObject tile = tileFactory.CreateTile(spriteIndex, levelData.tilesets [0].tilewidth); tilePropertiesFactory.CreatePropertyComponents(tile, tileWidth, tileProperties); tile.transform.SetParent(parent.transform); tile.transform.Translate(position); if (!tileData.visible) { tile.GetComponent <SpriteRenderer>().enabled = false; } }
public Tile GenerateTile(TileFactory tileFactory, Vector2Int gridPosition, int depth) { int realDepth = depth - gridPosition.y; GroundGroup group = GetGroup(realDepth); Tile tile = tileFactory.CreateTile(gridPosition, Tile.TileType.Ground, group.prefab); if (group != null) { tile.GetComponent <SpriteRenderer>().sprite = group.sprites[Random.Range(0, group.sprites.Length)]; } return(tile); }
private void InitializeTileMap() { var tileWidth = _tileAtlases[0].TileWidth; var tileHeight = _tileAtlases[0].TileHeight; TileMapIterator((data) => { if (_mapData[data.offset] == 0) { return; } _tiles[data.offset] = _tileFactory.CreateTile(_canvasBitmaps[0], new Vector2(data.x * tileWidth, data.y * tileHeight), new Vector2(tileWidth, tileHeight), (TileType)_mapData[data.offset]); }); }
private void GenerateTile(int mapValue, int gridX, int gridY) { if (mapValue == 0) { return; } var go = TileFactory.CreateTile(mapValue); var trm = go.transform; trm.SetParent(bgTileRoot, false); Vector3 pos = layout.TileStartPos; float offx = gridX * layout.TileW; float offy = gridY * layout.TileH; pos.x = pos.x + offx; pos.y = pos.y - offy; pos.z = 0; trm.position = pos; trm.localScale = Vector3.one * layout.Scale; }
/// <summary> /// Initializes the Game with configured settings. /// </summary> private void Start() { tileFactory = TileFactory.instance; unitFactory = UnitFactory.instance; var selectedMap = SceneLoader.GetParam(SceneLoader.LOAD_MAP_PARAM); if (selectedMap != "") { mapData = MapLoader.instance.GetMapAsset(selectedMap); } else { } var gameTypeString = SceneLoader.GetParam(SceneLoader.GAME_TYPE_PARAM); if (gameTypeString == GameManager.SINGLEPLAYER_GAME_TYPE) { gameType = GameType.Singleplayer; } else if (gameTypeString == GameManager.MULTIPLAYER_GAME_TYPE) { gameType = GameType.Multiplayer; } else { } if (gameType == GameType.Singleplayer) { var singleGameTypeString = SceneLoader.GetParam(SceneLoader.SINGLEPLAYER_GAME_TYPE_PARAM); if (singleGameTypeString == GameManager.CAMPAIGN_GAME_TYPE) { singleplayerGameType = SingleplayerGameType.Campaign; } else if (singleGameTypeString == GameManager.PRACTICE_GAME_TYPE) { singleplayerGameType = SingleplayerGameType.Practice; } else { throw new Exception("Singleplayer Game Type not set!"); } } else if (gameType == GameType.Multiplayer) { } // Read map data from text file to get columns and rows var tileData = JsonUtility.FromJson <TileDataWrapper>(mapData.text); int cols = tileData.Columns; int rows = tileData.Rows; // Set up Players var players = new List <Player>(); for (int playerNum = 1; playerNum <= numberOfPlayers; playerNum++) { Player newPlayer = null; if (gameType == GameType.Singleplayer) { if (singleplayerGameType == SingleplayerGameType.Practice) { newPlayer = new Player($"Player {playerNum}", playerNum); } else if (singleplayerGameType == SingleplayerGameType.Campaign) { if (playerNum == 1) { newPlayer = CampaignManager.instance.CampaignPlayerData; newPlayer.Units.Clear(); } else { newPlayer = new Player($"Enemy Faction", playerNum); } } else { throw new Exception($"Error setting up Player {playerNum}"); } } if (gameType == GameType.Multiplayer) { // TODO: Get logic to set up Players with unique names from server? } players.Add(newPlayer); } // If playing a Singleplayer game, the user always controls the first Player (Player 1) if (gameType == GameType.Singleplayer) { ControllingPlayer = players.First(); } // If playing a Multiplayer game, the server decides which player the user controls if (gameType == GameType.Multiplayer) { // TODO: Set up logic to find out which player the human in controlling } model.ConstructModel(cols, rows, players); var newObjectViews = new Dictionary <Vector2Int, ObjectView>(); Tuple <Unit, GameObject> newUnitTuple = null; var boardTileData = tileData.tileData; var boardUnitData = boardTileData.Where(data => data.Player != 0).Select(data => new { Player = data.Player, UnitPosition = new Vector3(data.Column, data.Row, 0f), UnitData = data.UnitData } ); foreach (var boardTile in boardTileData) { // Initialize Tile Model/View var newTile = tileFactory.CreateTile(boardTile, view.tiles.transform); model.AddTile(newTile); } foreach (var boardUnit in boardUnitData) { var unitData = boardUnit.UnitData; var unitPosition = boardUnit.UnitPosition; var unitPlayer = boardUnit.Player; if (gameType == GameType.Singleplayer) { if (singleplayerGameType == SingleplayerGameType.Campaign) { if (unitPlayer == 1) { const char DELIMITER = '_'; const int UNIT_NAME_INDEX = 3; if (unitData == "FREE_ALLY_SQUARE") { // TODO: Make Free allies } else { var split_string = unitData.Split(DELIMITER); if (split_string.Length == 4) { // Named Unit var unitName = split_string[UNIT_NAME_INDEX]; var existingUnit = CampaignManager.instance.CampaignPlayerData.CampaignUnits.SingleOrDefault( campaignUnit => campaignUnit.Name == unitName); if (existingUnit != null) { var cloneUnit = existingUnit.Clone(); newUnitTuple = unitFactory.ImportUnitForBoard(unitPosition, view.units.transform, cloneUnit, unitData); } else { newUnitTuple = unitFactory.CreateUnitForBoard(unitPosition, view.units.transform, unitData); } } else { throw new NotImplementedException(); } } } else { newUnitTuple = unitFactory.CreateUnitForBoard(boardUnit.UnitPosition, view.units.transform, unitData); CampaignManager.instance.ModifyUnitStats(newUnitTuple.Item1); } } else if (singleplayerGameType == SingleplayerGameType.Practice) { newUnitTuple = unitFactory.CreateUnitForBoard(boardUnit.UnitPosition, view.units.transform, unitData); } else { throw new Exception("Singleplayer Game Type not set"); } } else if (gameType == GameType.Multiplayer) { } else { throw new Exception("Game Type not set"); } var newUnitModel = newUnitTuple.Item1; var newUnitObject = newUnitTuple.Item2; var newUnitView = new UnitView(newUnitObject); var unitPos = unitPosition.ToVector2Int(); newObjectViews.Add(unitPos, newUnitView); model.AddUnit(newUnitModel, unitPlayer, unitPos.x, unitPos.y); } // Invoke model to set up tile neighbors model.AddNeighbors(); viewModel.ConstructViewModel(); view.ConstructView(cols, rows, newObjectViews); view.mCamera.MoveToPosition(model.GridForUnit(ControllingPlayer.Units[0]).ToVector3()); var text = SceneLoader.GetParam(SceneLoader.LOAD_OPENING_DIALOGUE_PARAM); StartGame(); if (text != "") { dialogueManager.LoadDialogue(text); } }
public LevelData GenerateGrid(string levelFilePath) { string jsonString; List <Vector3> checkpoints = new List <Vector3>(); if (File.Exists(levelFilePath)) { using StreamReader reader = new StreamReader(File.OpenRead(levelFilePath)); jsonString = reader.ReadToEnd(); } else { throw new FileNotFoundException("The level file with the path: " + levelFilePath + " was not found! Remember to set Build Action to 'Content' and Copy to 'Copy always' in the file properties!"); } data = LevelDataConverter.ConvertJsonToLevelData(jsonString); _grid = new Tile[(int)data.gridSize.X, (int)data.gridSize.Y, (int)data.gridSize.Z]; Vector3 pos = Vector3.Zero; for (int x = 0; x < (int)data.gridSize.X; x++) { for (int y = 0; y < (int)data.gridSize.Y; y++) { for (int z = 0; z < (int)data.gridSize.Z; z++) { if (data.gridValues[x, y, z] != ETileType.None) { //Super duper algorithm to determine what the current tile looks like! Tile.StaticTileType staticTileType = Tile.StaticTileType.DarkChocolate; int count = 0; for (int i = -1; i <= 1; i += 2) { if (x + i >= 0 && x + i < (int)data.gridSize.X) { count += data.gridValues[x + i, y, z] == ETileType.Static ? 1 : 0; } if (y + i >= 0 && y + i < (int)data.gridSize.Y) { count += data.gridValues[x, y + i, z] == ETileType.Static ? 1 : 0; } if (z + i >= 0 && z + i < (int)data.gridSize.Z) { count += data.gridValues[x, y, z + i] == ETileType.Static ? 1 : 0; } } if (count > 4) { staticTileType = Tile.StaticTileType.WhiteChocolate; } else if (count > 3) { staticTileType = Tile.StaticTileType.Chocolate; } if (y == 0) { staticTileType = Tile.StaticTileType.Chocolate; } Tile tile = tileFactory.CreateTile(pos + new Vector3(0, 0, data.gridSize.Z - 1), data.gridValues[x, y, z], staticTileType); tile?.InitializeTile(); //Giving the player a list of checkpoints, so that we can switch between them (for debug/demo purposes) if (tile != null && tile.TileType == ETileType.Checkpoint) { checkpoints.Add(tile.Transform3D.Translation); } _grid[x, y, (int)data.gridSize.Z - 1 - z] = tile; } else { _grid[x, y, (int)data.gridSize.Z - 1 - z] = null; } pos.Z -= data.tileSize.Z; //MonoGames Forward is -UnitZ } pos.Z = 0; pos.Y += data.tileSize.Y; } pos.Y = 0; pos.X += data.tileSize.X; } CreateShapes(data, _grid); SetPaths(data, _grid); SetActivatorIds(data, _grid); SetCollectibleIds(data, _grid); EventManager.FireEvent(new PlayerEventInfo { type = PlayerEventType.SetCheckpointList, checkpoints = checkpoints }); return(data); }
public override Tile.OverlapResolution OnOverlap(Tile overlapper) { Board.currBoard.SwapOutTile(overlapper, TileFactory.CreateTile(TileType.EATEN_CAKE)); tile.Kill(Tile.KillReason.EATEN); return(Tile.OverlapResolution.DO_NOTHING); }