コード例 #1
0
ファイル: EnemyManager.cs プロジェクト: chloir/NexusRe
    private void Awake()
    {
        _stateManager = GetComponent <StateManager>();
        _enemyIdle    = GetComponent <EnemyIdle>();

        _stateManager.SetInitialState(_enemyIdle);
    }
コード例 #2
0
ファイル: Cat.cs プロジェクト: Hansen-L/Roguelike
    // Start is called before the first frame update
    void Start()
    {
        #region Configuring State Machine

        _animator       = GetComponent <Animator>();
        _spriteRenderer = GetComponent <SpriteRenderer>();
        _rb             = GetComponent <Rigidbody2D>();
        _stateMachine   = new StateMachine();

        var randomMoving       = new RandomMoving(this, _animator, _rb);
        var enemyIdle          = new EnemyIdle(this, _animator, _rb);
        var enemyDashAttacking = new EnemyDashAttacking(this, _animator, _rb);

        // Assigning transitions
        At(randomMoving, enemyIdle, IsIdle());
        At(enemyIdle, randomMoving, IsMoving());

        _stateMachine.AddAnyTransition(enemyDashAttacking, IsInRangeAndAttackReady());
        At(enemyDashAttacking, enemyIdle, IsNotAttacking());

        // Starting state
        _stateMachine.SetState(enemyIdle);

        // Method to assign transitions easily
        void At(IState to, IState from, Func <bool> condition) => _stateMachine.AddTransition(to, from, condition);

        #endregion

        health = MaxHealth;
    }
コード例 #3
0
        private void Awake()
        {
            _stateMachine = new StateMachine();

            var idle   = new EnemyIdle(this);
            var attack = new EnemyAttack(this);
            var move   = new EnemyMove(this, _rigidbody);
            var death  = new EnemyDeath(this, _collider);

            At(idle, move, hasTarget());
            At(move, idle, lostTarget());

            At(move, attack, reachedTarget());

            At(attack, idle, lostTarget());
            At(attack, move, targetOutOfRange());

            At(idle, death, isDead());
            At(move, death, isDead());
            At(attack, death, isDead());

            Func <bool> hasTarget() => () => Target != null;
            Func <bool> lostTarget() => () => Target == null;
            Func <bool> reachedTarget() => () => Vector2.Distance(transform.position, Target.transform.position) < attackRange - 0.5f;
            Func <bool> targetOutOfRange() => () => Target != null && Vector2.Distance(transform.position, Target.transform.position) > attackRange - 0.5f;
            Func <bool> isDead() => () => health <= 0;

            void At(IState from, IState to, Func <bool> condition) => _stateMachine.AddTransition(from, to, condition);

            _stateMachine.SetState(idle);
        }
コード例 #4
0
    private void Awake()
    {
        enemyFleeFrom    = new EnemyFleeFrom(this);
        enemyIdle        = new EnemyIdle(this);
        enemyScaredState = new EnemyScaredState(this);

        navMeshAgent = GetComponent <NavMeshAgent> ();
    }
コード例 #5
0
 protected void Awake()
 {
     rb           = GetComponent <Rigidbody2D>();
     hitboxes     = GetComponentsInChildren <Collider2D>();
     dormant      = new EnemyDormant(this.gameObject, this);
     idle         = new EnemyIdle(gameObject, this);
     approach     = new EnemyApproach(gameObject, this);
     attack       = new EnemyAttack(gameObject, this);
     hitState     = new EnemyHit(gameObject, this);
     currentState = idle;
 }
コード例 #6
0
    private void InitStateMachine()
    {
        m_StateMachine = new StateMachine <Enemy>();

        enemyDie     = new EnemyDie(m_StateMachine);
        enemyFall    = new EnemyFall(m_StateMachine);
        enemyFlee    = new EnemyFlee(m_StateMachine);
        enemyIdle    = new EnemyIdle(m_StateMachine);
        enemyJumping = new EnemyJumping(m_StateMachine);
        enemyWalk    = new EnemyWalk(m_StateMachine);
    }
コード例 #7
0
    void Awake()
    {
        context = new StageContext();
        speed   = 2.0f;

        playerEntity = GameObject.FindGameObjectsWithTag("Player")[0];

        huntPlayerStrategy = huntObj.GetComponent <HuntPlayer>();
        enemyIdleStrategy  = idleObj.GetComponent <EnemyIdle>();
        patrolZoneStrategy = patrolObj.GetComponent <PatrolZone>();
        huntPlayerStrategy.setPlayerAndRigidBody(playerEntity, rb);
        enemyIdleStrategy.setPlayerAndRigidBody(playerEntity, rb);
        patrolZoneStrategy.setPlayerAndRigidBody(playerEntity, rb);

        animator = GetComponent <Animator>();

        currentState = EnemyState.Patrol;
        context.setStrategy(enemyIdleStrategy);
        context.executeStrategy();
    }
コード例 #8
0
ファイル: RBCNexus.cs プロジェクト: Xannada/Securi-T-Cell
    void OnTriggerEnter(Collider col)
    {
        if (col.transform.CompareTag("Ally"))
        {
            RBCPathing RBC = col.transform.GetComponent <RBCPathing>();
            if (RBC)
            {
                RBC.SetTarget(GiveNextPath());
            }
        }
        else
        {
            EnemyIdle ei = col.transform.GetComponent <EnemyIdle>();

            if (ei && ei.isActiveAndEnabled)
            {
                ei.SetTarget(GiveNextPath());
            }
        }
    }
コード例 #9
0
    public override void _Ready()
    {
        _collision_layer = 2;
        ((Area)FindNode("MeleAttackArea")).SetCollisionMaskBit(1, true);        // monitor only player

        var state_spawn     = new OneShotAnim("spawn");
        var state_chase     = new EnemyChase();
        var state_idle      = new EnemyIdle();
        var state_telegraph = new EnemyTelegraph();
        var state_attack    = new EnemyAttack();

        var tr_spawn_finished      = new FromOneShotAnim(state_idle, "spawn");
        var tr_to_chase            = new EnemyToChase(state_chase);
        var tr_to_idle             = new EnemyToIdle(state_idle);
        var tr_start_telegraph     = new EnemyStartTelegraph(state_telegraph);
        var tr_telegraph_finished  = new FromOneShotAnim(state_attack, "telegraph");
        var tr_telegraph_interrupt = new EnemyInterruptTelegraph(state_idle);
        var tr_attack_finished     = new FromOneShotAnim(state_idle, "attack");

        state_spawn.AddTransition(tr_spawn_finished);
        state_chase.AddTransition(tr_to_idle);
        state_chase.AddTransition(tr_start_telegraph);
        state_idle.AddTransition(tr_to_chase);
        state_idle.AddTransition(tr_start_telegraph);
        state_telegraph.AddTransition(tr_telegraph_finished);
        state_telegraph.AddTransition(tr_telegraph_interrupt);
        state_attack.AddTransition(tr_attack_finished);

        _fsm = new FSM(this, state_spawn);
        _fsm.AddTransition(new EnemyDie(new EnemyDead()));

        // temp
        Attributes.RunSpeed   = 10;
        Attributes.MaxHealth  = Attributes.Health = 20;
        Attributes.Damage     = 10;
        Attributes.CritChance = 0.1f;
    }