public void BuildCity() { foreach (var col in city) { for (int y = 0; y < col.Length; y++) { Destroy(col[y].gameObject); } } city.Clear(); float lastGround = height / 2f; float ground; for (int x = 0; x < width; x++) { var cc = new CityCube[height]; city.Add(cc); do { ground = Random.Range(height / 3f, 2 * height / 3f); } while (Mathf.Abs(ground - lastGround) < height / 7f); lastGround = ground; level[x] = (byte)Mathf.FloorToInt(ground); for (int y = 0; y < height; y++) { var cube = Instantiate(cubePrefab); cube.transform.parent = transform; cube.transform.localPosition = ll + new Vector3(x, y); cube.x = x; cube.y = y; cc[y] = cube; cube.SetState(ground < y, true); if (!flipData) { cube.changed = true; } } } myScore = 0; otherScore = 0; me.position = Vector3.up * 7; me.velocity = Vector3.zero; other.position = Vector3.down * 7; other.velocity = Vector3.zero; }
public void BuildCity() { foreach (var col in city) { for (int y = 0; y < col.Length; y++) { Destroy(col[y].gameObject); } } city.Clear(); float lastGround = height / 2f; float ground; for (int x = 0; x < width; x++) { var cc = new CityCube[height]; city.Add(cc); do { ground = Random.Range(height / 3f, 2 * height / 3f); } while (Mathf.Abs(ground - lastGround) < height / 7f); lastGround = ground; level[x] = (byte)Mathf.FloorToInt(ground); for (int y = 0; y < height; y++) { var cube = Instantiate(cubePrefab); cube.transform.parent = transform; cube.transform.localPosition = ll + new Vector3(x, y); cube.x = x; cube.y = y; cc[y] = cube; cube.SetState(ground < y, true); if (!flipData) cube.changed = true; } } myScore = 0; otherScore = 0; me.position = Vector3.up * 7; me.velocity = Vector3.zero; other.position = Vector3.down * 7; other.velocity = Vector3.zero; }
private bool DestroyBlock(CityCube[] col, int y, int power, bool upper) { if (power <= 0) return false; if (y < 0 || y >= height) return true; var cc = col[y]; if (cc.isUpper != upper) return true; if (cc.hp == 2) { cc.hp = 1; cc.UpdateGfx(); DestroyBlock(col, y + (upper ? -1 : 1), power - 1, upper); return false; } if (cc.hp == 1) { if (DestroyBlock(col, y + (upper ? -1 : 1), power, upper)) { cc.SetState(!upper); return true; } return false; } cc.SetState(!upper); return true; }