コード例 #1
0
    public void UpdateLeg()
    {
        stepSpeed = parent.GetSpeed();

        double angle = parent.GetDirection()
                       + legOffset * (orientation ? 1 : -1);

        Vector3 targetPos = new Vector3(parent.GetX() + (float)Lib.CosX(length, angle),
                                        parent.GetY() + (float)Lib.SinY(length, angle),
                                        parent.GetZ());

        if (stepping)
        {
            position.x += (float)((position.x > targetPos.x) ? -stepSpeed : stepSpeed);
            position.y += (float)((position.y > targetPos.y) ? -stepSpeed : stepSpeed);

            if (Lib.GetDist(position.x, position.y, targetPos.x, targetPos.y) < stepSpeed)
            {
                ToggleStepping();
            }
        }
        else
        {
            if (Lib.GetDist(position.x, position.y, targetPos.x, targetPos.y) > length)
            {
                ToggleStepping();
            }
            else if (Lib.GetDist(parent.GetX(), parent.GetY(), position.x, position.y) < lastDist)
            {
                parent.Push(length / 5 * (orientation ? 1:-1));
            }
        }

        lastDist = Lib.GetDist(parent.GetX(), parent.GetY(), position.x, position.y);

        if (parent.GetState() == 1)
        {
            VectorFactory.DrawCircle(position, thickness, Color.yellow);
        }
    }
コード例 #2
0
ファイル: Body.cs プロジェクト: zaineashe/salamander
    public void UpdateBody()
    {
        size = baseSize + breathing;

        if ((inOut == true && breathing > 0.2) || (inOut == false && breathing <= 0.1))
        {
            inOut = !inOut;
        }

        if (master.GetSpeed() < 0.1)
        {
            breathing += ((inOut ? 0.3 : 0) - breathing) / 20;
        }
        else
        {
            inOut = false;
        }


        float targetX = position.x;
        float targetY = position.y;

        if (parent == null)
        {
            if (Lib.GetDist(position.x, position.y, master.transform.position.x, master.transform.position.y) > size * 2)
            {
                targetX = master.transform.position.x + (float)Lib.CosX(0.1, master.GetDirection() + 180);
                targetY = master.transform.position.y + (float)Lib.SinY(0.1, master.GetDirection() + 180);
            }

            direction = master.GetDirection();
        }
        else
        {
            PointTo(parent.GetX(), parent.GetY());

            if (Lib.GetDist(position.x, position.y, parent.GetX(), parent.GetY()) > size * 2)
            {
                targetX = parent.GetX() + (float)Lib.CosX(size * 2, parent.GetDirection() + 180);
                targetY = parent.GetY() + (float)Lib.SinY(size * 2, parent.GetDirection() + 180);
            }
        }


        position.x += (float)((targetX - position.x) / 3.0);
        position.y += (float)((targetY - position.y) / 3.0);

        speedFactor = Math.Abs((((targetX - position.x) / 3.0) + (((targetY - position.y) / 3.0))) / 2) * 10;
        if (speedFactor < 0.8)
        {
            speedFactor = 0.8;
        }

        if (legs != null)
        {
            for (int i = 0; i < legs.Count; i++)
            {
                Leg leg = (Leg)legs[i];
                leg.UpdateLeg();
            }
        }

        if (master.GetState() == 0)
        {
            VectorFactory.DrawCircle(position, size, Color.white);
        }
    }