public void GenerateChunk(int xStart, int yStart, Chunk chunk) { Tilemap tilemap = chunk.ChunkTilemap; chunk.transform.position = new Vector3(xStart, yStart, 0); for (int x = 0; x < ChunkSize; x++) { for (int y = 0; y < ChunkSize; y++) { DestructibleTile toSet = null; int baseOre = 0; float perlin = MainPerlin.GetPerlin(x + xStart, y + yStart); float solidThreshold = SolidThresholdPerlin.GetPerlin(x + xStart, y + yStart); //if we're generating a solid tile: if (perlin > solidThreshold) { //check whether it should be explosive if (ShouldBeExplosive(x + xStart, y + yStart)) { toSet = ExplosiveTiles[0]; //tilemap.SetTile(new Vector3Int(x, y, 0), newTile); } else { //determine how much ore the tile should have float normOre = Mathf.InverseLerp(solidThreshold, 1, perlin); normOre = Mathf.InverseLerp(.5f, 1, normOre); int oreAmount = Mathf.FloorToInt(normOre / (1.0f / OreTiles.Length)); oreAmount = Mathf.Clamp(oreAmount, 0, OreTiles.Length); baseOre = oreAmount; //set the tile to the normal tile thing toSet = TerrainTiles[0]; //tilemap.SetTile(new Vector3Int(x, y, 0), newTile); } } else { //tilemap.SetTile(new Vector3Int(x, y, 0), null); //chunk.ForegroundTilemap.SetTile(new Vector3Int(x, y, 0), null); //chunk.OreAmount[x, y] = 0; } chunk.SetTile(x, y, toSet, baseOre); } } chunk.ApplyTiles(); chunk.Caverns = Cavern.GetChunkCaverns(chunk, chunk.MinCavernSize); if (chunk.Caverns.Count > 0) { chunk.BiggestCavern = chunk.Caverns.Aggregate((i1, i2) => i1.AirTiles.Count > i2.AirTiles.Count ? i1 : i2); } else { chunk.BiggestCavern = null; } GenerateLevelFeatures(chunk); }
public void SetTile(int x, int y, DestructibleTile tile, int oreSqrRt) { int index = (y * ChunkSize) + x; _tiles[index] = (tile as TileBase); //set ore stuff TileBase oreTile = null; if (tile != null) { //print(oreSqrRt); if (oreSqrRt != 0) { oreTile = tile.OreForegroundTiles[oreSqrRt - 1]; } HealthAmount[x, y] = tile.StartingHealth; } else { HealthAmount[x, y] = 0; } ForegroundTilemap.SetTile(_tilePositions[index], oreTile); if (oreSqrRt == 0) { OreAmount[x, y] = 0; } else { OreAmount[x, y] = (int)Mathf.Pow(2, oreSqrRt); } }
public void TryDestroyTileAt(Vector3Int target, int ore = 0, BulletProperties props = null, bool shouldExplode = false) { Vector3 tileCenter = CellToTileCenter(target); TileBase tile = TargetTilemap.GetTile(target); DestructibleTile dTile = tile as DestructibleTile; if (dTile != null) { if (dTile.Destructible) { if (dTile.DestroyEffect != null) { GameObject effect = Instantiate(dTile.DestroyEffect); effect.transform.position = tileCenter; } bool tileExplodes = dTile.Explodes; float radius = dTile.ExplodeRadius; if (props != null) { //if this is an explosive tile, use the explosive multiplier if (tileExplodes) { radius *= props.ExplosiveMultiplier; } //otherwise, if this is an explosive bullet... else if (shouldExplode) { tileExplodes = true; radius = props.ExplodeRadius; } } TargetTilemap.SetTile(target, null); if (ore > 0) { for (int i = 0; i < ore; i++) { OreParticle newOre = Instantiate(OrePrefab); newOre.transform.position = tileCenter; newOre.Target = PlayerObject; } } if (tileExplodes) { DoExplosion(target, radius); } } } }
public void Start() { tileMap = GetComponent <Tilemap>(); grid = GetComponentInParent <GridLayout>(); foreach (Vector3Int position in tileMap.cellBounds.allPositionsWithin) { TileBase t = tileMap.GetTile(position); if (!Equals(t, null)) { if (t is DestructibleTile) { DestructibleTile dt = Instantiate(t) as DestructibleTile; dt.StartUp(position, dt.tileMap, dt.gameObject); tileMap.SetTile(position, dt); } } } }
public DestructibleTile GetItem() { switch (Type) { case DestructibleType.MiningBlock: thisItem = new MiningWall(Audio, Clips); break; case DestructibleType.Tree: thisItem = new MushroomTree(Audio, Clips); break; case DestructibleType.HugeCrystal: thisItem = new HugeCrystal(Audio, Clips); break; case DestructibleType.SimpleCrystal: thisItem = new SimpleCrystal(Audio, Clips); break; } return thisItem; }
public DestructibleTile GetItem() { switch (Type) { case DestructibleType.MiningBlock: thisItem = new MiningWall(Audio, Clips); break; case DestructibleType.Tree: thisItem = new MushroomTree(Audio, Clips); break; case DestructibleType.HugeCrystal: thisItem = new HugeCrystal(Audio, Clips); break; case DestructibleType.SimpleCrystal: thisItem = new SimpleCrystal(Audio, Clips); break; } return(thisItem); }