コード例 #1
0
ファイル: AIController.cs プロジェクト: mikehenson273/GPE205
    // Update is called once per frame
    void FixedUpdate()
    {
        ObstacleAvoidance();
        AILife();
        switch (EnemyType)
        {
        case TypeofEnemy.Idle:
        {
            if (!avoiding)
            {
                Idle();
                SensedSomething();
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Looping:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Looping();
                SensedSomething();
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Retracing:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Retrace();
                SensedSomething();
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Lookout:
        {
            if (!avoiding)
            {
                LookoutAI();
                SensedSomething();
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Flee:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                RunFATBOYRun();
            }
            return;
        }

        case TypeofEnemy.sawPlayer:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                FoundYou();
            }
            return;
        }

        case TypeofEnemy.HeardASound:
        {
            if (!avoiding)
            {
                HeardSomething();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                else if (!sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = originalState_;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        default:
        {
            Debug.Log("No/Invalid State Was Selected");
            break;
        }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        ObstacleAvoidance();
        AILife();
        switch (EnemyType)
        {
        case TypeofEnemy.Idle:
        {
            if (!avoiding)
            {
                Idle();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }

                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Looping:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Looping();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Retracing:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Retrace();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                if (sensing.CanSee(GameObject.FindWithTag("PowerUp")))         //if set to flee AI runs from it (can't figure it out at the moment)
                {
                    playerCharacter_ = gameObject.transform;
                    EnemyType        = TypeofEnemy.sawPlayer;
                }
                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Lookout:
        {
            if (!avoiding)
            {
                LookoutAI();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Flee:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                RunFATBOYRun();
            }
            return;
        }

        case TypeofEnemy.sawPlayer:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                FoundYou();
            }
            return;
        }

        case TypeofEnemy.HeardASound:
        {
            if (!avoiding)
            {
                HeardSomething();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                else if (!sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = originalState_;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        default:
        {
            Debug.Log("No/Invalid State Was Selected");
            break;
        }
        }
    }