Exemplo n.º 1
0
    // Update is called once per frame.
    void Update()
    {
        // Reset total jumps allowed when not performing a jump and grounded or when on a moving/sinking platform.
        if (!jump && (player.grounded || player.IsStuckToPlatform()) && ((Mathf.Round(GetComponent <Rigidbody2D>().velocity.y) == 0) || ((player.OnMovingPlatform() || player.OnSinkingPlatform()) && GetComponent <Rigidbody2D>().velocity.y == player.GetPlatform().GetComponent <Rigidbody2D>().velocity.y)))
        {
            jumps = doubleJumping.totalJumps;
        }

        // If the jump button is pressed, jumps are allowed and the player is not dashing, sliding, on a ladder or crouching under an obstacle...
        if (!jump && CFInput.GetButtonDown("Jump") && jumps > 0 && !player.dashing && !player.sliding && !player.onLadder)
        {
            // If the player is grounded...
            if (player.grounded)
            {
                // ... initialize jump.
                InitJump();
                // If the player is not grounded and totalJumps is higher than 1...
            }
            else if (doubleJumping.totalJumps > 1)
            {
                // ... initialize jump if the Y velocity is inside the double jump window (or when there isn't a window).
                if (!doubleJumping.jumpWindow || (doubleJumping.jumpWindow && GetComponent <Rigidbody2D>().velocity.y > doubleJumping.jumpWindowMin && GetComponent <Rigidbody2D>().velocity.y < doubleJumping.jumpWindowMax))
                {
                    doubleJump = true;
                    InitJump();
                }
            }
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        if (player.grounded)
        {
            totalAirDashes = airDashTotal;
        }

        SetDashAllowed();


        if (player.dashing)
        {
            dashAllowed = false;

            if (GetComponent <Rigidbody2D>().velocity.x == 0)
            {
                dashTimer = 0;
            }

            if (dashTimer > 0)
            {
                dashTimer -= Time.deltaTime;
            }

            else
            {
                runCooldownTimer = true;

                player.Dash(false);
            }
        }

        if (runCooldownTimer)
        {
            dashAllowed = false;

            if (cooldownTimer > 0)
            {
                cooldownTimer -= Time.deltaTime;
            }

            else
            {
                runCooldownTimer = false;

                SetDashAllowed();
            }
        }

        else if (CFInput.GetButtonDown("Dash") && dashAllowed && !player.dashing && !player.crouching && !player.stuckToWall && !player.falling && !player.sliding && !player.onLadder && !player.stop)
        {
            dash = true;
            GetComponent <AudioSource>().PlayOneShot(dashsound);
            Instantiate(dashparticle, dashparticleloc.position, dashparticleloc.localRotation);
            if (PlayerPrefs.GetInt("Vibrate") == 0)
            {
                player.Vib650();
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame.
    void Update()
    {
        // Check if the player's hitbox collides with a ladder.
        Vector2 pos    = transform.position;
        Vector2 pointA = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2), pos.y + boxCollider.offset.y - (boxCollider.size.y / 2));
        Vector2 pointB = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));

        hitLadder = Physics2D.OverlapArea(pointA, pointB, ladderLayer);

        // If the player isn't currently on a ladder, there is a ladder collission and the player isn't falling, dashing, crouching, sliding or stuck on a wall...
        if (!player.onLadder && hitLadder && !player.falling && !player.dashing && !player.crouching && !player.sliding && !player.stuckToWall)
        {
            // ... cache the vertical CFInput.
            float v = CFInput.GetAxis("Vertical");

            // If the player isn't on a ladder and the vertical movement is either moving up or down...
            if (!player.onLadder && (v > 0.5 || v < -0.5))
            {
                // ... make sure the player is stuck to the ladder.
                Stick();
            }
        }

        // If there isn't a collission with a ladder and the player is considered on a ladder...
        if (!hitLadder && player.onLadder)
        {
            // ... make the player unstuck from the ladder.
            Unstick();
        }

        // If the player is on a ladder, there is a ladder object and the player is allowed to jump...
        if (player.onLadder && ladder && ladder.allowJump && CFInput.GetButtonDown("Jump"))
        {
            // ... unstick the player from the ladder and perform the jump.
            Unstick();
            player.Jump();
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        animator.SetBool("grounded", grounded);
        animator.SetBool("walking", walking);
        animator.SetBool("crouching", crouching);
        animator.SetBool("sliding", sliding);
        animator.SetBool("dashing", dashing);
        animator.SetBool("falling", falling);
        animator.SetBool("wall", stuckToWall);
        animator.SetBool("onLadder", onLadder);
        animator.SetBool("jumpingThrough", jumpingThrough);

        if (timer > 0f)
        {
            timer -= Time.deltaTime;
        }

        if (timer < 0f)
        {
            timer = 0f;
        }

        if (timer == 0f)
        {
            WSVibrator.Cancel();
        }

        if (orient == null)
        {
            orient = GameObject.Find("KingOrient");
        }

        if (goodSpawn == null)
        {
            goodSpawn = GameObject.Find("EndSpawnBack");
        }

        if (attackTimer > 0f)
        {
            attackTimer -= Time.deltaTime;
        }

        if (attackTimer == 0f && timedFire)
        {
            timedFire = false;
            fire      = false;
        }

        if (nextFire > 0f)
        {
            nextFire -= Time.deltaTime;
        }

        if (attackTimer < 0f)
        {
            attackTimer = 0f;
        }

        if (staffTimer < 0f)
        {
            staffTimer = 0f;
        }

        if (staffTimer > 0f)
        {
            staffTimer -= Time.smoothDeltaTime;
        }

        if (staffTimer == 0)
        {
            staffClicks = 0;
        }

        if (nextFire < 0f)
        {
            nextFire = 0f;
        }

        Vector2 pos = transform.position;

        if (facingRight)
        {
            frontCheckTop.transform.position = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));
            frontCheckBot.transform.position = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2) + 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius / 2));
        }

        else
        {
            frontCheckTop.transform.position = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));
            frontCheckBot.transform.position = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2) - 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius / 2));
        }

        if (!stop)
        {
            hor = CFInput.GetAxis("Horizontal");
            animator.SetFloat("horizontal", Mathf.Abs(hor));
        }

        animator.SetFloat("xSpeed", Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x));
        animator.SetFloat("ySpeed", GetComponent <Rigidbody2D>().velocity.y);

        if (!OnPlatform())
        {
            groundCollider = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer);
        }

        if (keepVelocityOnGround && groundedXVelocity > 0)
        {
            if (groundedTimer > 0)
            {
                groundedTimer -= Time.deltaTime;
            }

            else
            {
                groundedXVelocity = 0;
            }
        }

        if (groundCollider && !jumpingThrough)
        {
            if (keepVelocityOnGround && !grounded)
            {
                groundedXVelocity = GetComponent <Rigidbody2D>().velocity.x;
                groundedTimer     = groundedVelocityTime;
            }
            grounded = true;
            jumping  = false;
            if (rotateOnSlope && !OnPlatform())
            {
                transform.rotation = groundCollider.transform.localRotation;
            }
            if (falling)
            {
                animator.SetTrigger("stateComplete");
            }
            falling = false;
        }

        else
        {
            transform.rotation = normalRotation;
            grounded           = false;
        }

        if ((hor > 0 && !facingRight) || (hor < 0 && facingRight) || flipAgain)
        {
            Flip();
        }

        if (Staff)
        {
            if (pickup.staffAmmo > 0f && staffClicks == 1 && !staffFired)
            {
                if (staffTimer < 0.3f)
                {
                    Vib100();
                    isAttacking = true;
                    fire        = true;
                    animator.SetBool("StaffFire", true);
                    GetComponent <AudioSource>().PlayOneShot(staffShot, 1.0f);
                    GameObject      newBullet = Instantiate(staffBullet);
                    StaffController bullCon   = newBullet.GetComponent <StaffController>();
                    bullCon.playerObject = gameObject;
                    bullCon.StaffShoot();
                    newBullet.transform.position = staffBulletSpawn.position;
                    pickup.staffAmmo--;
                    staffFired = true;
                }
            }
        }

        if (CFInput.GetButtonDown("Fire1"))
        {
            Fire();
        }

        if (CFInput.GetButton("Fire1") && Machinegun)
        {
            machinegunBulletSpawn = GameObject.Find("MachineGunSpawnPoint").transform;
            if (!onLadder && !stuckToWall)
            {
                if (nextFire == 0f && pickup.machinegunAmmo > 0f)
                {
                    Vib50();
                    isAttacking = true;
                    nextFire    = machinegunFireRate;
                    animator.SetBool("MachineGunFire", true);
                    GetComponent <AudioSource>().PlayOneShot(machinegunShot, 1.0f);
                    GameObject           newBullet = Instantiate(machinegunBullet);
                    GameObject           newKick   = Instantiate(machinegunKick);
                    MachineGunController bullCon   = newBullet.GetComponent <MachineGunController>();
                    ParticleFlip         kickCon   = newKick.GetComponent <ParticleFlip>();
                    bullCon.playerObject = gameObject;
                    kickCon.playerObject = gameObject;
                    bullCon.MachineGunShoot();
                    kickCon.MachineGunShoot();
                    newBullet.transform.position = machinegunBulletSpawn.position;
                    newKick.transform.position   = machinegunBulletSpawn.position;
                    pickup.machinegunAmmo--;
                }

                else if (pickup.machinegunAmmo == 0f)
                {
                    isAttacking = false;
                    animator.SetBool("MachineGunFire", false);
                    GetComponent <AudioSource>().PlayOneShot(outOfAmmo);
                }
            }
        }

        if (CFInput.GetButtonUp("Fire1") && Machinegun)
        {
            isAttacking = false;
            animator.SetBool("MachineGunFire", false);
        }
    }
