示例#1
0
    // Update is called once per frame
    public void FixedUpdate()
    {
        float mx = Input.GetAxis("Horizontal");
        float my = Input.GetAxis("Vertical");

        if (mx > 0)
        {
            dirx = 1;
        }
        else if (mx < 0)
        {
            dirx = -1;
        }

        if (ManualMode()) // Manuel
        {
            if (leftPressed)
            {
                mx = -1;
            }
            if (rightPressed)
            {
                mx = 1;
            }
            if (jumpPressed)
            {
                my = 1; mx = dirx;
            }
            //Debug.Log("mx " + mx+ " right "+rightPressed);
            if ((mx != 0 || my != 0) && ConsumeMovement(GameSettings.MovementBase * Time.deltaTime * GameSettings.AutoManualRatio))
            {
                rigidbody.AddForce(new Vector2(mx * speedX, my * speedY));
            }
            else
            {
                //Debug.Log("Can't move");
            }
            if (Input.GetKeyDown(KeyCode.K))
            {
                ActionForrer();
            }
        }
        else
        {
            elapsed += Time.deltaTime;
            if (mode == Mode.moving)
            {
                float vel = rigidbody.velocity.magnitude;
                if (vel == 0)
                {
                    SetMode(Mode.idle);
                    stackPanel.ConsumeAction();
                    //Debug.Log("Stop");
                }
                else
                {
                    //Debug.Log(vel);
                }
            }
            else if (mode == Mode.jumping)
            {
                if (elapsed >= GameSettings.DoubleJumpDelay)
                {
                    SetMode(Mode.idle);
                    stackPanel.ConsumeAction();
                }
            }
            else if (mode == Mode.deployingForreuse)
            {
                SetMode(Mode.idle);
                stackPanel.ConsumeAction();
            }
            else if (mode == Mode.deployingAnalyser)
            {
                SetMode(Mode.idle);
                stackPanel.ConsumeAction();
            }
            else if (mode == Mode.undeployingForreuse)
            {
                SetMode(Mode.idle);
                stackPanel.ConsumeAction();
            }
            else if (mode == Mode.undeployingAnalyser)
            {
                SetMode(Mode.idle);
                stackPanel.ConsumeAction();
            }
            else
            {
                string action = stackPanel.GetAction();
                if (action == "left")
                {
                    DoActionLeft();
                }
                else if (action == "right")
                {
                    DoActionRight();
                }
                else if (action == "jump")
                {
                    DoActionJump();
                }
                else if (action == "forreuse-on")
                {
                    DoActionForreuseOn();
                }
                else if (action == "forreuse-off")
                {
                    DoActionForreuseOff();
                }
                else if (action == "analyser-on")
                {
                    DoActionAnalyserOn();
                }
                else if (action == "analyser-off")
                {
                    DoActionAnalyserOff();
                }
                ////Debug.Log(mx + " " + my);
                //if (mx != 0 || my != 0)
                //{
                //    if (mx > 0) { mx = 1; }
                //    else if (mx < 0) { mx = -1; }
                //    if (my > 0) { my = 1; mx = dirx; }
                //    //else if (my < 0) { my = -1; my = dirx; }
                //    MoveTo((int)mx, (int)my);
                //}
            }
        }

        Vector3 scale = spritePlayer.transform.localScale;

        scale.x = dirx;
        spritePlayer.transform.localScale = scale;
        if (!FuelConso(GameSettings.TimeConso * Time.deltaTime, 0))
        {
            Fuel = 0;
        }
        if (Fuel <= 0)
        {
            GameManager.instance.OutOfEnergy(InterestPointCollected);
        }
    }