Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        float diff = Vector3.Distance(transform.position, pos);

        if (!word.empty())
        {
            if (diff < 0.001f)
            {
                updatePosition();
                transform.position = Vector3.MoveTowards(transform.position, pos, step);
            }
            else
            {
                transform.position = Vector3.MoveTowards(transform.position, pos, step);
            }
        }
        else
        {
            setUp();
        }
    }
    private void updatePosition()
    {
        RenderCommand rc         = RenderCommand.NONE;
        bool          updatedPos = false;

        while (!(word.empty()) && !updatedPos)
        {
            rc = word.dequeue();
            switch (rc)
            {
            case RenderCommand.FORWARD:
            case RenderCommand.FORWARD2:
                float x;
                float y;

                double theta = Math.Atan2(pos.y, pos.x);
                x = (float)(forward * Math.Cos(theta));
                y = (float)(forward * Math.Sin(theta));

                //Debug.Log("THETA: X: " + x + " Y: " + y);

                double r = Math.Sqrt(x * x + y * y);
                x = (float)(r * Math.Cos(startHeading));
                y = (float)(r * Math.Sin(startHeading));
                //Debug.Log("R: X: " + x + " Y: " + y);

                pos.x += x;
                pos.y += y;

                updatedPos = true;
                break;

            case RenderCommand.RIGHT:
                startHeading += (turn * Math.PI / 180.0);
                break;

            case RenderCommand.LEFT:
                startHeading += (-turn * Math.PI / 180.0);
                break;

            case RenderCommand.PUSH:
            case RenderCommand.POP:
            case RenderCommand.IGNORE:
            default:
                break;
            }

            word.enqueue(rc);
        }
    }