Esempio n. 1
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 (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;
    }
Esempio n. 2
0
 void Update()
 {
     // set the correct sprite animation
     if (hidden)
     {
         hideAC.setupAndPlay();
     }
 }
Esempio n. 3
0
    public void setIdle(bool force)
    {
        // not idle if jumping and force = false
        if (!force && jump != null && jump.isJumping())
        {
            return;
        }

        if (move != null)
        {
            move.stop();
        }

        if (crouch != null)
        {
            crouch.noCrouch();
        }

        // due to problems on Unity's initialization order there is a use case where the object isn't instantiated

        /*if (idleAC == null)
        *       idleAC = AnimateTiledConfig.getByName(gameObject, EnumAnimateTiledName.Idle, true);
        *  if (idleAC != null)*/
        idleAC.setupAndPlay();
    }
Esempio n. 4
0
    protected void _walk(float vel)
    {
        //NOTE: remember to set the gain property before calling this method from subclasses

        // set the correct sprite animation
        if (!walkAC.isWorking() && (jump == null || !jump.isJumping()) && (crouch == null || !crouch.isCrouching()))
        {
            walkAC.setupAndPlay();
        }

        velocity = vel;
        if (!walking)
        {
            this.enabled = true;
        }
        walking = true;

        if (agUpdater != null)
        {
            agUpdater.setWalkSpeed(gain * velocity);
        }
        else
        {
            Vector2 v = body.velocity;
            v.x           = gain * vel;
            body.velocity = v;
        }

        /*if (jump != null) {
         *      if (!jump.isJumping())
         *              updateWalk();
         * } else */{
            updateWalk();
        }
    }
Esempio n. 5
0
    public void sneak()
    {
        if (sneaking)
        {
            return;
        }

        sneaking = true;
        sneakAC.setupAndPlay();
    }
Esempio n. 6
0
    public void forceJump(float jumpVel)
    {
        // set the correct sprite animation
        if (crouch == null || !crouch.isCrouching())
        {
            jumpAC.setupAndPlay();
        }

        _isJumping = true;

        Vector2 v = body.velocity;

        v.y           = jumpVel;
        body.velocity = v;
    }
Esempio n. 7
0
    protected void _walk(float velocity)
    {
        //NOTE: remember to set the gain property before calling this method from subclasses

        // set the correct sprite animation
        if (!walkAC.isWorking() && (jump == null || !jump.IsJumping()) && (crouch == null || !crouch.isCrouching()))
        {
            walkAC.setupAndPlay();
        }

        walking = true;

        // horizontal move
        bool oldLooking = lookingRight;

        // moving right
        if (velocity > 0f)
        {
            lookingRight = true;
        }
        // moving left
        else if (velocity < 0f)
        {
            lookingRight = false;
        }

        Vector2 v = shape.body.velocity;

        v.x = gain * velocity;
        shape.body.velocity = v;

        // did game object turn around?
        if (oldLooking != lookingRight)
        {
            Vector3 theScale = transform.localScale;
            theScale.x          *= -1f;
            transform.localScale = theScale;
        }
    }
Esempio n. 8
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();
    }
Esempio n. 9
0
    // Update is called once per frame
    public void crouch()
    {
        // is it jumping?
        bool jumping = false;

        if (jump != null && jump.isJumping())
        {
            jumping = true;
        }
        // is it moving?
        bool moving = false;

        if (move != null && move.isWalking())
        {
            moving = true;
        }

        // if crouching then update accordingly
        if (sneak != null && crouching)
        {
            // while in the air we can't sneak
            if (jumping)
            {
                if (sneak.isSneaking())
                {
                    sneak.stopSneaking();
                    crouchAC.setupAndPlay();
                }
            }
            // if not jumping and not moving and sneaking: stop sneaking and do crouch
            else if (!moving)
            {
                if (sneak.isSneaking())
                {
                    sneak.stopSneaking();
                    crouchAC.setupAndPlay();
                }
            }
            // if not jumping and moving: sneak
            else
            {
                sneak.sneak();
            }
        }

        // don't update
        if (crouching || jumping)
        {
            return;
        }

        crouching = true;

        // resize the collider
        Vector3 theSize = box.size;

        theSize.y *= crouchColliderProportion;
        box.size   = theSize;
        // transform the collider
        Vector3 theCenter = box.center;

        theCenter.y -= centerOffsetY;
        box.center   = theCenter;

        // set the correct sprite animation
        crouchAC.setupAndPlay();
    }