Ejemplo n.º 1
0
        private void StopWallRunning(HeroController hc)
        {
            if (hc == null)
            {
                return;
            }

            FixHero(hc);

            // Move the hero a bit up left after the rotation in FixHero to prevent clipping
            Transform t   = hc.transform;
            Vector3   pos = t.position;

            t.SetPositionX(pos.x - 0.75f);
            hc.transform.SetPositionY(pos.y + 0.5f);

            // Force a wall jump
            hc.FaceLeft();
            hc.cState.wallSliding = true;
            hc.touchingWallL      = true;
            HcWallJump(hc, null);

            // If the player has wings, prevent a double jump
            if (Ref.PD.hasDoubleJump)
            {
                On.HeroController.DoDoubleJump -= No;
                On.HeroController.DoDoubleJump += No;

                // Unhook after one frame just to be 100% certain this doesn't cause dropped inputs
                StartCoroutine(UnhookNo());
            }
        }
Ejemplo n.º 2
0
        public void Update()
        {
            // Jump off the wall if the player presses jump
            if (_wallRunning && Ref.Input.inputActions.jump.WasPressed)
            {
                StopWallRunning(Ref.Hero);
                return;
            }

            HeroController hc = Ref.Hero;

            if (hc == null || !_wallRunning)
            {
                return;
            }

            GameObject hero = hc.gameObject;

            // Handle movement of the hero
            // Bounds checking is only in the direction the player is currently moving, but this should be fine
            if (hc.transform.position.y < transform.position.y + _box.size.y / 2 &&
                Ref.Input.inputActions.left.IsPressed)
            {
                hc.FaceLeft();
                hero.transform.SetPositionX(transform.position.x + _box.size.x + .15f);

                hero.transform.SetPositionY(hero.transform.position.y +
                                            hc.GetRunSpeed() * Time.deltaTime);
                hc.GetComponent <tk2dSpriteAnimator>().Play(hc.GetRunAnimName());
            }
            else if (hc.transform.position.y > transform.position.y - _box.size.y / 2 &&
                     Ref.Input.inputActions.right.IsPressed)
            {
                hc.FaceRight();
                hero.transform.SetPositionX(transform.position.x + _box.size.x + .15f);

                hero.transform.SetPositionY(hero.transform.position.y -
                                            hc.GetRunSpeed() * Time.deltaTime);
                hc.GetComponent <tk2dSpriteAnimator>().Play(hc.GetRunAnimName());
            }
            else if (Ref.Input.inputActions.left.WasReleased ||
                     Ref.Input.inputActions.right.WasReleased)
            {
                hc.GetComponent <tk2dSpriteAnimator>().Play("Run To Idle");
                hero.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            }
            else
            {
                string animName = hc.GetComponent <tk2dSpriteAnimator>().CurrentClip.name;
                if (animName != "Run To Idle")
                {
                    hc.GetComponent <tk2dSpriteAnimator>().Play("Idle");
                }

                hero.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            }
        }
Ejemplo n.º 3
0
        private float FaceHero()
        {
            var heroSignX = Mathf.Sign(_target.transform.GetPositionX() - gameObject.transform.GetPositionX());
            var pScale    = gameObject.transform.localScale;

            gameObject.transform.localScale = new Vector2(Mathf.Abs(pScale.x) * heroSignX, pScale.y);
            if (heroSignX > 0)
            {
                _target.FaceLeft();
            }
            else
            {
                _target.FaceRight();
            }
            return(heroSignX);
        }