コード例 #1
0
        private void FixedUpdate()
        {
            switch (Character.CurrentState)
            {
            case Character.State.Stunned:
                Speed.Reinitialize();
                break;

            default:
                Move();
                if (Type == MovementType.GroundOnly && Character.GroundCheck.Evaluate())
                {
                    int savedLayer = Character.gameObject.layer;
                    Character.gameObject.layer = 2;
                    bool v = !Character.GroundCheck.Check.Evaluate();
                    Character.gameObject.layer = savedLayer;
                    if (v && previousState == Character.State.Moving && Character.CurrentState == Character.State.Idle && Character.Input.Dir == CharacterInput.Direction.None)
                    {
                        // If Character falls off of an edge, and does not want to move, drop straight below!
                        Character.MovementExecution.Reinitialize();
                        Character.MovementExecution.Rigidbody.velocity = Vector2.zero;
                    }
                }
                break;
            }
            previousState = Character.CurrentState;
            if (Character.Input.Dir != CharacterInput.Direction.None)
            {
                previousDirection = Character.Input.Dir;
            }
        }
コード例 #2
0
 public void Start(IAIAction.IStartable.Token token) {
     currentState = State.Patrol;
     patrolTimer.SetTime(PatrolTime);
     if (token.Source.SpriteRenderer.flipX) {
         token.Source.Character.Input.Dir = CharacterInput.Direction.Left;
         nextDir = CharacterInput.Direction.Right;
     } else {
         token.Source.Character.Input.Dir = CharacterInput.Direction.Right;
         nextDir = CharacterInput.Direction.Left;
     }
 }
コード例 #3
0
        public bool Execute(AIActionList.Token token)
        {
            if (moveTimer > 0f)
            {
                moveTimer -= Time.fixedDeltaTime;
                if (StrictMovementCheck(currentChecks))
                {
                    switch (direction)
                    {
                    case CharacterInput.Direction.Right:
                        MovementAndJumpExecution(RightSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest);
                        break;

                    default:
                        MovementAndJumpExecution(LeftSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest);
                        break;
                    }
                    if (moveTimer <= 0f)
                    {
                        direction = CharacterInput.Direction.None;
                    }
                }
                else
                {
                    moveTimer = 0f;
                    direction = CharacterInput.Direction.None;
                }
                return(true);
            }
            else if (directionTimer > 0f)
            {
                directionTimer -= Time.fixedDeltaTime;
                if (directionTimer <= 0f)
                {
                    SetMove(
                        Random.Range(MinMoveTime, MaxMoveTime),
                        Random.Range(0, 2) == 0 ?
                        CheckMovementDirection(RightSide, LeftSide, CharacterInput.Direction.Right, CharacterInput.Direction.Left) :
                        CheckMovementDirection(LeftSide, RightSide, CharacterInput.Direction.Left, CharacterInput.Direction.Right)
                        );
                }
                return(false);
            }
            else
            {
                directionTimer = Random.Range(MinNewDirectionTime, MaxNewDirectionTime);
                token.Source.Character.Input.Dir = CharacterInput.Direction.None;
                return(false);
            }
        }
コード例 #4
0
        private void SetMove(float moveTime, CharacterInput.Direction direction)
        {
            directionTimer = 0f;
            moveTimer      = moveTime;
            this.direction = direction;
            switch (this.direction)
            {
            case CharacterInput.Direction.Right:
                currentChecks = RightSide;
                return;

            default:
                currentChecks = LeftSide;
                return;
            }
        }
コード例 #5
0
 public bool Execute(AIActionList.Token token) {
     if (!patrolTimer.Execute(Time.fixedDeltaTime)) {
         switch (currentState) {
             case State.Patrol:
                 token.Source.Character.Input.Dir = CharacterInput.Direction.None;
                 currentState = State.Pause;
                 patrolTimer.SetTime(PauseTime);
                 break;
             default:
                 nextDir = nextDir == CharacterInput.Direction.Left ? CharacterInput.Direction.Right : CharacterInput.Direction.Left;
                 currentState = State.Patrol;
                 patrolTimer.SetTime(PatrolTime);
                 break;
         }
     } else if (currentState == State.Patrol) {
         if (nextDir == CharacterInput.Direction.Left)
             token.Source.Wander.MovementAndJumpExecution(token.Source.Wander.RightSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest);
         else
             token.Source.Wander.MovementAndJumpExecution(token.Source.Wander.LeftSide, out token.Source.Character.Input.Dir, ref token.Source.Character.Input.JumpRequest);
     }
     return true;
 }
コード例 #6
0
        /// <summary>
        /// If there is ground ahead or below, move to it.
        /// Otherwise, if there is ground above or across, jump to it.
        /// </summary>
        public bool MovementAndJumpExecution(SideChecks checks, out CharacterInput.Direction dir, ref bool jumpRequest, float dirY = 1f)
        {
            bool groundCheck = checks.GroundCheck.Evaluate();

            if ((groundCheck || checks.FallCheck.Evaluate()) && !checks.WallCheck.Evaluate())
            {
                dir = checks.Direction;
                if (dirY > 0f && !groundCheck && checks.JumpAboveCheck.Evaluate() && !checks.FreeGroundAboveCheck.Evaluate())
                {
                    jumpRequest = true;
                }
            }
            else if ((checks.JumpAboveCheck.Evaluate() && !checks.FreeGroundAboveCheck.Evaluate()) || (checks.JumpAcrossCheck.Evaluate() && !checks.FreeGroundAcrossCheck.Evaluate()))
            {
                dir         = checks.Direction;
                jumpRequest = true;
            }
            else
            {
                dir = CharacterInput.Direction.None;
                return(false);
            }
            return(true);
        }
コード例 #7
0
 private void OnEnable()
 {
     previousState     = Character.CurrentState;
     previousDirection = Character.Input.Dir;
 }
コード例 #8
0
 /// <summary>
 /// Make sure there is ground in the direction we want to move, and there is no wall in the way.
 /// If there is, go the other direction.
 /// If the other direction is also blocked, don't move at all.
 /// </summary>
 private static CharacterInput.Direction CheckMovementDirection(SideChecks checks, SideChecks oppositeChecks, CharacterInput.Direction dir, CharacterInput.Direction oppositeDir)
 {
     if (MovementCheck(checks))
     {
         return(dir);
     }
     else if (MovementCheck(oppositeChecks))
     {
         return(oppositeDir);
     }
     return(CharacterInput.Direction.None);
 }