public void SetTile(int index, TileEnum tileEnum) { Tuple <int, int> coord = Coord(index); grid[index] = tileEnum; gridMesh.UpdateMesh(coord.first, coord.second); }
public Tile(int x, int y, TileEnum te = TileEnum.Wall) { //assign data from constructor xPos = x; yPos = y; UpdateTileData(te); }
public void UpdateTileData(TileEnum te) { tileEnum = te; switch (tileEnum) { case TileEnum.Void: isPassable = false; cost = Mathf.Infinity; break; case TileEnum.Grass: isPassable = true; cost = 1; break; case TileEnum.Water: isPassable = true; cost = 1; break; case TileEnum.Wall: isPassable = false; cost = Mathf.Infinity; break; } }
public TileEnum[,] translate(MetaTileEnum[,] metaTiles) { //simplest implementation. uses only two tile types TileEnum[,] finalTiles = new TileEnum[metaTiles.GetLength(0), metaTiles.GetLength(1)]; for (int m = 0; m < metaTiles.GetLength(0); m++) { for (int n = 0; n < metaTiles.GetLength(1); n++) { switch (metaTiles[m, n]) { case MetaTileEnum.FLOOR_1: case MetaTileEnum.FLOOR_2: case MetaTileEnum.FLOOR_3: case MetaTileEnum.DOOR: finalTiles[m, n] = TileEnum.FLOOR1; break; default: finalTiles[m, n] = TileEnum.WALL5; break; } } } return(finalTiles); }
public static char ToTileChar(this TileEnum value) { if (value.ToString().Length == 4) { return(value.ToString()[3]); } return(value.ToString()[2]); }
public static int ToTileNumber(this TileEnum value) { if (value.ToString().Length == 4) { return(int.Parse(value.ToString().Substring(1, 2))); } return(int.Parse(value.ToString().Substring(1, 1))); }
public void PlaceTile(TileEnum tile) { UndoGame.Add(Model.DeepCopy()); var item = Model.Board[(int)tile]; if (item.Hotel != HotelEnum.NotUsed) { throw new Exception("Tile has already been placed!"); } item.Hotel = HotelEnum.Used; // Remove Tile from Player Model.Players[Model.ActivePlayer].TileBag.Remove(tile); // Get a New Tile PlayerGetNextTile(Model.Players[Model.ActivePlayer]); var adjacentTiles = GetAdjacent(tile); if (adjacentTiles.Count > 0) { var Hotel = HotelEnum.NotUsed; // Look for a Hotel foreach (var test in adjacentTiles) { if (Model.Board[(int)test].Hotel.IsHotel()) { Hotel = Model.Board[(int)test].Hotel; // If we find a hotel then break out of our search and use the Hotel found break; } if (Model.Board[(int)test].Hotel == HotelEnum.Used) { Hotel = HotelEnum.Used; } } if (!Hotel.IsHotel()) { Hotel = GetNextHotel(); } if (Hotel.IsHotel()) { item.Hotel = Hotel; ExpandTiles(adjacentTiles, Hotel); } } // Move to Next Player NextPlayer(); Model.LastTilePlaced = (TileEnum)item.Index; ViewModel.UpdateBoard(Model); ViewModel.UpdatePlayers(Model); }
//generate visual based on the data and spawn respective prefabs private void GenerateVisualTile() { for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { TileEnum tileType = tileData[x][y].tileEnum; GameObject go = Instantiate(tilePrefabs[(int)tileType], TileToWorldCoord(x, y), Quaternion.identity) as GameObject; go.transform.parent = transform; } } }
private bool IsTraversible(TileEnum tileType) { switch (tileType) { case TileEnum.GRASS: case TileEnum.HILL: return(true); default: return(false); } }
private List <TileEnum> GetAdjacent(TileEnum tile) { var result = new List <TileEnum>(); int number = tile.ToTileNumber(); char character = tile.ToTileChar(); // LEFT if (number != 1) { var newNumber = number - 1; var target = Model.Board[(int)GetTile(newNumber, character)]; if (target.Hotel != HotelEnum.NotUsed) { result.Add(target.Index); } } // RIGHT if (number != 12) { var newNumber = number + 1; var target = Model.Board[(int)GetTile(newNumber, character)]; if (target.Hotel != HotelEnum.NotUsed) { result.Add(target.Index); } } // UP if (character != 'A') { var newCharacter = character; newCharacter--; var target = Model.Board[(int)GetTile(number, newCharacter)]; if (target.Hotel != HotelEnum.NotUsed) { result.Add(target.Index); } } // DOWN if (character != 'I') { var newCharacter = character; newCharacter++; var target = Model.Board[(int)GetTile(number, newCharacter)]; if (target.Hotel != HotelEnum.NotUsed) { result.Add(target.Index); } } return(result); }
/* Tests if the tile at position index is enclosed by tiles of type tileType. * Returns false if the tile at position index is already of type tileType. */ public bool IsEnclosed(int index, TileEnum tileType) { if (!this.IsValidIndex(index) || this.grid[index] == tileType) { return(false); } bool ret = true; int[] dx = { 1, 0, -1, 0 }; int[] dy = { 0, 1, 0, -1 }; List <int> seen = new List <int> (); List <TileEnum> seenTypes = new List <TileEnum> (); List <int> todo = new List <int> (); seen.Add(index); seenTypes.Add(this.grid[index]); todo.Add(index); for (int ii = 0; ii < todo.Count;) { int count = todo.Count; for (; ii < count; ii++) { Tuple <int, int> coord = this.Coord(todo[ii]); for (int jj = 0; jj < 4; jj++) { index = this.Index(coord.first + dx[jj], coord.second + dy[jj]); if (!IsValidIndex(index)) { ret = false; goto loopBreak; } if (this.grid[index] != tileType) { seen.Add(index); seenTypes.Add(this.grid[index]); todo.Add(index); //SetTile(index, tileType); this.grid[index] = tileType; } } } } loopBreak: for (int ii = 0; ii < seen.Count; ii++) { //SetTile(seen[ii], seenTypes[ii]); this.grid[seen[ii]] = seenTypes[ii]; } return(ret); }
private void SetHotel(TileEnum tile, HotelEnum hotel) { if (hotel.IsHotel()) { // If the Tile was already a Hotel then decrement that Hotel if (Model.Board[(int)tile].Hotel.IsHotel()) { Model.Hotels[(int)Model.Board[(int)tile].Hotel].TileCount--; } Model.Hotels[(int)hotel].TileCount++; } Model.Board[(int)tile].Hotel = hotel; }
public TileControl FindTile(TileEnum tile) { foreach (TileControl item in Controls) { if (item == null) { continue; } if (item.Tile == tile) { return(item); } } return(null); }
TileEnum[][] InitGameBoard(TileEnum[][] board) { board = new TileEnum[gameSizeX][]; for (int x = 0; x < gameSizeX; x++) { board [x] = new TileEnum[gameSizeY]; for (int y = 0; y < gameSizeY; y++) { board [x][y] = TileEnum.None; } } return(board); }
void createTile(IntVector2 tilePos, TileEnum type) { GameObject sample = Instantiate(tilledCell); if (type == TileEnum.TILLED) { sample.GetComponentInChildren <Renderer>().material = tilledMaterial; } else { sample.GetComponentInChildren <Renderer>().material = wateredMaterial; } //sample.transform.parent = transform; sample.name = type.ToString(); sample.transform.position = new Vector3(tilePos.x * cellSize + cellSize / 2, 0, tilePos.y * cellSize + cellSize / 2); objectTileGrid[tilePos] = sample; if (!Game.current.tileGrid.ContainsKey(tilePos)) { Game.current.tileGrid[tilePos] = type; } }
/* Flood fills from position index using type tileType. * Only overwrites tiles of the type found at index. Treats other tiletypes as boundaries. * Returns number of tiles flood filled */ public int FloodFill2(int index, TileEnum tileType) { if (!this.IsValidIndex(index)) { return(0); } if (tileType == this.grid[index]) { return(0); } int[] dx = { 1, 0, -1, 0 }; int[] dy = { 0, 1, 0, -1 }; List <int> todo = new List <int> (); TileEnum type = this.grid[index]; todo.Add(index); SetTile(index, tileType); //this.grid[index] = tileType; for (int ii = 0; ii < todo.Count;) { int count = todo.Count; for (; ii < count; ii++) { Tuple <int, int> coord = this.Coord(todo[ii]); for (int jj = 0; jj < 4; jj++) { index = this.Index(coord.first + dx[jj], coord.second + dy[jj]); if (!IsValidIndex(index) || this.grid[index] != type) { continue; } todo.Add(index); SetTile(index, tileType); //this.grid[index] = tileType; } } } return(todo.Count); }
public int CountSurroundingTileType(Tile selectedTile, TileEnum tileType) { int sum = 0; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (i == 0 && j == 0) { continue; } if (tileExists(selectedTile.VPos + i, selectedTile.HPos + j)) { if (tileArray[selectedTile.VPos + i, selectedTile.HPos + j].TileType == tileType) { sum++; } } } } return(sum); }
private GameObject GetTilePrefab(TileEnum type) { switch (type) { case TileEnum.GRASS: return(hexTileGrass); case TileEnum.HILL: return(hexTileHill); case TileEnum.MOUNTAIN: return(hexTileMountain); case TileEnum.RIVER: return(hexTileRiver); case TileEnum.WATER: return(hexTileWater); default: return(null); } }
public void CreateMap() { map = GetComponent <HexMapController>(); player = FindObjectOfType <PlayerController>(); if (transform.Find(TILE_HOLDER_NAME)) { DestroyImmediate(transform.Find(TILE_HOLDER_NAME).gameObject); } var tiles = new Dictionary <HexPos, HexTileController>(); Transform tileHolder = new GameObject(TILE_HOLDER_NAME).transform; Transform movableHolder = new GameObject("Movable").transform; Transform immovableHolder = new GameObject("Immovable").transform; tileHolder.parent = this.transform; movableHolder.parent = tileHolder; immovableHolder.parent = tileHolder; if (mapString != null) { String[] lines = mapString.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int y = 0; y < lines.Length; y++) { String[] tileChars = lines[lines.Length - 1 - y].Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries); for (int x = 0; x < tileChars.Length; x++) { TileEnum tileType = (TileEnum)int.Parse(tileChars[x]); GameObject tile = GetTilePrefab(tileType); if (tile != null) { HexPos hexPos = new HexPos(x, y); GameObject tileObject = Instantiate(GetTilePrefab(tileType), map.GetPositionFor(hexPos), Quaternion.identity); HexTileController hexTile = tileObject.GetComponentInChildren <HexTileController>(); hexTile.pos = hexPos; var hexOrigScale = hexTile.transform.localScale; hexTile.transform.localScale = new Vector3(scale * hexOrigScale.x, scaleY * hexOrigScale.y, scale * hexOrigScale.z); switch (tileType) { case TileEnum.GRASS: case TileEnum.HILL: case TileEnum.RIVER: tileObject.transform.parent = movableHolder; break; case TileEnum.MOUNTAIN: case TileEnum.WATER: tileObject.transform.parent = immovableHolder; break; } if (!showTiles) { hexTile.flipped = startPos.DistanceTo(hexPos) <= player.viewDistance; } tiles.Add(hexPos, hexTile); } } } } map.SetTiles(tiles); map.SetPlayerStart(startPos); }
internal void PlaceTile(TileEnum tile) { Controller.PlaceTile(tile); }
public void CreateTile() { // TODO: 맵을 처음 생성할 때는 특수효과 넣기 Debug.Log("InitIngameMap::CreateTile"); GameManager.Instance.mapTile = new FloorTile[gridRows, gridCols]; GameManager.Instance.mapCols = gridCols; GameManager.Instance.mapRows = gridRows; Quaternion waterRotation = Quaternion.identity; waterRotation.eulerAngles = new Vector3(90, 0, 0); Vector3 center = new Vector3((int)(gridCols / 2), 0, (int)(gridRows / 2)) * cellSize; float maxDist = Mathf.Sqrt(gridCols * gridCols + gridRows * gridRows); TileEnum[,] map = new TileEnum[gridRows, gridCols]; // Perlin noise 값에, 섬 중심으로부터의 거리에 비례하는 dist를 뺀 후 .05f를 더한다 // 이 값이 0.5f보다 크면 땅이라는 표시로 map[i, j]를 true로, 아니면 물이라는 표시로 map[i, j]를 false로 한다 int seed = Random.Range(0, 1000); for (int i = 0; i < gridRows; ++i) { for (int j = 0; j < gridCols; ++j) { float dist = Mathf.Sqrt((i - gridRows / 2) * (i - gridRows / 2) + (j - gridCols / 2) * (j - gridCols / 2)); dist /= maxDist / 2.5f; var perlin = Mathf.PerlinNoise((float)i / (float)gridRows * 8 + seed, (float)j / gridCols * 8 + seed) - dist + .05f; if (perlin > .2f) { map[i, j] = TileEnum.grass; } else if (perlin > .05f) { map[i, j] = TileEnum.soil; } else { map[i, j] = TileEnum.water; } } } // 위 알고리즘에서 섬 중심은 dist가 0이므로, Perlin Noise와 상관없이 항상 땅이다 // 그러므로 섬 중심으로부터 BFS 탐색을 진행해, 섬 중심과 떨어져 있는 땅을 제외하고 Instantiate한다 // 땅과 닿아있는 물 부분에는 waterObject를 Instantiate해 상호작용이 가능하게 한다 Queue <Pair <int, int> > q = new Queue <Pair <int, int> >(); q.Enqueue(new Pair <int, int>((int)(gridCols / 2), (int)(gridRows / 2))); // map[(int)(gridRows / 2), (int)(gridCols / 2)] = false; bool[,] check = new bool[gridRows, gridCols]; check.Initialize(); check[(int)(gridRows / 2), (int)(gridCols / 2)] = true; int[] dx = { 0, -1, 1, 0 }; int[] dy = { 1, 0, 0, -1 }; while (q.Count > 0) { var top = q.Dequeue(); int x = top.First; int y = top.Second; { GameObject obj; if (map[y, x] == TileEnum.grass) { obj = Instantiate(tileObjects[(y + x) % 2], new Vector3(x, 0, y) * cellSize - center, Quaternion.identity) as GameObject; } else { obj = Instantiate(soilObject, new Vector3(x, 0, y) * cellSize - center, Quaternion.identity) as GameObject; } obj.transform.parent = mapParent.transform; FloorTile ft = obj.AddComponent <FloorTile>(); ft.canMove = true; GameManager.Instance.mapTile[y, x] = ft; } for (int i = 0; i < 4; ++i) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx >= 0 && nx < gridCols && ny >= 0 && ny < gridRows && !check[ny, nx]) { check[ny, nx] = true; if (map[ny, nx] == TileEnum.grass || map[ny, nx] == TileEnum.soil) { q.Enqueue(new Pair <int, int>(nx, ny)); } else { var obj = Instantiate(waterObject, new Vector3(nx, 0, ny) * cellSize - center, waterRotation) as GameObject; obj.transform.parent = mapParent.transform; FloorTile ft = obj.AddComponent <FloorTile>(); ft.canMove = false; GameManager.Instance.mapTile[ny, nx] = ft; } } } } // 맵 생성이 완료된 뒤에 NavMesh를 업데이트함 NavigationManager.Instance.UpdateNavMeshSurfaces(); }
public TileInfo(TileEnum tileType, int growthStage) { //currentVeggie = veggie; //this.growthStage = growthStage; }
public void SetTile(int x, int y, TileEnum tileEnum) { this.tileMap.MapData[x, y] = (int)tileEnum; }
public Tile(TileEnum tileEnum, DirectionEnum direction = DirectionEnum.none) { this.tileEnum = tileEnum; this.direction = direction; }
public void Remove(TileEnum tile) { Tiles.Remove(tile); }