コード例 #1
0
    public void ChangeState(IEnemyState newState)
    {
        if (currentState != null) {
            currentState.Exit();
        }

        currentState = newState;
        currentState.Enter(this);
    }
コード例 #2
0
	public void ChangeState(IEnemyState newState)
	{
		//Exits old state
		if(currentState != null)
			currentState.Exit();

		//Enters new
		currentState = newState;
		currentState.Enter(this);
	}
コード例 #3
0
    void Start()
    {
        if(GetComponent<StatePatternEnemy>() == null)
        {
            Debug.Warning("level", "Redcoat " + gameObject.name + " has no state pattern to animate on.");
            return;
        }

        animController = GetComponent<Animator>();
        animParams = animController.parameters;
        redcoat = GetComponent<StatePatternEnemy>();
        state = redcoat.currentState;
    }
コード例 #4
0
ファイル: AIAgent.cs プロジェクト: elaimaz/VRMonkeyTest
    public void setState(IEnemyState newState)
    {
        navAgent.threadController.moving = false;
        currentStateType = newState.getStateType();

        if (currentStateType == StateType.idle)
        {
            Debug.Log("hm");
        }
        currentState.End();
        previousState = currentState;
        currentState  = newState;
        currentState.Start(this);
    }
コード例 #5
0
 public Koopa(int locX, int locY)
 {
     score     = new NonPlayerScoreItem(100, true);
     location  = new Vector2(locX, locY);
     state     = new KoopaHealthy(this);
     rigidbody = new AutonomousPhysicsObject();
     LoadRigidBodyProperties();
     directionLeft   = false;
     shellForm       = false;
     hurtMario       = true;
     frozen          = false;
     freezeCounter   = UtilityClass.zero;
     enemyFreezeTime = UtilityClass.enemyFreezeTime;
 }
コード例 #6
0
    void DedectPlayer()
    {
        Collider[] hitColliders = Physics.OverlapSphere(transform.position, detectRange);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            if (hitColliders[i].CompareTag("Player") && currentState != chaseState)
            {
                currentState = alertState;
            }
            i++;
        }
    }
コード例 #7
0
    public void ChangeState(IEnemyState newState)
    {
        // Stop current state
        if (currentState != null)
        {
            currentState.Exit();
        }

        // Only enter new state when it's different from previous state, prevent multiple calls of the same function
        if (currentState != newState)
        {
            currentState = newState;
            currentState.Enter(this);
        }
    }
コード例 #8
0
    // Cambia el estado del enemigo.
    public void ChangeState(IEnemyState newState)
    {
        // Si ya tiene un estado actual.
        if (currentState != null)
        {
            // Llama a la función de salida del estado.
            currentState.Exit();
        }

        // Establece el estado actual como el nuevo estado.
        currentState = newState;

        // Llama a la función de entrada del estado actual.
        currentState.Enter(this);
    }
コード例 #9
0
    public void GoToNextState(IEnemyState nextState)
    {
        Vector3 distanceVector = m_owner.transform.position - GameObject.FindWithTag("Player").transform.position;

        distanceVector.z = 0;
        float distance = distanceVector.magnitude;

        if (distance > playerDistanceToTeleport)
        {
            nextState = new DashAttackState();
        }
        nextState.OnStateEntered(m_owner);

        m_owner.GetComponent <BouncerStateMachine>().currentState = nextState;
    }
コード例 #10
0
 public WallMaster(int x, int y)
 {
     this.health     = 6;
     this.maxHealth  = 6;
     this.Speed      = 1;                       /*Changeable*/
     this.Size       = 3;                       /************/
     this.position   = new Vector2();
     this.position.X = x;
     this.position.Y = y;
     this.state      = new EStateWallMasterIdleAnimated(this);
     projectiles     = new List <IProjectile>();                  /*Projectiles*/
     hitBox          = new Rectangle(x, y, 16 * Size, 16 * Size);
     hitBox          = new Rectangle(x, y, 16 * Size, 16 * Size);
     this.IsDone     = false;
 }
コード例 #11
0
    //Changes the enemy's state
    public void ChangeState(IEnemyState newState)
    {
        //If we have a current state
        if (currentState != null)
        {
            //Call the exit function on the state
            currentState.Exit();
        }

        //Sets the current state as the new State
        currentState = newState;

        //Calls the enter function on the current state
        currentState.Enter(this);
    }
