/// <summary> /// Stvara tile određenog tipa na tim kordinatama. /// </summary> /// <param name="col"></param> /// <param name="row"></param> /// <param name="type"></param> /// <returns>GameObject</returns> private GameObject CreateTile(int col, int row, Node.TileType type) { if (col >= cols * numberOfRooms || row >= rows) { Debug.LogWarning("CreateTile je problem"); return(null); } GameObject referenceTile = (GameObject)Resources.Load("TileDirt"); Node node = referenceTile.GetComponent <Node>(); referenceTile = node.CreateNode(type); referenceTile.GetComponent <Node>().tileType = type; GameObject tile = (GameObject)Instantiate(referenceTile, transform); tile.name = "(" + col + ", " + row + ")"; float posX = col * tileSize; float posY = row * -tileSize; tile.transform.position = new Vector2(posX, posY); grid[col, row] = tile; Destroy(referenceTile); return(tile); }
// detailed constructor, used in the node.copy() method public Node_old(int index, int north, int south, int east, int west, Color32 colorF, Color32 colorW, String floorSprite, String wallSprite, /*String cornerSprite,*/ String[] debris, Node.TileType type, bool hasSign, String signMessage, List <ConnectionSet> connectionOriginal, List <LineData> dataOriginal) { this.index = index; this.colorF = colorF; this.colorW = colorW; this.floorSprite = floorSprite; this.wallSprite = wallSprite; //this.cornerSprite = cornerSprite; for (int i = 0; i < 9; i++) { this.debris[i] = debris[i]; } this.type = type; this.hasSign = hasSign; this.signMessage = signMessage; //this.connectionList = connectionOriginal. foreach (ConnectionSet conn in connectionOriginal) // does this actually do anything? { this.connectionList.Add(conn.Copy()); } foreach (LineData data in dataOriginal) { this.dataList.Add(data.Copy()); } }
/// <summary> /// Vraća true ako postoje prepreke za postavljanje nove zamke. /// </summary> /// <param name="col"></param> /// <param name="row"></param> /// <param name="trapType"></param> /// <returns></returns> private bool CheckForTraps(int col, int row, Node.TileType trapType) { bool retVal = true; int currentCol = col; int currentRow = row; if (trapType == Node.TileType.trapSpikes) { if (!CheckForTile(currentCol - 1, currentRow - 1) && !CheckForTile(currentCol + 0, currentRow - 1) && !CheckForTile(currentCol + 1, currentRow - 1) && !CheckForTile(currentCol - 1, currentRow - 2) && !CheckForTile(currentCol + 0, currentRow - 2) && !CheckForTile(currentCol + 1, currentRow - 2) && !CheckForTile(currentCol - 1, currentRow - 3) && !CheckForTile(currentCol + 0, currentRow - 3) && !CheckForTile(currentCol + 1, currentRow - 3)) { retVal = false; } } return(retVal); }
/// <summary> /// changes the type of a tile. /// automatically applies visual changes and other supporting stuff to match the change /// </summary> /// <param name="room"></param> /// <param name="tileIndex"></param> /// <param name="newType"></param> public static void setType(LevelMap room, int tileIndex, Node.TileType newType) { //resets visual stuff //regular, source, target, checkpointon, checkpointoff if (room[tileIndex].type == Node.TileType.checkpoint) // if this tile was previously a checkpoint, remove it from the list { int i; bool removed = false; for (i = 0; i < room.checkpoints.Length; i++) { if (room.checkpoints[i] == tileIndex) { removed = true; i++; break; } } if (removed) { for (; i < room.checkpoints.Length; i++) { room.checkpoints[i - 1] = room.checkpoints[i]; } int[] temp = new int[room.checkpoints.Length - 1]; for (i = 0; i < room.checkpoints.Length - 1; i++) { temp[i] = room.checkpoints[i]; } room.checkpoints = temp; } } if (room[tileIndex].type == Node.TileType.sign) { room[tileIndex].signMessage = ""; } for (int i = 0; i < 9; i++) { if ( room[tileIndex].debris[i] != null && ( // remove sprites used for particular tile types room[tileIndex].debris[i].Equals("Source") || room[tileIndex].debris[i].Equals("Target") || room[tileIndex].debris[i].Equals("Checkpoint") || room[tileIndex].debris[i].Equals("Pit_Placeholder") || room[tileIndex].debris[i].Equals("Deb_Page_1") || room[tileIndex].debris[i].Equals("Deb_Page_2") || room[tileIndex].debris[i].Equals("Deb_Page_3") )) { room[tileIndex].debris[i] = ""; } } //set stuff based on tile type switch (newType) { case Node.TileType.regular: room[tileIndex].type = Node.TileType.regular; break; case Node.TileType.source: for (int i = 0; i < room.size; i++) { if (room[i].type == Node.TileType.source) { room[i].type = Node.TileType.regular; room[i].debris[4] = ""; } } room[tileIndex].type = Node.TileType.source; room[tileIndex].debris[4] = "Source"; room.sourceNodeIndex = tileIndex; break; case Node.TileType.target: for (int i = 0; i < room.size; i++) { if (room[i].type == Node.TileType.target) { room[i].type = Node.TileType.regular; room[i].debris[4] = ""; } } room[tileIndex].type = Node.TileType.target; room[tileIndex].debris[4] = "Target"; room.targetNodeIndex = tileIndex; break; case Node.TileType.checkpoint: room[tileIndex].type = Node.TileType.checkpoint; room[tileIndex].debris[4] = "Checkpoint"; int[] temp = new int[room.checkpoints.Length + 1]; // add this tile to the list of checkpoints for (int i = 0; i < room.checkpoints.Length; i++) { temp[i] = room.checkpoints[i]; } temp[room.checkpoints.Length] = tileIndex; room.checkpoints = temp; break; case Node.TileType.sign: room[tileIndex].type = Node.TileType.sign; room[tileIndex].debris[4] = "Deb_Page_1"; break; case Node.TileType.unwalkable: room[tileIndex].type = Node.TileType.unwalkable; // un-walkable tile type, doen't need anything else room[tileIndex].debris[4] = "Pit_Placeholder"; break; default: break; } }