コード例 #1
0
    private void FinishCommand()
    {
        HeroCommand cmd = this.currentCommand;

        if (cmd.stillValid())
        {
            this.floatingTime = (cmd.finish.y > cmd.start.y) ? 0 : (Mathf.PI / this.floatingFreq);

            this.eqPos = cmd.finish;
            this.transform.position = this.eqPos;

            if (cmd.stillValid())
            {
                cmd.complete(this);
            }
        }

        bool startingNewCommand = false;

        while (this.commandQ.Count > 0)
        {
            HeroCommand nextCommand = this.commandQ.Dequeue();
            if (nextCommand.stillValid())
            {
                this.BeginCommand(nextCommand);
                startingNewCommand = true;
                break;
            }
        }
        if (!startingNewCommand)
        {
            this.state          = HeroState.FLOATING;
            this.currentCommand = null;
        }
    }
コード例 #2
0
    private void BeginCommand(HeroCommand cmd)
    {
        cmd.start = transform.position;

        this.currentScale = this.transform.localScale.x;

        if (cmd.start.x < cmd.finish.x)
        {
            // Moving right
            this.destScale = 1f;
        }
        else if (cmd.start.x > cmd.finish.x)
        {
            // Moving left
            this.destScale = -1f;
        }
        this.turning = (this.destScale != this.currentScale);

        this.totalMoveTime   = this.FlightTime(cmd.start, cmd.finish);
        this.currentMoveTime = 0f;
        this.state           = HeroState.FLYING;
        this.currentCommand  = cmd;

        cmd.PreComplete(this.totalMoveTime, this);
    }
コード例 #3
0
    private void SetFlyingTransform()
    {
        HeroCommand cmd = this.currentCommand;

        // What portion of the way are we through our flight command?
        float t = (this.totalMoveTime == 0f) ? 1f : this.currentMoveTime / this.totalMoveTime;

        // "Smootherstep"
        // https://chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/
        t = t * t * t * (t * (6f * t - 15f) + 10f);

        this.transform.position = Vector2.Lerp(cmd.start, cmd.finish, t);
        this.UpdateScale();
    }
コード例 #4
0
    private void FinishCommand()
    {
        HeroCommand cmd = this.currentCommand;
        if (cmd.stillValid ()) {
            this.floatingTime = (cmd.finish.y > cmd.start.y) ? 0 : (Mathf.PI / this.floatingFreq);

            this.eqPos = cmd.finish;
            this.transform.position = this.eqPos;

            if (cmd.stillValid ())
                cmd.complete (this);
        }

        bool startingNewCommand = false;

        while (this.commandQ.Count > 0) {
            HeroCommand nextCommand = this.commandQ.Dequeue();
            if (nextCommand.stillValid()) {
                this.BeginCommand(nextCommand);
                startingNewCommand = true;
                break;
            }
        }
        if (!startingNewCommand) {
            this.state = HeroState.FLOATING;
            this.currentCommand = null;
        }
    }
コード例 #5
0
    private void BeginCommand(HeroCommand cmd)
    {
        cmd.start = transform.position;

        this.currentScale = this.transform.localScale.x;

        if (cmd.start.x < cmd.finish.x) {
            // Moving right
            this.destScale = 1f;
        } else if (cmd.start.x > cmd.finish.x) {
            // Moving left
            this.destScale = -1f;
        }
        this.turning = (this.destScale != this.currentScale);

        this.totalMoveTime = this.FlightTime(cmd.start, cmd.finish);
        this.currentMoveTime = 0f;
        this.state = HeroState.FLYING;
        this.currentCommand = cmd;

        cmd.PreComplete (this.totalMoveTime, this);
    }