コード例 #1
0
    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;
    }
コード例 #2
0
ファイル: NodeBlock.cs プロジェクト: makscee/prototype-1
 public void StepNumberChangeNotify()
 {
     foreach (var bind in BindMatrix.GetAllAdjacentBinds(this))
     {
         if (bind.First == this && bind.Second is NodeBlock nodeBlock)
         {
             nodeBlock._stepNumberDirty = true;
         }
     }
 }
コード例 #3
0
ファイル: NodeBlock.cs プロジェクト: makscee/prototype-1
    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);
    }
コード例 #4
0
ファイル: BlockPhysics.cs プロジェクト: makscee/prototype-1
    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;
    }
コード例 #5
0
ファイル: NodeBlock.cs プロジェクト: makscee/prototype-1
 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;
         }
     }
 }
コード例 #6
0
    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);
                }
            }
        }
    }
コード例 #7
0
ファイル: NodeBlock.cs プロジェクト: makscee/prototype-1
    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();
    }