void WaterSim2() { /* Grid = new Cell[3, 3] { { new Cell(TileType.Air, 0), new Cell(TileType.Air, 0), new Cell(TileType.Air, 0), }, { new Cell(TileType.Air, 7), new Cell(TileType.Air, 0), new Cell(TileType.Air, 0), }, { new Cell(TileType.Air, 0), new Cell(TileType.Air, 0), new Cell(TileType.Air, 0), }, };*/ //Width = 3; //Height = 3; //Width = 64; //Height = 64; Grid = new Cell[Width, Height]; currentCellY = Height - 1; //Random r = new Random(); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { // if (y < 3) // { // //Grid[x, y] = new Cell(TileType.Air, r.Next(0, Cell.MaxLevel)); // Grid[x, y] = new Cell(TileType.Air, 0); //Grid[x, y] = new Cell(TileType.Air, Random.Range(0, Cell.MaxLevel)); // } // else // { //if (r.Next(100) > 5) Grid[x, y] = new Cell(TileType.Air, 0); //else //Grid[x, y] = new Cell(TileType.Dirt, 0); // } } } }
// mainloop void Update() { xUpdate(); DebugRender(); if (Input.GetKeyDown("1")) { renderer.material.mainTexture.filterMode = FilterMode.Point; } if (Input.GetKeyDown("2")) { renderer.material.mainTexture.filterMode = FilterMode.Bilinear; } if (Input.GetKeyDown("3")) { renderer.material.mainTexture.filterMode = FilterMode.Trilinear; } if (Input.GetMouseButton(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100)) { Debug.DrawLine(ray.origin, hit.point,Color.yellow,10); float hx = Width-(hit.point.x*Width/10); float hy = Height-(hit.point.z*Height/10); //Debug.Log(hx+","+hy); Grid[(int)hx,(int)hy] = new Cell(TileType.Dirt, (byte)Cell.MaxLevel); } } if (Input.GetMouseButton(1)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100)) { Debug.DrawLine(ray.origin, hit.point,Color.yellow,10); float hx = Width-(hit.point.x*Width/10); float hy = Height-(hit.point.z*Height/10); //Debug.Log(hx+","+hy); //Grid[(int)hx,(int)hy] = new Cell(TileType.Air, (byte)Cell.MaxLevel); // Grid[(int)hx+1,(int)hy].Level = (byte)Cell.MaxLevel; // Grid[(int)hx,(int)hy-1].Level = (byte)Cell.MaxLevel; Grid[(int)hx,(int)hy].Level = (byte)Cell.MaxLevel; // Grid[(int)hx,(int)hy+1].Level = (byte)Cell.MaxLevel; // Grid[(int)hx-1,(int)hy].Level = (byte)Cell.MaxLevel; //Grid[(int)hx,(int)hy] = new Cell(TileType.Air, (byte)Cell.MaxLevel); } } }
private void FlowRight(ref Cell cell, ref Cell rightCell) { int amountToSpread = (rightCell.Level + cell.Level) / 2; int remainder = (rightCell.Level + cell.Level) % 2; rightCell.Level = amountToSpread + remainder; rightCell.NoCalc = true; rightCell.Direction = Direction.Right; cell.Level = amountToSpread; cell.NoCalc = true; }
private void FlowLeftRight(ref Cell cell, ref Cell leftCell, ref Cell rightCell) { int amountToSpread = (leftCell.Level + rightCell.Level + cell.Level) / 3; int remainder = (leftCell.Level + rightCell.Level + cell.Level) % 3; // if we have a remainder... if (remainder > 0) { // if (cell.Direction == Direction.Left) { leftCell.Level = amountToSpread + remainder; leftCell.Direction = Direction.Left; rightCell.Level = amountToSpread; } else { leftCell.Level = amountToSpread; rightCell.Level = amountToSpread + remainder; rightCell.Direction = Direction.Right; } } else { // otherwise it's an even split leftCell.Level = amountToSpread; leftCell.Direction = Direction.None; rightCell.Level = amountToSpread; rightCell.Direction = Direction.None; } cell.Level = amountToSpread; cell.NoCalc = true; cell.Direction = Direction.None; leftCell.NoCalc = true; rightCell.NoCalc = true; }
private void FlowLeft(ref Cell cell, ref Cell leftCell) { int amountToSpread = (leftCell.Level + cell.Level) / 2; int remainder = (leftCell.Level + cell.Level) % 2; leftCell.Level = amountToSpread + remainder; leftCell.NoCalc = true; leftCell.Direction = Direction.Left; cell.Level = amountToSpread; cell.NoCalc = true; }
private int FlowBottom(ref Cell cell, ref Cell bottomCell) { // check to see how much fluid can fall down var spaceAvailable = Cell.MaxLevel - bottomCell.Level; //var amountToMove = (int)MathHelper.Min(spaceAvailable, cell.Level); var amountToMove = (int)Mathf.Min(spaceAvailable, cell.Level); // move all fluid that can be moved bottomCell.Level += amountToMove; bottomCell.NoCalc = true; bottomCell.Direction = Direction.None; cell.Level -= amountToMove; cell.NoCalc = true; return cell.Level; }