コード例 #12
0
    public void DeleteState(IEnemyState state)
    {
        if (state == null)
        {
            Debug.LogError("要删除的状态为空");
            return;
        }

        if (mStates.Count == 0 || !mStates.Contains(state))
        {
            Debug.LogError("要删除的状态ID[" + state + "]不存在");
        }

        mStates.Remove(state);
    }
コード例 #13
0
    void Start()
    {
        currentState  = patrolState;
        currentHealth = enemyHealth;

        GameObject playerObject = GameObject.FindWithTag("Player");

        if (playerObject != null)
        {
            chaseTarget = playerObject.transform;
        }
        if (playerObject == null)
        {
            Debug.Log("Cannot find 'Player'");
        }
    }
コード例 #14
0
 void Attack()
 {
     // Debug.DrawRay(attackPoint.transform.position,-direc.normalized,Color.yellow);
     Collider[] obj = Physics.OverlapSphere(attackPoint.transform.position, 1f, LayerMask.GetMask("PlayerLayer"));
     if (obj.Length > 0)
     {
         if (obj[0].tag == "Player")
         {
             currentState = attack;
         }
     }
     else
     {
         anim.SetBool("Attack", false);
     }
 }
コード例 #15
0
        public void Update()
        {
            if (Game1.nightmare && count == 0 && isAlive == false)
            {
                int dx = 100;
                newLocation = WorldManager.spriteSet.players[0].GetLocation();
                location.X  = newLocation.X;
                location.X -= dx;
                count++;
                this.koopaHealth = KoopaHealth.Normal;
                this.koopaState  = new KoopaNightmareState(this);
            }

            koopaSprite.Update();
            koopaState.Update();
        }
コード例 #16
0
    void Start()
    {
        currentState = roamState;

        m_Player = GameObject.FindGameObjectWithTag("Player");
        m_Anim   = GetComponent <Animator>();

        GameObject[] spawns = GameObject.FindGameObjectsWithTag("Spawner");

        foreach (GameObject spawn in spawns)
        {
            spawnPoints.Add(spawn);
        }

        agroUI.enabled = false;
    }
コード例 #17
0
 // Use this for initialization
 void Start()
 {
     /*
      * Set default state of the AI (walking, patroling, guarding)
      * set current state to default state
      *
      *
      *
      *
      *
      */
     currentState = patrolState; //sets the current state
     Path         = Pathways[PathwayCount];
     AIPath CheckpointScript = Path.GetComponent <AIPath>();
     //THIS might not be needed maybe idk lets find out navPoint = CheckpointScript.getPoints()[CheckpointCount];
 }
コード例 #18
0
    // Start is called before the first frame update
    void Start()
    {
        SoundEffectSource = GameObject.Find("SoundEffect Source  2").GetComponent <AudioSource>();

        stunState    = new StunState(this);
        burnState    = new BurnState(this);
        chaseState   = new ChaseState(this);
        currentState = chaseState;

        player     = FindObjectOfType <PlayerController>();
        winManager = FindObjectOfType <WinManager>();

        burnCounter = 0f;

        ChasePlayer();
    }
コード例 #19
0
    private void Awake()
    {
        rb               = GetComponent <Rigidbody2D>();
        sGroup           = GetComponent <SortingGroup>();
        anim             = GetComponent <Animator>();
        sortingTransform = transform.Find("SortingTransform");
        top              = transform.Find("Top");
        idleState        = new IdleState(this);                 // Set enemy states
        aggressiveState  = new AggressiveState(this);
        patrolState      = new PatrolState(this);
        gotHitState      = new GotHitState(this);


        spritesTransform = transform.Find("Sprites");
        oriScale         = spritesTransform.localScale;
        colliders        = spritesTransform.GetComponentsInChildren <Collider2D>();
        Collider2D[] attackCol = colliders.Where(col => col.tag == "EnemyAttackBox").ToArray();
        attackState = new AttackState(this, GetComponent <Collider2D>(), attackCol);

        var spriteChilds = spritesTransform.GetComponentsInChildren <SpriteRenderer>();

        sprites = new EnemySprite[spriteChilds.Length];
        for (int i = 0; i < spriteChilds.Length; i++)
        {
            var _transform = spriteChilds[i].transform;
            var _sprite    = spriteChilds[i];
            var _color     = spriteChilds[i].color;
            sprites[i] = new EnemySprite(_transform, _sprite, _color);
        }

        _animMoveSpeed   = Animator.StringToHash("MoveSpeed");
        _animAttackSpeed = Animator.StringToHash("AttackSpeed");

        anim.SetFloat(_animMoveSpeed, stats.moveSpeed * 0.5f);
        overrideController = new AnimatorOverrideController();
        overrideController.runtimeAnimatorController = anim.runtimeAnimatorController;
        anim.runtimeAnimatorController = overrideController;
        overrideController["BaseWalk"] = walk;
        overrideController["BaseIdle"] = idle;
        if (death.Length > 0)
        {
            overrideController["BaseDeath"] = death[0];
        }
        layers                   = LayerMask.GetMask("StaticWall", "PlayerHitbox");
        stats.moveSpeed         += Random.Range(-0.2f, 0.2f);
        stats.minPathUpdateTime += Random.Range(-0.2f, 0.2f);
    }