Exemplo n.º 5
0
    // Token: 0x060003E6 RID: 998 RVA: 0x00018788 File Offset: 0x00016B88
    private void Update()
    {
        this.stick = (UnityEngine.Object.FindObjectOfType(typeof(EasyJoystick)) as EasyJoystick);
        if (CFInput.GetButton("Eat") && this.eats && this.questM.Eatbar())
        {
            if (base.GetComponent <AttackTriggerC>().useMecanim)
            {
                this.mainModel.GetComponent <Animator>().CrossFade(this.EatingAnim, 0.5f);
            }
            else
            {
                this.mainModel.GetComponent <Animation>()[this.EatingAnim].layer = 25;
                this.mainModel.GetComponent <Animation>().CrossFade(this.EatingAnim);
            }
        }
        if (this.moveSleep && this.maleSleepPos && this.femaleSleepPos)
        {
            this.mate.transform.position = Vector3.MoveTowards(this.mate.transform.position, this.femaleSleepPos.position, 0.1f);
            base.transform.position      = Vector3.MoveTowards(base.transform.position, this.maleSleepPos.position, 0.1f);
        }
        if (this.rotating)
        {
            this._lookRotation      = Quaternion.LookRotation(this._direction);
            base.transform.rotation = Quaternion.Slerp(base.transform.rotation, this._lookRotation, Time.deltaTime * this.RotationSpeed);
        }
        StatusC component = base.GetComponent <StatusC>();

        if (component.freeze)
        {
            this.motor.inputMoveDirection = new Vector3(0f, 0f, 0f);
            return;
        }
        if (Time.timeScale == 0f)
        {
            return;
        }
        if (this.dodging)
        {
            Vector3 a = base.transform.TransformDirection(this.dir);
            this.controller.Move(a * 8f * Time.deltaTime);
            return;
        }
        if (this.recover && !this.sprint && !this.dodging)
        {
            if (this.recoverStamina >= this.staminaRecover)
            {
                this.StaminaRecovery();
            }
            else
            {
                this.recoverStamina += Time.deltaTime;
            }
        }
        if (this.dodgeRollSetting.canDodgeRoll)
        {
            if (CFInput.GetButtonDown("Vertical") && CFInput.GetAxis("Vertical") > 0f && (this.controller.collisionFlags & CollisionFlags.Below) != CollisionFlags.None && CFInput.GetAxis("Horizontal") == 0f)
            {
                if (CFInput.GetButtonDown("Vertical") && Time.time - this.lastTime < 0.4f && CFInput.GetButtonDown("Vertical") && Time.time - this.lastTime > 0.1f && CFInput.GetAxis("Vertical") > 0.03f)
                {
                    this.lastTime = Time.time;
                    this.dir      = Vector3.forward;
                    base.StartCoroutine(this.DodgeRoll(this.dodgeRollSetting.dodgeForward));
                }
                else
                {
                    this.lastTime = Time.time;
                }
            }
            if (CFInput.GetButtonDown("Vertical") && CFInput.GetAxis("Vertical") < 0f && (this.controller.collisionFlags & CollisionFlags.Below) != CollisionFlags.None && CFInput.GetAxis("Horizontal") == 0f)
            {
                if (CFInput.GetButtonDown("Vertical") && Time.time - this.lastTime < 0.4f && CFInput.GetButtonDown("Vertical") && Time.time - this.lastTime > 0.1f && CFInput.GetAxis("Vertical") < -0.03f)
                {
                    this.lastTime = Time.time;
                    this.dir      = Vector3.back;
                    base.StartCoroutine(this.DodgeRoll(this.dodgeRollSetting.dodgeBack));
                }
                else
                {
                    this.lastTime = Time.time;
                }
            }
            if (CFInput.GetButtonDown("Horizontal") && CFInput.GetAxis("Horizontal") < 0f && (this.controller.collisionFlags & CollisionFlags.Below) != CollisionFlags.None && !CFInput.GetButton("Vertical"))
            {
                if (CFInput.GetButtonDown("Horizontal") && Time.time - this.lastTime < 0.3f && CFInput.GetButtonDown("Horizontal") && Time.time - this.lastTime > 0.15f && CFInput.GetAxis("Horizontal") < -0.03f)
                {
                    this.lastTime = Time.time;
                    this.dir      = Vector3.left;
                    base.StartCoroutine(this.DodgeRoll(this.dodgeRollSetting.dodgeLeft));
                }
                else
                {
                    this.lastTime = Time.time;
                }
            }
            if (CFInput.GetButtonDown("Horizontal") && CFInput.GetAxis("Horizontal") > 0f && (this.controller.collisionFlags & CollisionFlags.Below) != CollisionFlags.None && !CFInput.GetButton("Vertical"))
            {
                if (CFInput.GetButtonDown("Horizontal") && Time.time - this.lastTime < 0.3f && CFInput.GetButtonDown("Horizontal") && Time.time - this.lastTime > 0.15f && CFInput.GetAxis("Horizontal") > 0.03f)
                {
                    this.lastTime = Time.time;
                    this.dir      = Vector3.right;
                    base.StartCoroutine(this.DodgeRoll(this.dodgeRollSetting.dodgeRight));
                }
                else
                {
                    this.lastTime = Time.time;
                }
            }
        }
        if ((this.sprint && Input.GetAxis("Vertical") < 0.02f) || (this.sprint && this.stamina <= 0f) || (this.sprint && Input.GetButtonDown("Fire1")) || (this.sprint && Input.GetKeyUp(KeyCode.LeftShift)))
        {
            this.sprint  = false;
            this.recover = true;
            this.motor.movement.maxForwardSpeed  = this.walkSpeed;
            this.motor.movement.maxSidewaysSpeed = this.walkSpeed;
            this.recoverStamina = 0f;
        }
        Vector3 vector = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));

        if (vector != Vector3.zero)
        {
            float num = vector.magnitude;
            vector /= num;
            num     = Mathf.Min(1f, num);
            num    *= num;
            vector *= num;
        }
        this.motor.inputMoveDirection = base.transform.rotation * vector;
        if (CFInput.GetButton("Jump") && !this.alwJump)
        {
            base.GetComponent <PlayerMecanimAnimationC>().PlayAnim("jump");
            base.GetComponent <PlayerMecanimAnimationC>().PlayAnim("Jump_place_All_short");
            base.StartCoroutine(this.jumping());
        }
        this.motor.inputJump = CFInput.GetButton("Jump");
        if (this.sprint)
        {
            this.motor.movement.maxForwardSpeed  = this.sprintSpeed;
            this.motor.movement.maxSidewaysSpeed = this.sprintSpeed;
            return;
        }
        if (CFInput.GetButton("Sprint") && Input.GetAxis("Vertical") > 0f && (this.controller.collisionFlags & CollisionFlags.Below) != CollisionFlags.None && this.canSprint && this.stamina > 0f)
        {
            this.sprint = true;
            base.StartCoroutine(this.Dasher());
        }
        if (CFInput.GetButton("Sprint"))
        {
        }
    }
