コード例 #1
0
ファイル: LookUpwards.cs プロジェクト: memsyi/marioBadClone
    public void lookUpwards()
    {
        // since is allowed to look upwards and walk at the same time then make sure the correct
        // sprite anim is executed when is not walking
        if (lookingUp && !walk.isWalking())
        {
            lookUpAC.setupAndPlay();
        }
        // avoid re calculation if is already looking upwards
        if (lookingUp || !restoreLookUp.isRestored())
        {
            return;
        }

        // copy state
        tempConfig.setStateFrom(playerFollower);
        // apply changes
        playerFollower.lockY      = false;
        playerFollower.smoothLerp = true;         // the camera moves with nice lerping
        playerFollower.offsetY   += camDisplacement;
        playerFollower.timeFactor = speedFactor;

        restoreLookUp.setRestored(false);

        // set the correct sprite animation
        lookUpAC.setupAndPlay();
        lookingUp = true;
    }
コード例 #2
0
    public void lookUpwards()
    {
        // since is allowed to look upwards and walk at the same time then make sure the correct
        // sprite anim is executed when is not walking
        if (dirSign > 0f && !walk.isWalking())
        {
            lookUpAC.setupAndPlay();
        }

        // if it's not correct timing then exit method
        if (timing < 1f)
        {
            timing += Time.deltaTime * _PERIOD;
            return;
        }
        // avoid re calculation if is already looking upwards
        if (dirSign > 0f || !restoreLookDir.isRestored())
        {
            return;
        }

        dirSign = 1f;
        lookToDir();
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        bool isIdle = true;

        // This sets the correct jump status when the player without jumping enters on free fall state.
        // Also corrects a sprite animation flickering when walking because the animation starts again
        // constantly after jump.resetStatus()
        if (exitedFromScenery && !jump.isJumping())
        {
            ChipmunkSegmentQueryInfo qinfo;
            // check if there is no shape below us
            Vector2 end = body.position + queryOffset;
            Chipmunk.SegmentQueryFirst(body.position, end, collisionLayersSkip, collisionGroupSkip, out qinfo);
            // if no handler it means no hit
            if (System.IntPtr.Zero == qinfo._shapeHandle)
            {
                jump.reset();                 // set state as if were jumping
            }
        }

        // jump
        if (Gamepad.Instance.isA())
        {
            walk.stop();
            jump.jump(lightJumpVelocity);
            // apply gain jump power. Only once per jump (handled in Jump component)
            if (Gamepad.Instance.isHardPressed(EnumButton.A))
            {
                jump.applyGain(gainJumpFactor);
            }
            isIdle = false;
        }

        // power up action
        if (powerUp != null && powerUp.ableToUse())
        {
            powerUp.action(gameObject);
        }

        // walk
        if (Gamepad.Instance.isLeft())
        {
            // is speed up button being pressed?
            if (Gamepad.Instance.isB())
            {
                walk.setGain(walk.speedUpFactor);
            }
            else
            {
                walk.setGain(1f);
            }
            walk.walk(-walkVelocity);
            fireDir = leftFireDir;
        }
        else if (Gamepad.Instance.isRight())
        {
            // is speed up button being pressed?
            if (Gamepad.Instance.isB())
            {
                walk.setGain(walk.speedUpFactor);
            }
            else
            {
                walk.setGain(1f);
            }
            walk.walk(walkVelocity);
            fireDir = rightFireDir;
        }
        if (walk.isWalking())
        {
            isIdle = false;
        }

        // crouch
        if (Gamepad.Instance.isDown())
        {
            crouch.crouch();
            isIdle = false;
        }
        else
        {
            crouch.noCrouch();
        }

        // look upwards/downwards
        if (!jump.isJumping())
        {
            if (Gamepad.Instance.isUp())
            {
                lookDirections.lookUpwards();
                isIdle = false;
            }
            else
            {
                lookDirections.restore();
            }
        }
        else
        {
            lookDirections.lockYWhenJumping();
        }

        // finally only if not doing any action then set idle state
        if (isIdle)
        {
            idle.setIdle(false);
        }
    }