コード例 #20
0
ファイル: Sprint3Tests.cs プロジェクト: Sway623/Mario-3902
        public void TestEnemyOnRightOfBlockCollisionHandling()
        {
            IEnemy     enemy       = new Goomba(new Vector2(110, 100));
            Goomba     staticEnemy = new Goomba(new Vector2(100, 100));
            FloorBlock block       = new FloorBlock(new Vector2(100, 100));

            Rectangle enemyRect = enemy.GetRectangle();
            Rectangle blockRect = block.GetRectangle();

            Game1.Side collisionType = Game1.Side.Left;
            EnemyBlockCollisionHandler.HandleCollision(enemy, block, collisionType);

            IEnemyState enemyState    = enemy.GetState();
            IEnemyState expectedState = new GoombaLeftMovingState(staticEnemy);

            Assert.AreEqual(enemyState.ToString(), expectedState.ToString());
        }
コード例 #21
0
ファイル: EnemyFSM.cs プロジェクト: woym2008/PerfectJam
        public void SetState(IEnemyState state)
        {
            //if(m_EnemyStates.Count > 0)
            {
                //m_EnemyStates[m_EnemyStates.Count - 1].Exit();
            }

            if (m_CurState != null)
            {
                m_CurState.Exit();
            }

            state.Enter();

            //m_EnemyStates.Add(state);
            m_CurState = state;
        }
コード例 #22
0
        // Use this for initialization
        void Start()
        {
            chaseState  = new MajorChaseState(this);
            alertState  = new MajorAlertState(this);
            patrolState = new MajorPatrolState(this);
            combatState = new MajorCombatState(this);

            navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();
            anim         = GetComponent <Animator>();
            animHelper   = new AnimationUtilities();

            currentState = patrolState;

            stop = false;

            waypoints = new List <Transform>();
        }
コード例 #23
0
 // Use this for initialization
 private void Start()
 {
     anim         = GetComponent <Animator>();
     currentState = patrolState;//Initializes first state to patrolling
     //if (GetComponent<SkeletonArcher>() != null)
     //{
     //    monsterName = "Skeleton Archer";
     //}
     //if (GetComponent<SkeletonKnight>() != null)
     //{
     //    monsterName = "Skeleton Archer";
     //}
     //if (GetComponent<Slime>() != null)
     //{
     //    monsterName = "Slime";
     //}
     GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("SFX Volume");
 }
コード例 #24
0
        public Necky()
        {
            sprite = EnemySpriteFactory.Instance.CreateDKNeckySprite();
            BodyDefinition bodyDef = new BodyDefinition()
            {
                BottomCenter = new Vector2(425, 300), Type = BodyType.Dynamic, Dimensions = sprite.Dimensions
            };
            Filter filter = new Filter();

            filter.Category = (byte)Filter.Categories.Enemy;
            filter.Mask     = (byte)Filter.Categories.Player + (byte)Filter.Categories.LevelBlock + (byte)Filter.Categories.Throwable;
            bodyDef.Filter  = filter;
            bodyDef.Mass    = MASS;
            body            = PhysicsWorld.Instance.CreateBody(bodyDef);
            body.UserData   = this;
            state           = new EnemyIdleState(this);
            PhysicsWorld.Instance.OnContact += OnContact;
        }
コード例 #25
0
    public void CheckTransitions()
    {
        IEnemyState newState   = null;
        var         enumerator = transitions.GetEnumerator();

        while (newState == null && enumerator.MoveNext())
        {
            if (enumerator.Current.Key.Invoke())
            {
                newState = enumerator.Current.Value;
            }
        }

        if (newState != null)
        {
            context.ChangeState(newState);
        }
    }
