Esempio n. 1
0
    private static AttackEnemyState instance; //Static instance of the state

    private AttackEnemyState()                //Constructor for the state
    {
        if (instance != null)                 //If we already have an instance of this state, we don't need another one
        {
            return;
        }
        instance = this;
    }
Esempio n. 2
0
 void Recover()
 {
     RecoveryTime -= Time.deltaTime;
     animator.SetBool("isRecovering", true);
     if (RecoveryTime <= 0)
     {
         RecoveryTime = RECOVERYTIMER;
         animator.SetBool("isRecovering", false);
         nextEnemyState = AttackEnemyState.ENEMY_WAIT;
     }
 }
Esempio n. 3
0
 void Wait()
 {
     if (Vector2.Distance(gameObject.transform.position, target.position) <= m_MaxDistance)
     {
         animator.SetBool("isMoving", true);
         nextEnemyState = AttackEnemyState.ENEMY_CLOSEDISTANCE;
     }
     else
     {
         animator.SetBool("isMoving", false);
     }
 }
Esempio n. 4
0
 void Awake()
 {
     attackBox.enabled = false;
     AttackTimer       = ATTACKTIMER;
     RecoveryTime      = RECOVERYTIMER;
     enemyState        = AttackEnemyState.ENEMY_WAIT;
     nextEnemyState    = AttackEnemyState.ENEMY_WAIT;
     damaged           = false;
     IFrameTime        = IFRAME_TIME;
     target            = Player.transform;
     pouch             = (GoldPouch)gameObject.GetComponent <GoldPouch>();
     m_RigidBody2D     = (Rigidbody2D)gameObject.GetComponent <Rigidbody2D>();
     animator          = (Animator)gameObject.GetComponent <Animator>();
 }
Esempio n. 5
0
            private void InitEventCallBack()
            {
                MovePointEnemyState initMoveState = GetState("P0_MoveToUpCenter") as MovePointEnemyState;

                if (initMoveState != null)
                {
                    initMoveState.OnStateEnd += P0_MoveToUpCenter;
                }

                MoveEnemyState moveState = GetState("P1_Move") as MoveEnemyState;

                if (moveState != null)
                {
                    moveState.OnStateEnd += AddMoveTimes;
                    moveState.OnStateEnd += P1_MoveTransition;
                }

                AttackEnemyState attackState = GetState("P1_MatrixAttack") as AttackEnemyState;

                if (attackState != null)
                {
                    attackState.OnStateEnd += AddAttackTimes;
                    attackState.OnStateEnd += P1_AttackTransition;
                }

                AlignAttackEnemyState alignAttackState = GetState("P2_AlignAttack") as AlignAttackEnemyState;

                if (alignAttackState != null)
                {
                    alignAttackState.OnStateEnd += AddAlignAttackTimes;
                    alignAttackState.OnStateEnd += P2_AlignAttackTransition;
                }

                MoveAttackEnemyState sectorMoveAttState = GetState("P2_SectorMoveAttack") as MoveAttackEnemyState;

                if (sectorMoveAttState != null)
                {
                    sectorMoveAttState.OnStateEnd += AddSectorMoveAttackTimes;
                    sectorMoveAttState.OnStateEnd += P2_SectorMoveAttackTransition;
                }

                MovePointEnemyState P3InitMoveState = GetState("P3_MoveToUpCenter") as MovePointEnemyState;

                if (initMoveState != null)
                {
                    P3InitMoveState.OnStateEnd += P3_MoveToUpCenterTransition;
                }
            }
Esempio n. 6
0
 void CloseDistance()
 {
     if (Vector2.Distance(gameObject.transform.position, target.position) > m_MinDistance && Vector2.Distance(gameObject.transform.position, target.position) <= m_MaxDistance)
     {
         FacePlayer();
         m_RigidBody2D.position = Vector2.MoveTowards(m_RigidBody2D.position, new Vector2(target.position.x, m_RigidBody2D.position.y), m_Speed * Time.deltaTime);
     }
     else if (Vector2.Distance(gameObject.transform.position, target.position) <= m_MinDistance)
     {
         nextEnemyState = AttackEnemyState.ENEMY_ATTACK;
     }
     else if (Vector2.Distance(gameObject.transform.position, target.position) > m_MaxDistance)
     {
         nextEnemyState = AttackEnemyState.ENEMY_WAIT;
     }
 }
Esempio n. 7
0
    // Constructor
    public RecruitmentPattern(Unit unit)
    {
        _unit = unit;

        waitBehavior    = new WaitBehavior(_unit);
        seekBehavior    = new SeekBehavior(_unit);
        pursuitBehavior = new PursuitBehavior(_unit);

        waitState           = new WaitState(this, waitBehavior);
        followLeaderState   = new FollowLeaderState(this, seekBehavior);
        holdPositionState   = new HoldPositionState(this, waitBehavior);
        defendPositionState = new DefendPositionState(this, pursuitBehavior);
        attackEnemyState    = new AttackEnemyState(this, pursuitBehavior);
        attackTargetState   = new AttackLeaderTargetState(this, seekBehavior);
        workState           = new WorkState(this, waitBehavior);

        currentState = waitState;
    }
Esempio n. 8
0
 void Attack()
 {
     animator.SetBool("isAttacking", true);
     AttackTimer -= Time.deltaTime;
     if (AttackTimer <= BeginAttackFrames && AttackTimer > EndAttackFrames)
     {
         attackBox.enabled = true;
     }
     else if (AttackTimer <= EndAttackFrames && AttackTimer > 0)
     {
         attackBox.enabled = false;
     }
     else if (AttackTimer <= 0)
     {
         AttackTimer = ATTACKTIMER;
         animator.SetBool("isAttacking", false);
         nextEnemyState = AttackEnemyState.ENEMY_RECOVER;
     }
 }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        if (!state.m_IsDead)
        {
            switch (enemyState)
            {
            case AttackEnemyState.ENEMY_WAIT: Wait();
                break;

            case AttackEnemyState.ENEMY_CLOSEDISTANCE: CloseDistance();
                break;

            case AttackEnemyState.ENEMY_ATTACK: Attack();
                break;

            case AttackEnemyState.ENEMY_RECOVER: Recover();
                break;
            }

            enemyState = nextEnemyState;
            if (damaged)
            {
                if (IFrameTime > 0)
                {
                    IFrameTime -= Time.deltaTime;
                }
                else
                {
                    IFrameTime = IFRAME_TIME;
                    damaged    = false;
                }
            }
        }
        target = Player.transform;
        EnemyActive();
    }