public RMGRiverNode(RMGRiverNode parent, float dir, bool doubleSplit) { this.parent = parent; this.river = parent.river; this.river.nodeCount += 1; this.facing = parent.facing + (Funcs.Random(0.01f, Mathf.PI / 4) * dir); this.facing = Mathf.Clamp(this.facing, this.river.minAngle, this.river.maxAngle); this.deathChance = parent.deathChance * Funcs.Random(0.99f, 1.01f); this.splitChance = parent.splitChance * Funcs.Random(0.99f, 1.01f); this.narrowChance = parent.narrowChance * Funcs.Random(0.99f, 1.01f); this.widenChance = parent.widenChance * Funcs.Random(0.99f, 1.01f); this.w = parent.w; if (Funcs.fChance(narrowChance)) { this.w -= 1; } else if (Funcs.fChance(widenChance)) { this.w += 0.5f; } if (doubleSplit) { this.w -= 1; deathChance += 0.01f; splitChance -= 0.1f; } Vector2 p = new Vector2(parent.x, parent.y); Vector2 pa = Funcs.RadianToVector2(this.facing); pa *= 3; p += pa; this.x = p.x; this.y = p.y; }
public void Update() { iterations += 1; int countAtStart = nodeCount; if (start == null) { start = new RMGRiverNode(this, this.facing, this.x, this.y); return; } else { start.Update(); } if (countAtStart == nodeCount) { noChangeCount -= 1; } if (noChangeCount <= 0) { finished = true; } }
public void Update() { if (!alive) { return; } if (this.w <= 0) { alive = false; Debug.Log("too narrow"); } if (x < 0 || x > river.w || y < 0 || y > river.h) { alive = false; } if (childLeft == null && childRight == null) { if (Funcs.fChance(deathChance)) { //alive = false; } else { if (Funcs.fChance()) { childLeft = new RMGRiverNode(this, -1, false); canHaveLeft = false; river.leftChildren += 1; } else { childRight = new RMGRiverNode(this, 1, false); canHaveRight = false; river.rightChildren += 1; } } return; } if (river.splits >= river.maxSplits) { canHaveLeft = canHaveRight = false; } if (childLeft != null) { childLeft.Update(); if (canHaveRight) { canHaveRight = false; if (Funcs.fChance(splitChance)) { childRight = new RMGRiverNode(this, 1, true); river.splits += 1; river.rightChildren += 1; return; } else { } } } if (childRight != null) { childRight.Update(); if (canHaveLeft) { canHaveLeft = false; if (Funcs.fChance(splitChance)) { childLeft = new RMGRiverNode(this, -1, true); river.splits += 1; canHaveLeft = false; river.leftChildren += 1; return; } } } }