コード例 #26
0
ファイル: EnemyFactory.cs プロジェクト: yy2792/c-sharp-mario
        public Enemy build(EnemyType type, Vector2 location)
        {
            if (type == EnemyFactory.EnemyType.Dino)
            {
                state = new LeftTallDinoState();
            }
            if (type == EnemyFactory.EnemyType.Koopa)
            {
                state = new LeftWalkingShellessKS();
            }
            if (type == EnemyFactory.EnemyType.Bill)
            {
                state = new BanzaiBillState();
            }
            Enemy product = new Enemy(location, state);

            return(product);
        }
コード例 #27
0
ファイル: Stalfos.cs プロジェクト: Belair34/3902-Project
 public Stalfos(int x, int y)
 {
     this.health     = 5;
     this.maxHealth  = 5;
     this.Speed      = 2;                       /*Changeable*/
     this.Size       = 3;                       /************/
     this.position   = new Vector2();
     this.position.X = x;
     this.position.Y = y;
     this.state      = new EStateStalfosMovingLeft(this);
     projectiles     = new List <IProjectile>();                  /*Projectiles*/
     hitBox          = new Rectangle(x, y, 15 * Size, 15 * Size);
     numberGenerator = new Random();
     maxTimer        = 100;
     minTimer        = 20;
     movementTimer   = numberGenerator.NextDouble() * maxTimer + minTimer;
     this.IsDone     = false;
 }
コード例 #28
0
ファイル: Enemy.cs プロジェクト: kycshiudev/futureshooter
    private void Update()
    {
        if (player.GetComponent <PlayerCharacter>().dead)
        {
            state = new StopState();
            return;
        }

        var newState = state.HandleTransition(this);

        if (newState != null && !dbugFreeze)
        {
            state.OnExit(this);
            state = newState;
            state.OnEnter(this);
        }
        state.HandleUpdate(this);
    }
コード例 #29
0
    public void ChangeState(IEnemyState newState)
    {
        if (SceneManager.GetActiveScene().name == "Level01_Intro")
        {
            newState = new PatrolState();
        }

        if (currentState != null)
        {
            currentState.Exit();
        }

        currentState = newState;

//        Debug.LogWarning(currentState.ToString());

        currentState.Enter(this);
    }
コード例 #30
0
    //----------------------------

    private void Awake()
    {
        m_enemyInteractable = GetComponent <EnemyInteractable>();
        audioSource         = GetComponent <AudioSource>();
        playerActor         = GameObject.FindObjectOfType <PlayerActor>();
        wantedLevel         = GameObject.FindObjectOfType <WantedLevel>();

        chaseState          = new ChaseState(this);
        alertState          = new AlertState(this);
        patrolState         = new PatrolState(this);
        m_caughtPlayerState = new CaughtPlayerState(this);

        navMeshAgent       = GetComponent <NavMeshAgent>();
        navMeshAgent.speed = standartSpeed;

        enemyAnimator    = GetComponent <Animator>();
        elephantMovement = playerActor.GetComponent <ElephantMovement>();

        if (wayPoints == null)
        {
            wayPoints = new Waypoints()
            {
                points = new[] { transform.position },
                pairs  = new[] { new Pair() }
            }
        }
        ;
    }

    void OnValidate()
    {
        currentState = patrolState;
    }

    void Start()
    {
        currentState = patrolState;

        viewCone.MainViewRadius = toleratedSightrange;
        viewCone.FullViewRadius = sightRange;
        viewCone.FieldOfView    = fieldOfView;

        OnCaught += StatePatternEnemy_OnCaught;
    }
コード例 #31
0
    protected override void Start()
    {
        base.Start();

        if (AttackType == RhythmAttackType.NOTES)
        {
            for (int i = 0; i < attackPeriod.Length; i++)
            {
                attackTime += 60 / (MusicController.bpm * BeatDecimalValues.values[(int)attackPeriod[i]]);
            }
            for (int i = 0; i < waitToAttackPeriod.Length; i++)
            {
                waitToAttackTime += 60 / (MusicController.bpm * BeatDecimalValues.values[(int)waitToAttackPeriod[i]]);
            }
        }

        if (isInSquad)
        {
            if (isLeader)
            {
                Role = Leader;
            }
            else
            {
                Role = Subordinate;
            }

            Role.SquadPlacement(this);
        }
        else
        {
            Role = Independent;
        }

        if (patrolWaypoints != null && patrolWaypoints.Count > 0)
        {
            currentState = patrolState;
        }
        else
        {
            currentState = idleState;
        }
    }
