// destroy all objects in a particular area public int destroyArea(clsPoint topLeft, clsPoint bottomRight, int containerId = 0) { // initiate destruction method for each object int result = 0; clsObject obj = new clsObject(_db); result += obj.destroyArea((int)topLeft.x, (int)topLeft.y, (int)bottomRight.x, (int)bottomRight.y, containerId); return result; }
// all vectors start from 0,0 public void setVector(clsPoint from, clsPoint to) { _vector = new clsPoint(to.x - from.x, to.y - from.y, to.z - from.z); }
public clsVector(clsPoint from, clsPoint to) { setVector(from, to); }
public string SaveMap(clsPoint worldLocation) { int size = heights.GetLength(0); // clear block clsPoint worldLocationBotRight = new clsPoint(worldLocation.x + heights.Length - 1, worldLocation.y + heights.Length - 1); this.destroyArea(worldLocation, worldLocationBotRight); // load templates clsTemplate template = new clsTemplate(_db); List<clsTemplate> templates = template.getAllTemplates(); int waterLevel = 0; // save results to database clsObject obj = new clsObject(_db); List<clsObject> results = new List<clsObject>(); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { obj = this.createObject((int)worldLocation.x + x, (int)worldLocation.y + y, heights[x, y] * 32, templates.Find(i => i.name.Contains("MC Grass"))); if (heights[x, y] < waterLevel) { for (int z = heights[x, y] + 1; z <= waterLevel; z++) { obj = this.createObject((int)worldLocation.x + x, (int)worldLocation.y + y, z * 32, templates.Find(i => i.name.Contains("MC Water"))); } } } } // height map to JSON string JSON; JSON = "{"; JSON = "\"objectsCreated\":" + results.Count + ""; JSON += "}"; return JSON; }
public int getSeed(clsPoint worldLocation) { int maxRandomHeight = 6; return r.Next(0, maxRandomHeight); }
public string createBlock(clsPoint block) { int size = heights.GetLength(0); // clear the height array for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { heights[x, y] = 0; } } int blockSize = size; clsPoint arrayMax = new clsPoint(blockSize - 1, blockSize - 1); clsPoint worldTopLeft = new clsPoint(block.x * blockSize, block.y * blockSize); clsPoint worldBotRight = new clsPoint(worldTopLeft.x + blockSize - 1, worldTopLeft.y + blockSize - 1); // seed the corners heights[0, 0] = getSeed(worldTopLeft); heights[blockSize - 1, 0] = getSeed(new clsPoint(worldBotRight.x, worldTopLeft.y)); heights[0, blockSize - 1] = getSeed(new clsPoint(worldTopLeft.x, worldBotRight.y)); heights[blockSize - 1, blockSize - 1] = getSeed(worldBotRight); // mid point displacement loop // http://minecraft.gamepedia.com/ calculateMidPoints(size); return SaveMap(worldTopLeft); }