private Chunk makeDefaultChunk(int chunkXcoord, int chunkYcoord) { Floor.Type typeOfFloor = Floor.Type.Asphalt; Block.Type typeOfEdgeBlock = Block.Type.wCement; string typeOfFloorName = typeOfFloor.ToString(); string typeOfBlockName = Block.toStrings[typeOfEdgeBlock]; Chunk chunk = new GameObject().AddComponent <Chunk>(); chunk.name = "Default chunk " + chunkXcoord + ", " + chunkYcoord; chunk.chunkX = chunkXcoord; chunk.chunkY = chunkYcoord; chunk.width = chunkSize; chunk.height = chunkSize; chunk.init(); chunks.Add(new global::Point(chunkXcoord, chunkYcoord), chunk); for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { chunk.setFloor(x, y, typeOfFloor, typeOfFloorName); if (x == 0 || y == 0 || x == chunkSize - 1 || y == chunkSize - 1) { setBlock(chunkXcoord, chunkYcoord, x, y, typeOfEdgeBlock, false, typeOfBlockName); } } } return(chunk); }
private Chunk makeRandomBlocksChunk(int chunkXcoord, int chunkYcoord, float densityOfBlocks) { Floor.Type typeOfFloor = Floor.Type.Asphalt; string typeOfFloorName = typeOfFloor.ToString(); Chunk chunk = new GameObject().AddComponent <Chunk>(); chunk.name = "Random chunk " + chunkXcoord + ", " + chunkYcoord; chunk.chunkX = chunkXcoord; chunk.chunkY = chunkYcoord; chunk.width = chunkSize; chunk.height = chunkSize; chunk.init(); chunks.Add(new global::Point(chunkXcoord, chunkYcoord), chunk); for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { chunk.setFloor(x, y, typeOfFloor, typeOfFloorName); if (Random.Range(0f, 1f) < densityOfBlocks) { if (Random.Range(0f, 1f) < 0.5) { setBlock(chunkXcoord, chunkYcoord, x, y, Block.Type.wIce, false, "ice wall"); } else { setBlock(chunkXcoord, chunkYcoord, x, y, Block.Type.wFlesh, false, "flesh wall"); } } } } return(chunk); }
public void setFloor(int x, int y, Floor.Type floorType, string floorName = "???") { GameObject newFloor = new GameObject(); newFloor.name = floorName + " floor " + x + "," + y; newFloor.transform.SetParent(floorsObject.transform); //FYI, always setParent before changing localPosition! newFloor.transform.localPosition = new Vector3(x, y); Floor floorscript = newFloor.AddComponent <Floor>(); floorscript.type = floorType; floorscript.init(); if (floors[x, y] != null) { Destroy(floors[x, y].gameObject); } floors[x, y] = floorscript; }