protected virtual void Update() { if (!Movable) { return; } var maxSpeedChange = MaxAcceleration * Time.deltaTime; foreach (var bind in BindMatrix.GetAllAdjacentBinds(this)) { var v = bind.GetTarget(this) - GetPosition(); var f = v * (bind.Strength * Bind.StrengthMultiplier); DesiredVelocity += f; } if (!IsAnchored) { const float radius = 0.1f; const float speed = 1f; var t = Time.time; DesiredVelocity += new Vector2(Mathf.Cos(t * speed) * radius, Mathf.Sin(t * speed) * radius); } Velocity = Vector2.MoveTowards(Velocity, DesiredVelocity, maxSpeedChange); transform.position += (Vector3)Velocity * (Time.deltaTime); DesiredVelocity = Vector2.zero; }
public void StepNumberChangeNotify() { foreach (var bind in BindMatrix.GetAllAdjacentBinds(this)) { if (bind.First == this && bind.Second is NodeBlock nodeBlock) { nodeBlock._stepNumberDirty = true; } } }
bool CheckAlone() { var result = true; foreach (var adjacentBind in BindMatrix.GetAllAdjacentBinds(this)) { if (adjacentBind.First is Block && adjacentBind.First != this || adjacentBind.Second is Block && adjacentBind.Second != this) { result = false; break; } } return(result); }
void Update() { var maxSpeedChange = MaxAcceleration * Time.deltaTime; // _velocity = Vector2.ClampMagnitude(parent.logic.Position - Position, 50f); var bindStrengthDivisor = 1f / BindMatrix.GetBindsCount(parent); foreach (var bind in BindMatrix.GetAllAdjacentBinds(parent)) { var v = bind.GetTarget(parent) - Position; var f = v * (bind.Strength * bindStrengthDivisor * Bind.StrengthMultiplier); _desiredVelocity += f; } _velocity = Vector2.MoveTowards(_velocity, _desiredVelocity, maxSpeedChange); parent.transform.position += (Vector3)_velocity * Time.deltaTime; _desiredVelocity = Vector2.zero; }
void UpdateDirs() { if (!DeadEnd) { for (var i = 0; i < 4; i++) { dirs[i] = false; } return; } foreach (var bind in BindMatrix.GetAllAdjacentBinds(this)) { if (bind.First is Block block && bind.Second == this) { dirs[Utils.DirFromCoords(logic.Position - block.logic.Position)] = true; } } }
public void PulseConnectionUpdate() { pulseVersionDirty = false; pulseVersion++; var queue = new Queue <Block>(); queue.Enqueue(this); while (queue.Count > 0) { var next = queue.Dequeue(); next.pulseVersion = pulseVersion; foreach (var bind in BindMatrix.GetAllAdjacentBinds(next)) { if (bind.First == next && bind.Second is Block block && block.pulseVersion != pulseVersion && block.rootId == rootId) { queue.Enqueue(block); } } } }
public void RefreshStepNumber() { var t = int.MaxValue / 2; if (PulseConnected) { foreach (var bind in BindMatrix.GetAllAdjacentBinds(this)) { if (bind.Second == this && bind.First is Block block) { t = Math.Min(t, block.logic.stepNumber + 1); } } } if (t == logic.stepNumber) { return; } logic.stepNumber = t; view.SetText(logic.stepNumber.ToString()); StepNumberChangeNotify(); }