コード例 #32
0
    public void ChangeState(IEnemyState _state)
    {
        if (state != null)
        {
            if (state.id.Equals(_state.id))
            {
                return;
            }
            else
            {
                state.Exit();
            }
        }



        state = _state;
        state.Enter(this);
    }
コード例 #33
0
ファイル: Aquamentus.cs プロジェクト: Belair34/3902-Project
 public Aquamentus(int x, int y, Game1 game)
 {
     this.game       = game;
     this.health     = 20;
     this.maxHealth  = 20;
     this.Speed      = 2;                       /*Changeable*/
     this.Size       = 3;                       /************/
     this.position   = new Vector2();
     this.position.X = x;
     this.position.Y = y;
     this.state      = new EStateAquamentusMovingUp(this, game);
     projectiles     = new List <IProjectile>();                  /*Projectiles*/
     hitBox          = new Rectangle(x, y, 24 * Size, 32 * Size);
     numberGenerator = new Random();
     maxTimer        = 100;
     minTimer        = 20;
     movementTimer   = numberGenerator.NextDouble() * maxTimer + minTimer;
     this.IsDone     = false;
 }
コード例 #34
0
ファイル: EnemyStateManager.cs プロジェクト: Soren025/Zenject
        public void ChangeState(EnemyStates state)
        {
            if (_currentState == state)
            {
                // Already in state
                return;
            }

            //Log.Trace("Enemy Changing state from {0} to {1}", _currentState, state);

            _currentState = state;

            if (_stateHandler != null)
            {
                _stateHandler.Dispose();
                _stateHandler = null;
            }

            _stateHandler = _stateFactory.Create(state);
            _stateHandler.Initialize();
        }
コード例 #35
0
 void Start()
 {
     vacuumBase = transform.position;
     activeState = new WanderState(this);        //First state is wander state
     agent.speed = 10 + manager.gameLevel * 5;      //Sets enemy speed depending on level
 }
コード例 #36
0
 // Update is called once per frame
 void Update()
 {
     navMeshAgent.speed = moveSpeed;
     currentState.UpdateState(); //calls the update of the current state
     if (currentState == distractedState)
     {
         if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance && !navMeshAgent.pathPending)
         {
             currentState = searchingState;
         }
     }
 }
コード例 #37
0
    private void Awake()
    {
        chaseState = new ChaseState(this);
        patrolState = new PatrolState(this);
        guardState = new GuardState(this);
        dazedState = new DazedState(this);
        distractedState = new DistractedState(this);
        searchingState = new SearchingState(this);
        suspiciousState = new SuspiciousState(this);
        koState = new KOState(this);
        walkState = new WalkState(this);
        pointSearchState = new PointSearchState(this);

        navMeshAgent = GetComponent<NavMeshAgent>();
        player = GameObject.FindGameObjectWithTag("Player");
        Path = Pathways[0];
        AIPath CheckpointScript = Path.GetComponent<AIPath>();
        navPoint = CheckpointScript.getPoints()[0];
        currentState = patrolState; //sets the current state
        NoOcclusionLM = 1 << noOcclusionLayer;
        NoOcclusionLM = ~NoOcclusionLM;
    }
コード例 #38
0
ファイル: Ennemy.cs プロジェクト: teamCowboys/CowboyPanPan
 void ChangeState(S index)
 {
     currentState.Stop();
     currentState = state[(int)index];
     currentState.Init(this.gameObject);
 }
コード例 #39
0
ファイル: Ennemy.cs プロジェクト: teamCowboys/CowboyPanPan
 void Awake()
 {
     currentState = state[(int)S.SHOOT];
     isHiding = false;
 }
コード例 #40
0
 public void SwitchState(IEnemyState newState)
 {
     activeState = newState;
 }
コード例 #41
0
 void Start()
 {
     currentState = patrolState;
 }
コード例 #42
0
    /// <summary>
    /// Performs the state transition.
    /// </summary>
    /// <param name="state">State.</param>
    private void PerformStateTransition(string state)
    {
        switch(state)
        {
        case "Patrol":
            this.currentState = patrolState;
            break;
        case "Alert":
            this.currentState = alertState;
            break;
        case "Chase":
            this.currentState = chaseState;
            break;
        }

        //Performs the OnStateEnter method just before exiting to reset state
        currentState.OnStateEnter();
    }
コード例 #43
0
 // Use this for initialization
 void Start()
 {
     anim = GetComponent<AnimationController>();
     patrolState.GetPatrolPoint(15.0);
     currentState = patrolState;
     currentState.OnStateEnter();
 }