void SetUpTile(RaycastHit2D hitTile) { //the tile gets its sprite and type changed based on the currently selected type SpriteRenderer tileSR = hitTile.transform.GetComponent <SpriteRenderer>(); Tiletype newTiletype = Tiletype.Null; switch (currentTileType) { case Tiletype.Null: tileSR.sprite = empty; newTiletype = Tiletype.Null; break; case Tiletype.Floor: tileSR.sprite = floor; newTiletype = Tiletype.Floor; break; case Tiletype.Wall: tileSR.sprite = wall; newTiletype = Tiletype.Wall; break; case Tiletype.Entry: tileSR.sprite = entry; newTiletype = Tiletype.Entry; break; } //and the tile array also is changed tiletypeArray[(int)hitTile.transform.position.x, (int)hitTile.transform.position.y] = newTiletype; }
void Tile_Random(bool seal, bool muted) { if (!seal) { obj.SetDisplay(value.ToString()); if (!muted) { ConsoleMaster.Instance.Output(string.Format("//ResultOutput = SUCCESS(Output:Datamine_Results(Nearby_Secure_Nodes) = {0})", value)); } if (message != null) { ConsoleMaster.Instance.Output(string.Format("//TextFileFound = '{0}'", message)); } currentTile = (Tiletype)UnityEngine.Random.Range(1, (float)Enum.GetValues(typeof(Tiletype)).Cast <Tiletype>().Max() - 1); ConsoleMaster.Instance.Output(string.Format("//Abnormaltiledetected: typeof('{0}')", currentTile)); visible = false; SetColor(localworldgenref); Activate(); } else { obj.SetDisplay("[x]"); if (!muted) { ConsoleMaster.Instance.Output("//ResultOutput = FAILURE(Output:DataNodeSealed - WARNING: 'Possible detection of activities, Integrity comprimised.')"); } // Add integrity damage } }
/// <summary> /// Creates a new tile and sets the bounding box based on the x,y and height values /// </summary> /// <param name="a_x">The x value for bounding box</param> /// <param name="a_y">The y value for bounding box</param> /// <param name="a_height"></param> public Tile(int a_x, int a_y, int a_height, Tiletype a_type) { m_height = a_height; m_type = a_type; m_boundBox = new BoundingBox(new Vector3(a_x, a_y, a_height), new Vector3(a_x + Map.m_tileSize, a_y + Map.m_tileSize, a_height)); }
//room generating function public void GenerateRoom(int W, int H, ref Tiletype[,] roomArray, ref List <Region> regionList) { bool check = false; width = W; height = H; originX = 0; originY = 0; roomArray = new Tiletype[W, H]; //fill the room with tiles RandomPercentFill(roomArray); //start iterating with the current room for (int i = 0; i < RandomlyPick(smoothCount.m_Min, smoothCount.m_Max); i++) { SmoothTiles(roomArray); } check = RoomCheck(roomArray); if (!check) { GenerateRoom(W, H, ref roomArray, ref regionList); return; } //check for "regions" ProcessRoom(roomArray, ref regionList); }
//get all the existing regions(groups of tiles), by checking for similar tiletypes, uses GetRegionTiles List <List <Position> > GetRegions(Tiletype tileType, Tiletype[,] roomArray) { //create a list of lists of regions List <List <Position> > regions = new List <List <Position> >(); //room array to flag tiles for being checked beforehand, 1 is checked, 0 is unchecked int[,] roomFlags = new int[width, height]; //for each tile in the room for (int x = originX; x < width - 1; x++) { for (int y = originY; y < height - 1; y++) { //check if the tile hasn't been checked beforehand, and tile is of similar type with the given value(walls or floors) if (roomFlags[x, y] == 0 && roomArray[x, y] == tileType) { //check in the vicinity of the current tile to check if there are any similar tiles of same type near its vicinity then create a region List <Position> newRegion = GetRegionTiles(x, y, roomArray); //add the region to the list regions.Add(newRegion); //flag all tiles in the added region as being checked once foreach (Position tile in newRegion) { roomFlags[tile.tileX, tile.tileY] = 1; } } } } //return the list of lists return(regions); }
void SetImage(Tiletype type) { if (type == Tiletype.BLACK) { spriteRenderer.sprite = blackSprite; } else if (type == Tiletype.WHITE) { spriteRenderer.sprite = whiteSprite; } }
//this functions gets tiles coordinates and checks around the tile for similar tiletypes List <Position> GetRegionTiles(int originX, int originY, Tiletype[,] roomArray) { //create a list of tiles List <Position> tiles = new List <Position>(); //create the room array of tiles in order to flag already checked tiles int[,] roomFlags = new int[width, height]; //acquire tiletype of the tile at the given array coordinates Tiletype tileType = roomArray[originX, originY]; //create a queue of tile coordinates Queue <Position> queue = new Queue <Position>(); //add the current tile at the given coordinates to the queue queue.Enqueue(new Position(originX, originY)); //also flag the tile as already being checked once roomFlags[originX, originY] = 1; while (queue.Count > 0) { //acquire a tile from the queue Position tile = queue.Dequeue(); //add it to the list tiles.Add(tile); //check horizontally and vertically around the tile for similar tile types for (int i = tile.tileX - 1; i <= tile.tileX + 1; i++) { for (int j = tile.tileY - 1; j <= tile.tileY + 1; j++) { //if the tile is inside the room constraints and the tile is on the same row or column if (IsInRoomRange(i, j) && (j == tile.tileY || i == tile.tileX)) { //and if the tile has not been checked before and is of similar type if (roomFlags[i, j] == 0 && roomArray[i, j] == tileType) { //flag it roomFlags[i, j] = 1; //add it to the queue queue.Enqueue(new Position(i, j)); } } } } } //return the list of tiles return(tiles); }
//the option to generate a room from a file //this will also set a custom room Width and Height within the section bounds, sections will be discussed more in their own scripts public void GenerateRoom(ref int W, ref int H, ref Tiletype[,] roomArray, ref List <Region> regionList) { //load the text asset containing room data from the Resources folder TextAsset txt = (TextAsset)Resources.Load("DungeonStartRoom", typeof(TextAsset)); //get all the lines, split by the endings string[] fileLines = txt.text.Split('\n'); //split the initial line that contains the room W and H List <String> lineStrings = new List <string>(fileLines[0].Split('_')); //set them W = Convert.ToInt32(lineStrings[0]); H = Convert.ToInt32(lineStrings[1]); width = W; height = H; originX = 0; originY = 0; roomArray = new Tiletype[W, H]; //set up the array tiles from the rest of lines each part of a line being separated by a "_" for (int i = 1; i < fileLines.Length - 1; i++) { lineStrings = new List <string>(fileLines[i].Split('_')); roomArray[Convert.ToInt32(lineStrings[0]), Convert.ToInt32(lineStrings[1])] = (Tiletype)Enum.Parse(typeof(Tiletype), lineStrings[2]); } //set up the region of the file based room List <Position> regionTiles = new List <Position>(); for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { regionTiles.Add(new Position(i, j)); } } regionList.Add(new Region(regionTiles, roomArray, W, H)); //room creation will be discussed in its specific files }
//tiletype value is set on dropdown trigger public void GetTileType() { switch (selectedTileType.value) { case 0: currentTileType = Tiletype.Null; break; case 1: currentTileType = Tiletype.Wall; break; case 2: currentTileType = Tiletype.Floor; break; case 3: currentTileType = Tiletype.Entry; break; } }
static void AddTile(TiletypeShape tileShape, TiletypeSpecial tileSpecial, TiletypeMaterial tileMaterial, TiletypeVariant tileVariant, string tileDirection, Tiletype token) { if (tileDefs == null) { tileDefs = new Dictionary <TiletypeShape, Dictionary <TiletypeSpecial, Dictionary <TiletypeMaterial, Dictionary <TiletypeVariant, Dictionary <string, Tiletype> > > > >(); } if (!tileDefs.ContainsKey(tileShape)) { tileDefs[tileShape] = new Dictionary <TiletypeSpecial, Dictionary <TiletypeMaterial, Dictionary <TiletypeVariant, Dictionary <string, Tiletype> > > >(); } if (!tileDefs[tileShape].ContainsKey(tileSpecial)) { tileDefs[tileShape][tileSpecial] = new Dictionary <TiletypeMaterial, Dictionary <TiletypeVariant, Dictionary <string, Tiletype> > >(); } if (!tileDefs[tileShape][tileSpecial].ContainsKey(tileMaterial)) { tileDefs[tileShape][tileSpecial][tileMaterial] = new Dictionary <TiletypeVariant, Dictionary <string, Tiletype> >(); } if (!tileDefs[tileShape][tileSpecial][tileMaterial].ContainsKey(tileVariant)) { tileDefs[tileShape][tileSpecial][tileMaterial][tileVariant] = new Dictionary <string, Tiletype>(); } tileDefs[tileShape][tileSpecial][tileMaterial][tileVariant][tileDirection] = token; }
public Tile(int a_x, int a_y, Tiletype a_type) { x = a_x; y = a_y; m_type = a_type; }
public Tile(Tiletype currentTile, bool visible, TilePhysical obj) { value = 0; this.currentTile = currentTile; this.obj = obj; }
//Constructors: public Tile(TilePhysical obj) { value = 0; currentTile = Tiletype.normal; this.obj = obj; }
void SetType(Tiletype tiletype) { type = tiletype; SetImage(type); }
public void SetInit(Tiletype tiletype, Vector2Int position, StageManager stageManager) { intPosition = position; this.stageManager = stageManager; SetType(tiletype); }