Exemplo n.º 6
0
    // This function is called every fixed framerate frame.
    void FixedUpdate()
    {
        // If the player should jump...
        if (jump)
        {
            // If the player is jumping down a platform and is doing the first jump...
            if (player.jumpDown && jumps == doubleJumping.totalJumps)
            {
                // ... add a small Y force.
                GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, 200f));

                // If the player is on a platform...
                if (player.OnPlatform())
                {
                    // Set the moving platform to null.
                    player.UnstickFromPlatform();
                }

                // Reset the jumping variables.
                ResetJumpVars();

                // Reset jumpDown.
                player.jumpDown = false;

                // Stop the player from jumping.
                return;
            }

            // If this is the initial jump...
            if (initialJump)
            {
                // Check if the player is running when the jump is being performed.
                walkingOnJump = player.walking;

                // When double jumping, set Y velocity to 0 to make sure the jump force is applied correctly.
                if (doubleJump)
                {
                    player.SetYVelocity(0);
                }

                // Decrease total jumps allowed with 1.
                jumps--;

                // If the player is on a moving platform and should not keep the speed when jumping from a moving platform...
                if (player.OnMovingPlatform() && !player.KeepSpeedOnJump())
                {
                    // Set the X velocity to 0.
                    player.SetXVelocity(0);
                }
            }

            // Get the jump factor.
            float jumpFactor = player.GetJumpFactor();

            // If you need to hold the Jump input to jump higher...
            if (jumpType == JumpType.HoldToJumpHigher)
            {
                // When there is an initial jump...
                if (initialJump)
                {
                    // ... set the y velocity to the player's initial jump value.
                    float yVel = jumpFactor * (doubleJump ? holdToJumpHigher.initialDoubleJump : holdToJumpHigher.initialJump);

                    // If the player is on a moving platform...
                    if (player.OnMovingPlatform())
                    {
                        // ... get the current platform.
                        GameObject platform = player.GetPlatform();
                        // If the platform's Y velocity is greater than 0...
                        if (platform.GetComponent <Rigidbody2D>().velocity.y > 0)
                        {
                            // ... make sure the y velocity of this platform is taken into account when jumping.
                            yVel += platform.GetComponent <Rigidbody2D>().velocity.y;
                        }
                    }

                    // If the player is on a platform...
                    if (player.OnPlatform())
                    {
                        // Set the moving platform to null.
                        player.UnstickFromPlatform();
                    }

                    // Make sure the player's velocity is set.
                    player.SetYVelocity(yVel);

                    // Set initialJump to false.
                    initialJump = false;
                    // When the jump button is being pressed and the timer isn't finished yet...
                }
                else if (CFInput.GetButtonDown("Jump") && jumpTimer > 0)
                {
                    // ... decrease the timer's value.
                    jumpTimer -= Time.deltaTime;

                    // Set the Y Force for the player.
                    GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpFactor * (doubleJump ? holdToJumpHigher.doubleJumpForce : holdToJumpHigher.jumpForce)));
                    // When the timer is finished or the jump button isn't being pressed...
                }

                else
                {
                    // ... reset the jumping variables.
                    ResetJumpVars();
                }
                // Or else if you need a single press to perform a jump...
            }

            else
            {
                // Add a vertical force to the player.
                GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpFactor * (doubleJump ? singlePressToJump.doubleJumpForce : singlePressToJump.jumpForce)));

                // If the player is on a platform...
                if (player.OnPlatform())
                {
                    // Set the moving platform to null.
                    player.UnstickFromPlatform();
                }

                // Reset the jumping variables.
                ResetJumpVars();
            }
        }
    }