Пример #1
0
        public override int WantsToUpdate(float delta)
        {
            if (!pc2d.collisions.below)
            {
                return(0);
            }

            float x = input.GetAxisRawX();

            if (x > 0)
            {
                if (faceDir != 1)
                {
                    pushingCD.Reset();
                }

                faceDir = 1;
                if (character.IsBox(Directions.Right) && pushingCD.IncReady())
                {
                    return(priority);
                }
                return(0);
            }
            if (x < 0)
            {
                if (faceDir != -1)
                {
                    pushingCD.Reset();
                }

                faceDir = -1;
                if (character.IsBox(Directions.Left) && pushingCD.IncReady())
                {
                    return(priority);
                }
                return(0);
            }

            pushingCD.Reset();
            return(0);
        }
Пример #2
0
        public override int WantsToUpdate(float delta)
        {
            float x = input.GetAxisRawX();

            if (x > 0)
            {
                if (faceDir != 1)
                {
                    pushingCD.Reset();
                }

                faceDir = 1;
                if (IsBoxRight() && pushingCD.IncReady())
                {
                    return(priority);
                }
                return(0);
            }
            if (x < 0)
            {
                if (faceDir != -1)
                {
                    pushingCD.Reset();
                }

                faceDir = -1;
                if (IsBoxLeft() && pushingCD.IncReady())
                {
                    return(priority);
                }
                return(0);
            }

            pushingCD.Reset();
            return(0);
        }
Пример #3
0
        public override void PerformAction(float delta)
        {
            // guard: something goes wrong!
            if (character.ladder == null)
            {
                character.ExitState(States.Ladder);
                return;
            }
            Ladder ladder = character.ladder;

            Vector2 in2d = input.GetAxisRaw();

            if (character.IsOnArea(Areas.Ladder) && character.IsOnState(States.Ladder))
            {
                // disable x movement
                character.velocity.x = 0;
                character.velocity.y = speed * in2d.y;
            }

            // TODO transition
            if (centering)
            {
                float ladderCenter = ladder.GetComponent <BoxCollider2D>().bounds.center.x;
                float characterX   = character.GetCenter().x;
                if (Math.Abs(characterX - ladderCenter) < 0.05)
                {
                    centering            = false;
                    character.velocity.x = 0;
                }
                else
                {
                    // instant move to the center of the ladder!
                    Mathf.SmoothDamp(characterX, ladderCenter, ref character.velocity.x, towardsTime, towardsSpeed, delta);
                }
            }

            if (ladder.topDismount && ladder.IsAtTop(character, character.feet) && in2d.y > 0)
            {
                // top dismount enabled and reached
                character.velocity = Vector2.zero;
                ladder.Dismount(character);
            }
            else if (ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0)
            {
                // bottom dismount enabled and reached
                character.velocity = Vector2.zero;
                ladder.Dismount(character);
            }
            else if (!ladder.topDismount && ladder.IsAboveTop(character, character.head) && in2d.y > 0)
            {
                // can't dismount (vine) don't let the head 'overflow' the ladder
                character.velocity = Vector2.zero;
            }
            else if (!ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0)
            {
                // can't dismount (vine) don't let the head 'overflow' the ladder
                // caveat: Vine cannot be near ground
                character.velocity = Vector2.zero;
            }

            character.SetFacing(in2d.x);

            // check for dismount conditions
            if (in2d.x != 0)
            {
                // do not allow to jump without telling the direction.
                // move up if you want it
                if (dismountJumping && input.IsActionHeld(actionJump.action))
                {
                    dismount.Reset();
                    character.ladder.Dismount(character);
                    character.ladder = null;

                    actionJump.Jump(new JumpConstant(character,
                                                     jumpOff.Clone((int)character.faceDir)
                                                     ));
                }
                else if (dismount.IncReady())
                {
                    character.velocity = Vector2.zero;
                    character.ladder.Dismount(character);
                    character.ladder = null;
                }
            }
            else
            {
                dismount.Reset();
            }
        }