public void SetWidth(int width) { container.Columns = width; // add more if (this.width < width) { for (int i = this.width * height; i < width * height; i++) { ColorRect rect = new ColorRect(); rect.SetFrameColor(wallColour); rect.SetCustomMinimumSize(blockSize); container.AddChild(rect); map.Add(false); } } // remove more else { for (int i = width * height; i < this.width * height; i++) { container.GetChild(i).QueueFree(); } map.RemoveRange(width * height, height * (this.width - width)); } this.width = width; }
// Called when the node enters the scene tree for the first time. public override void _Ready() { width = 79; height = 45; map = new List <bool>(); timer = new Timer(); AddChild(timer); AddUserSignal("finished"); AddUserSignal("finished_generating"); AddUserSignal("finished_pathfinding", new Godot.Collections.Array { this, new Godot.Collections.Array <int> (), new Godot.Collections.Array <int>() }); container = GetNode("GridContainer") as GridContainer; container.SetColumns(width); for (int i = 0; i < width * height; i++) { ColorRect rect = new ColorRect(); rect.SetFrameColor(wallColour); rect.SetCustomMinimumSize(blockSize); container.AddChild(rect); map.Add(false); } ResizeBlock(); }
public void SetHeight(int height) { // add more if (this.height < height) { for (int i = width * this.height; i < width * height; i++) { ColorRect rect = new ColorRect(); rect.SetFrameColor(wallColour); rect.SetCustomMinimumSize(blockSize); container.AddChild(rect); map.Add(false); } } // remove more else { for (int i = width * height; i < width * this.height; i++) { container.GetChild(i).QueueFree(); } map.RemoveRange(width * height, (this.height - height) * width); } this.height = height; }
public void ResizeBlock() { int hsep = (int)container.Get("custom_constants/hseparation"); int vsep = (int)container.Get("custom_constants/vseparation"); // assuming heps are always the same for now, since it has to be a square if (hsep == 0) { blockSize.x = this.GetSize().x / width; blockSize.y = this.GetSize().y / height; } else { blockSize.x = (this.GetSize().x) / width - hsep; blockSize.y = (this.GetSize().y) / height - vsep; } for (int i = 0; i < width * height; i++) { ColorRect rect = container.GetChild(i) as ColorRect; rect.SetCustomMinimumSize(blockSize); } }