public override void TakeTurn(ulong player, int x, int y) { if (Players[Turn] != player) { return; } GridTile[,] Grid = GameGrid.GetGrid(); x = x - 1; y = y - 1; if (Grid[x, y].State.Equals("free")) { if (Turn == 0) { Grid[x, y].State = "cross"; Turn = 1; } else if (Turn == 1) { Grid[x, y].State = "naughts"; Turn = 0; } } }
// Set all static variables to variables set in the editor void Initialize() { // Create a new world world = new GridTile[length / tileSize, width / tileSize]; worldNodes = new GridNode[length / tileSize + 1, width / tileSize + 1]; // Set the seed to a random value if set seed is 0, else keep it if (seed == 0) { seed = Random.Range(0, int.MaxValue); } // Creating new rand instance rand = new Rand(); middlePoint = new Vector3(length / 2, 0, width / 2); islandSteepness = baseHeight / (radius * radius); // Create biome object meshes biomeMeshes = BuildMeshes(); GameObject light = new GameObject(); light.transform.SetParent(transform); light.AddComponent <Light>().type = LightType.Directional; light.GetComponent <Light>().shadows = LightShadows.Soft; light.transform.rotation = Quaternion.Euler(45, 0, 0); light.name = "Sun"; light.GetComponent <Light>().shadowNormalBias = 0.94f; light.GetComponent <Light>().shadowBias = 0.433f; light.GetComponent <Light>().shadowNearPlane = 0.86f; }
IEnumerator GridSetup_Routine() { var tileList = GetComponentsInChildren <GridTile>(); var width = baseTile.GetComponent <BoxCollider>().size.x *baseTile.transform.lossyScale.x; var builder = GetComponent <GridBuilder>(); gridWidth = builder.gridXSize; gridLength = builder.gridYSize; tiles = new GridTile[gridWidth, gridLength]; string[] coords; int x, y; foreach (var tile in tileList) { coords = tile.name.Split('_')[1].Split('-'); x = int.Parse(coords[0]) - 1; y = int.Parse(coords[1]) - 1; tiles[x, y] = tile; tile.Setup(width); yield return(new WaitForEndOfFrame()); } if (OnSetupDone != null) { OnSetupDone(); } }
public void InitializeGrid(GameObject tile, float tileSize) { //Calculate tileSize to be able to scale the tile correctly. //translateTransform makes it possible to get the distance in units between two points. ; //Scale transform makes it possible to get the resized scale in units. float scaleTransform = tileSize / (tile.GetComponent <BoxCollider2D>().size.x * 100); foreach (GameObject prefab in Prefabs) { prefab.transform.localScale = new Vector3(scaleTransform, scaleTransform, scaleTransform); } //Get the amount of tiles on the y. Math.Ceiling rounds an float to the next integer. //Initialize the GameObject array and make it the size of the amount of tiles. gridTiles = new GridTile[gameManager.tileAmountX, gameManager.tileAmountY]; for (int i = 0; i < gameManager.tileAmountX; i++) { for (int j = 0; j < gameManager.tileAmountY; j++) { //Get a new gridTile, add it to the gridTiles array. Vector2Int arrayPosition = new Vector2Int(i, j); GridTile gridTile = gameManager.CreateTile(tile, arrayPosition); Instantiate(gridTile.tile, gridTile.position, new Quaternion(0, 0, 0, 0)); gridTiles[i, j] = gridTile; } } gameManager.gridTiles = new GridTiles(gridTiles); //Debug.Log(gameManager.gridTiles.tiles[0, 0].tile); }
public static GridTile FindClosestGridTile(Vector3 point) { GridTile[,] world = TerrainController.thisTerrainController.world; int tileSize = TerrainController.thisTerrainController.tileSize; int x = (int)((point.x + tileSize / 2) / tileSize); int z = (int)((point.z + tileSize / 2) / tileSize); if (world == null) { return(null); } if (x >= world.GetLength(0) || x < 0) { return(null); } if (z >= world.GetLength(1) || z < 0) { return(null); } return(world[x, z]); }
//// Start is called before the first frame update //void Start() //{ // wallsHolder = new GameObject("Walls Holder"); // wallsHolder.transform.parent = transform; //} public void GenerateGrid() { gridHolder = new GameObject("Grid Holder"); gridHolder.transform.parent = transform; grid = map.GenerateMap(gridSizeX, gridSizeY, gridHolder.transform); //SettupPlayers(); }
// Start is called before the first frame update void Start() { GetGridSize(); gridTiles = new GridTile[factoryHeight, factoryWidth]; // gridSquare = Resources.Load("Grid") as GameObject; storageStart = factoryHeight - storageRows; CreateGrid(); }
#pragma warning restore 0649 /// <summary> /// Makes actions with all the units in the EnemyUnits list /// </summary> public async Task MoveEnemyUnitsAsync(IEnumerable <Unit> enemyUnits, GridTile[,] tileGrid) { foreach (var enemy in enemyUnits) { await _unitSelector.ChangeSelectedUnitAsync(enemy, tileGrid); var randomTile = enemy.PathfindingData[Random.Range(0, enemy.PathfindingData.Count)].DestinationGridTile; MoveUnitToTile(randomTile, enemy); } }
public Grid(int height, int width, GameObject tilePrefab, Transform transform, Action <GameObject, int, int> Instatiator) { this.height = height; this.width = width; this.tilePrefab = tilePrefab; _action = Instatiator; _camera = Camera.main; grid = new GridTile[width, height]; }
private void Start() { grid = new GridTile[Width, Height]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { grid[x, y] = Instantiate(TilePrefab, new Vector3(x, 0, y), Quaternion.identity, gameObject.transform); } } }
// CONSTRUCTEUR : Fonction qui sert à déclarer un nouvel objet de type GridInfo (avec new GridInfo(...)) // - Et d'assigner les valeurs des variables, à l'aide des paramètres en appel (dans les parenthèses) public GridInfo(GridTile[,] gameGridTiles, Vector2Int gameGridSize, Bounds gameGridWorldBounds, float tileWidth, Sprite evenSprite, Sprite oddSprite) { this.gameGridTiles = gameGridTiles; this.gameGridSize = gameGridSize; this.tileCount = (int)gameGridSize.x * (int)gameGridSize.y; this.gameGridWorldBounds = gameGridWorldBounds; this.gameGridQuadrants = new GridQuadrants(gameGridWorldBounds); this.tileWidth = tileWidth; this.evenSprite = evenSprite; this.oddSprite = oddSprite; //Debug.Log("New grid with " + tileCount + " tiles"); }
private void GenerateLevel() { //Generate new Level level = new GridTile[xSize, ySize]; for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { GridTile _tile = Instantiate(tilePrefab, new Vector3(0 + x * xOffset, 0, 0 + y * yOffset), Quaternion.identity, this.transform); _tile.gameObject.name = "Tile: " + x + ", " + y; _tile.coordinates = new Vector2Int(x, y); level[x, y] = _tile; } } //Set up neighbours for (int x = 0; x < level.GetLength(0); x++) { for (int y = 0; y < level.GetLength(1); y++) { //north if (y < level.GetLength(1) - 1) { level[x, y].neighbourNorth = level[x, y + 1]; level[x, y].neighbours.Add(level[x, y + 1]); } //south if (y > 0) { level[x, y].neighbourSouth = level[x, y - 1]; level[x, y].neighbours.Add(level[x, y - 1]); } //east if (x < level.GetLength(0) - 1) { level[x, y].neighbourEast = level[x + 1, y]; level[x, y].neighbours.Add(level[x + 1, y]); } //west if (x > 0) { level[x, y].neighbourWest = level[x - 1, y]; level[x, y].neighbours.Add(level[x - 1, y]); } } } }
public GridRender(ulong id, string name, int width, int height, string defaultState, int tileSize = 64) { Grid = new GridTile[width, height]; for (int x = 0; x < Grid.GetLength(0); x++) { for (int y = 0; y < Grid.GetLength(1); y++) { Grid[x, y] = new GridTile(defaultState); } } Id = id; Name = name; TileSize = tileSize; }
// Start is called before the first frame update void Start() { grid = new GridTile[x_Length, z_Length]; for (int i = 0; i < x_Length; i++) { for (int j = 0; j < z_Length; j++) { gridTile.x_pos = i; gridTile.z_pos = j; grid[i, j] = Instantiate(gridTile, new Vector3(i, 0f, j), gridTile.transform.rotation); gridList.Add(gridTile); } } RandomSpawns(); }
// Fonction qui génère la grille d'entiers private void GenerateMapData() { // Assigner la grosseur des arrays2D _gameGrid = new int[mapSizeX, mapSizeY]; _gameGridTiles = new GridTile[mapSizeX, mapSizeY]; // Assigner la valeur "0" à chaque index du array for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeY; y++) { _gameGrid[x, y] = 0; } } }
//public List<TilePathfindingData> SelectedUnitPathfindingData { get; private set; } public async Task ChangeSelectedUnitAsync(Unit unitToSelect, GridTile[,] tileGrid) { //Clicked on an idle player unit if (unitToSelect.State != UnitState.Idle || SelectedUnit == unitToSelect) { return; } DeselectUnit(); SelectedUnit = unitToSelect; if (SelectedUnit.PathfindingData == null) { var unitPosition = SelectedUnit.transform.position; SelectedUnit.PathfindingData = await PathfindingHelper.CalculateUnitAvailablePathsAsync(unitPosition, tileGrid); } }
public void CreateGrid() { grid = new GridTile[x_Length, z_Length]; for (int i = 0; i < x_Length; i++) { for (int j = 0; j < z_Length; j++) { gridTile.x_pos = i; gridTile.z_pos = j; grid[i, j] = Instantiate(gridTile, new Vector3(i, 0.75f, j), gridTile.transform.rotation); gridList.Add(gridTile); } } path.StartSearch(startingPos, endingPos); }
public void InitGrid() { grid = new GridTile[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GridTile tile = Instantiate(tilePrefab); tile.Init(new Coord(x, y), transform); grid[x, y] = tile; } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GridTile tile = grid[x, y]; if (x > 0) { tile.neighbors.Add(Coord.left, grid[x - 1, y]); } if (x < width - 1) { tile.neighbors.Add(Coord.right, grid[x + 1, y]); } if (y > 0) { tile.neighbors.Add(Coord.down, grid[x, y - 1]); } if (y < height - 1) { tile.neighbors.Add(Coord.up, grid[x, y + 1]); } } } //temp for (int i = 0; i < 5; i++) { int x = UnityEngine.Random.Range(0, width); int y = UnityEngine.Random.Range(0, height); if (grid[x, y].gridObjects.Count == 0) { Plant plant = Instantiate(plantPrefab); plant.Init(grid[x, y], Services.breedManager.breeds[BreedManager.BreedType.BasicPlant]); } } }
public virtual void Init(Inventory inventory) { GetComponent <GridLayoutGroup>().constraintCount = inventory.Rows; grid = new T[inventory.Rows, inventory.Columns]; for (int i = 0; i < inventory.Rows; i++) { for (int j = 0; j < inventory.Columns; j++) { GridTile newInventorySlot = Instantiate(_slot, transform); grid[i, j] = newInventorySlot; newInventorySlot.SetGridPosition(new Vector2(i, j)); } } }
void CreateGridArray(int width, int depth) { gridArray = new GridTile[width, depth]; for (int x = 0; x < gridArray.GetLength(0); x++) { for (int z = 0; z < gridArray.GetLength(1); z++) { CreateTile(x, z, 0); } } CreateTile(5, 7, 3); CreateTile(6, 7, 3); CreateTile(7, 7, 3); CreateTile(5, 8, 3); //CombineMesh(gameObject); }
private void InitializeTiles() { if (gridTilePrefab != null) { gridTileArray = new GridTile[gridSize.x, gridSize.y]; for (int x = 0; x < gridSize.x; x++) { for (int y = 0; y < gridSize.y; y++) { GameObject tile = Instantiate(gridTilePrefab.gameObject); gridTileArray[x, y] = tile.GetComponent <GridTile>(); gridTileArray[x, y].Initialize(transform, new Vector2Int(x, y)); } } } }
/// <summary> /// Returns the tile the mouse is currently hovering over /// </summary> private GridTile DetectHoveredTile(GridTile[,] tileGrid, Vector3 screenPointRaySource) { var ray = _mainCamera.ScreenPointToRay(screenPointRaySource); var raycastHits = new RaycastHit[MaxRaycastHits]; Physics.RaycastNonAlloc(ray, raycastHits); var hitTileTransform = raycastHits.FirstOrDefault(x => !ReferenceEquals(x.transform, null) && x.transform.CompareTag("Tile")).transform; if (ReferenceEquals(hitTileTransform, null)) { return(null); } var position = hitTileTransform.position; return(tileGrid[(int)position.x, (int)position.y]); }
private void GenerateGrid(Texture2D map) { //Start with a clean array grid = new GridTile[levelToSpawn.width, levelToSpawn.height]; //Fill it with tile prefabs depending on color for (int x = 0; x < map.width; x++) { for (int y = 0; y < map.height; y++) { SpawnTile(x, y); } } //Set up neighbours for (int x = 0; x < grid.GetLength(0); x++) { for (int y = 0; y < grid.GetLength(1); y++) { //North if (y < grid.GetLength(1) - 1) { grid[x, y].neighbourN = grid[x, y + 1]; } //East if (x < grid.GetLength(0) - 1) { grid[x, y].neighbourE = grid[x + 1, y]; } //South if (y > 0) { grid[x, y].neighbourS = grid[x, y - 1]; } //West if (x > 0) { grid[x, y].neighbourW = grid[x - 1, y]; } } } }
public void SetTileColorsToDefault() { if (Input.GetMouseButtonUp(0)) { GridTile[,] gridTiles = GridManager.Instance.Grid; for (int x = 0; x < gridTiles.GetLength(0); x++) { for (int y = 0; y < gridTiles.GetLength(1); y++) { if (gridTiles[x, y].IsWalkable) { gridTiles[x, y].gameObject.GetComponent <MeshRenderer>().material.color = Color.white; } } } } }
void Start() { array = new GridTile[sizeX, sizeY]; foreach (Transform child in tileContainer.transform) { int childX, childY; childX = Mathf.RoundToInt(child.position.x); childY = Mathf.RoundToInt(child.position.y); if (childX <= sizeX && childY <= sizeY) { if (array[childX, childY] != null) { continue; } array[childX, childY] = child.GetComponent <GridTile>(); } } }
public override ulong CheckForWinner() { GridTile[,] Grid = GameGrid.GetGrid(); string winner = "free"; if (Grid[0, 0].State == Grid[1, 1].State && Grid[0, 0].State == Grid[2, 2].State) { winner = Grid[1, 1].State; } if (Grid[0, 2].State == Grid[1, 1].State && Grid[0, 2].State == Grid[2, 0].State) { winner = Grid[1, 1].State; } for (int x = 0; x < 3; x++) { if (Grid[x, 0].State == Grid[x, 1].State && Grid[x, 0].State == Grid[x, 2].State) { winner = Grid[x, 0].State; } } for (int y = 0; y < 3; y++) { if (Grid[0, y].State == Grid[1, y].State && Grid[0, y].State == Grid[2, y].State) { winner = Grid[0, y].State; } } ulong winningPlayer = 0L; if (winner == "cross") { winningPlayer = Players[0]; } else if (winner == "naughts") { winningPlayer = Players[1]; } return(winningPlayer); }
public PathNode(GridTile[,] grid, GridTile tile, int x, int y) { this.grid = grid; this.tile = tile; this.x = x; this.y = y; isTraversable = true; isSafe = true; if (tile.tileType == 1) { isTraversable = false; } if (tile.tileType == 4) { isSafe = false; } }
public GridManager(int width, int height, string gridImage) { gridHeight = height; gridWidth = width; gridTiles = new GridTile[width, height]; gridSprite = new CCSprite(gridImage); tile_width = gridSprite.ScaledContentSize.Width; tile_height = gridSprite.ScaledContentSize.Height; for (int cellY = 0; cellY < height; cellY++) { for (int cellX = 0; cellX < width; cellX++) { gridTiles[cellX, cellY] = new GridTile(gridImage, cellX, cellY); PlaceTile(gridTiles[cellX, cellY], new CCPoint(cellX, cellY)); } } }
private void ComputeGridSize(BoardData oldBoardData) { if (oldBoardData.X_SIZE % 2 == 0) { gridSize.x = 10; } else { gridSize.x = 11; } if (oldBoardData.Y_SIZE % 2 == 0) { gridSize.y = 10; } else { gridSize.y = 11; } tiles = new GridTile[gridSize.x, gridSize.y]; }
internal void Build( Int2D size ) { this.size = size; float tileSize = 1f; tiles = new GridTile[size.x, size.y]; for( short i=0; i<size.y; i++ ) { for( short j=0; j<size.x; j++ ) { tiles[j, i] = Instantiate( SampleTile, new Vector3( ( j - size.x / 2 ) * tileSize, 0, ( i - size.y ) * tileSize ), SampleTile.transform.rotation ) as GridTile; tiles[j, i].location = new Int2D( j, i ); tiles[j, i].transform.parent = transform; } } ResetTiles(); God.OnReady_Grid(); }
// Use this for initialization void Start() { TileArray = new GridTile[Length, Width]; CornerArray = new bool[Length + 1, Width + 1]; for (int x = 0; x < Length; x++) { for (int y = 0; y < Width; y++) { TileArray[x, y] = Instantiate(Tile, new Vector3(x * 10, 0, y * 10), Quaternion.identity); } } for (int x = 0; x < Length + 1; x++) { for (int y = 0; y < Width + 1; y++) { CornerArray[x, y] = true; } } }
public GridTiles ( int sizeX, int sizeY ) { _sizeX = sizeX; _sizeY = sizeY; walls = new byte[sizeX, sizeY]; tiles = new GridTile[sizeX, sizeY]; TileCoord tCoord; for ( int ix = 0; ix < _sizeX; ix++ ) for ( int iy = 0; iy < _sizeY; iy++ ) { tCoord = new TileCoord ( ix, iy ); tiles[ix, iy] = new GridTile ( tCoord ); } }