/// <summary> ///Adds a chunk at the given coordinates and expands the map /// </summary> /// <param name="node"> ///The chunk you wish to add to the map /// </param> /// <param name="x"> ///The x target coordinate /// </param> /// <param name="y"> ///The y target coordinate /// </param> public void AddNodeAt(ChunkSet node, int x, int y) { node.SetCoordinates(x,y); if(x < 0){ //Debug.Log("ABS X: " + x); //expand and shuffle by Mathf.Abs(x) ExpandWidth(currentWidth + Mathf.Abs(x)); ShuffleMap(Mathf.Abs(x),0); node.SetCoordinates(0,node.GetY()); } else if(x >= currentWidth){ //we just need to expand out by x - (currentWidth - 1), no need to shuffle if(currentWidth == 0){ ExpandWidth(x+1); } else{ ExpandWidth(x+1); } } if(y < 0){ //Debug.Log("ABS Y: " + x); //expand and shuffle by Mathf.Abs(y) ExpandHeight(currentHeight + Mathf.Abs(y)); ShuffleMap(0,Mathf.Abs(y)); node.SetCoordinates(node.GetX(),0); } else if(y >= currentHeight){ //we just need to expand up by y - (currentHeight - 1), no need to shuffle ExpandHeight(y+1); } SetNodeAt(node,node.GetX(),node.GetY()); }
void SetNodeAt(ChunkSet node, int x, int y){ int index = y * currentWidth + x; map[index] = node; node.SetCoordinates(x,y); }