Example #1
0
    private void HandleMovingState()
    {
        if (ForOnce2)
        {
            foreach (Transform child in transform.parent.gameObject.transform)
            {
                if (null == child)
                {
                    continue;
                }

                if (child.gameObject.GetComponent <EnemyThrow>() != null)
                {
                    ForOnce2 = false;
                    ForOnce  = true;
                    child.gameObject.GetComponent <EnemyThrow>().End();
                }
            }
        }
        if (FightArea)
        {
            eCurState = BossActionType.Attacking;
            return;
        }



        transform.parent.Translate(direction * (speed * Time.deltaTime));    //move towards player
    }
Example #2
0
    void Start()
    {
        //sets the initial values
        movementSpeed    = 20;
        rotationSpeed    = 5;
        shortAttackSpeed = movementSpeed * 2;
        longAttackSpeed  = movementSpeed * 6;

        shortRangeAttackDistance = 7;

        timeCounter = 0;

        rb = GetComponent <Rigidbody>();

        player             = GameObject.FindGameObjectWithTag("Player").transform;
        target             = player.transform;
        distanceFromPlayer = player.position - transform.position;

        attacking       = false;
        preparingAttack = false;

        damageCount = 3;


        aquiredLongRangeTarget = false;

        currentState = BossActionType.CircleArea;
        RandomAction();
    }
Example #3
0
    IEnumerator waitAndDecide()
    {
        stateRunning = true;

        miniCrystals.SetEqualDistance();

        yield return(new WaitForSeconds(2f));

        int choice = Random.Range(0, 4);

        switch (choice)
        {
        case 0:
            curState = BossActionType.BigLaser;
            break;

        case 1:
            curState = BossActionType.SpinLaser;
            break;

        case 2:
            curState = BossActionType.IcicleDrop;
            break;

        case 3:
            curState = BossActionType.ScatterShot;
            break;
        }

        stateRunning = false;
    }
Example #4
0
    private IEnumerator WaitForAction(int seconds)
    {
        yield return(new WaitForSeconds(seconds));

        if (currentState == BossActionType.CircleArea || currentState == BossActionType.FollowPlayer)
        {
            System.Random waitRandom = new System.Random();
            int           action     = waitRandom.Next(1, 3);
            Debug.Log("rand action: " + action);
            //circle area
            if (action == 1)
            {
                currentState = BossActionType.CircleArea;
            }
            //follow player
            else if (action == 2)
            {
                currentState = BossActionType.FollowPlayer;
            }
            //long range attack
            else if (action == 3)
            {
                currentState = BossActionType.LongRangeAttack;
            }
        }
        RandomAction();
    }
Example #5
0
    void Update()
    {
        timer_RandomState += Time.deltaTime;

        if (timer_RandomState > 10)
        {
            int numState = Random.Range(1, 5);


            if (numState == 1)
            {
                eCurStateBoss = BossActionType.Idle;
            }
            if (numState == 2)
            {
                eCurStateBoss = BossActionType.Moving;
            }
            if (numState == 3)
            {
                eCurStateBoss = BossActionType.Patrolling;
            }
            if (numState == 4)
            {
                eCurStateBoss = BossActionType.Follow;
            }
            if (numState == 5)
            {
                eCurStateBoss = BossActionType.Shooting;
            }

            timer_RandomState = 0;
        }

        eCurStateBoss = BossActionType.Shooting;
        //FollowPlayer(maintainDistance, distance);
        //BossNavObj.GetComponent<NavMeshAgent>().SetDestination(player.transform.position);

        switch (eCurStateBoss)
        {
        case BossActionType.Idle:
            HandleIdleState();
            break;

        case BossActionType.Moving:
            HandleMovingState();
            break;

        case BossActionType.Patrolling:
            HandlePatrollingState();
            break;

        case BossActionType.Follow:
            HandleFollowState();
            break;

        case BossActionType.Shooting:
            HandleShootingState();
            break;
        }
    }
Example #6
0
    private IEnumerator BigLaser()
    {
        stateRunning = true;
        SetVulnerable();


        float elapsedTime = 0f;
        float waitTime    = 8f;

        miniCrystals.SetGuarding(waitTime);
        miniCrystals.ShootBigLaser(waitTime);

        miniCrystals.FaceTowards(playerTransform.position);
        while (elapsedTime < waitTime)
        {
            miniCrystals.LerpTowards(playerTransform.position, orbitSpeed / 100f);
            elapsedTime += Time.deltaTime;

            yield return(null);
        }

        miniCrystals.isSpinning = true;

        curState = BossActionType.Idle;
        SetInvulnerable();
        stateRunning = false;
    }
Example #7
0
 protected new void Update()
 {
     if (BossAction == BossActionType.wait)
     {
         if ((transform.position - GameObject.FindWithTag("Player").transform.position).sqrMagnitude < 4)
         {
             Debug.Log((transform.position - GameObject.FindWithTag("Player").transform.position).sqrMagnitude);
             BossAction = BossActionType.acttack;
         }
     }
     if (health <= 0 && BossAction != BossActionType.die)
     {
         c          = 0;
         status     = 0;
         BossAction = BossActionType.die;
         amim.SetBool("die", true);
     }
     if (health > 0 && health <= 24 && BossAction != BossActionType.recover)
     {
         c          = 0;
         status     = 0;
         BossAction = BossActionType.recover;
         damage     = 0;                                   //取消伤害
         GetComponent <Rigidbody2D>().gravityScale = 0;    //取消重力
         GetComponent <Collider2D>().isTrigger     = true; //取消碰撞体
     }
 }
Example #8
0
    //private void HandleAvoidingObstacleState()
    //{

    //}
    //private void HandlePatrollingState()
    //{

    //}
    private void HandleAttackingState()
    {
        if (!FightArea)
        {
            eCurState = BossActionType.Moving;
            return;
        }
        else
        {
            attackTimer += Time.deltaTime;

            if (attackTimer >= attackEnd)
            {
                attackEnable = true;
                attackTimer  = 0;
            }
            if (attackEnable)
            {
                attackEnable = false;
                SwordAnimator.gameObject.SetActive(true);
                SwordAnimator.SetTrigger("EnemyAttackTrigger");
            }
        }

        if (FightArea && Target.transform.position.y > transform.position.y + 3)
        {
            eCurState = BossActionType.JumpTowardsPlayer;
            return;
        }
    }
Example #9
0
    private void TimerA()
    {
        timerA -= Time.deltaTime;

        if (timerA <= 0)
        {
            if (choose % 2 == 0)
            {
                timerA = 10f;

                Vector3 t = ManageDirectionForJump();
                parentRb.AddForce((-t + new Vector3(0, 2, 0)) * 20000);
                eCurState = BossActionType.RangedAttacking;
                choose    = 1;
            }
            else

            if (choose % 2 == 1)
            {
                timerA = 10f;

                eCurState = BossActionType.Moving;
                choose    = 0;
            }
        }
    }
Example #10
0
    //Boss hits border and turns around
    void HitBorder()
    {
        Vector3    relativePos = Vector3.zero - transform.position;
        Quaternion rotation    = Quaternion.LookRotation(relativePos);

        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotationSpeed * Time.deltaTime);
        currentState       = BossActionType.FollowPlayer;
    }
Example #11
0
 void CheckShortRangeDistance()
 {
     if (distanceFromPlayer.magnitude < 10)
     {
         target.position = player.position;
         currentState    = BossActionType.ShortRangeAttack;
     }
 }
Example #12
0
    void HandleIdleState()
    {
        InstaRegenerate();

        if (howFar < 50)
        {
            eCurState = BossActionType.AttackingType0;
        }
    }
Example #13
0
 void DeactivateByDistance()
 {
     if (howFar > 50)
     {
         eCurState = BossActionType.Idle;
         CancelInvoke();
         isAttack = false;
     }
 }
Example #14
0
    private IEnumerator IcicleDrop()
    {
        stateRunning = true;
        SetVulnerable();

        yield return(new WaitForSeconds(icicleManager.IceDrop()));

        curState = BossActionType.Idle;
        SetInvulnerable();
        stateRunning = false;
    }
Example #15
0
    private void Start()
    {
        ForOnce = true;
        timerA  = 15f;
        choose  = 0;

        jumpCooldown = 0f;
        lookRight    = false;
        eCurState    = BossActionType.Moving;
        parentRb     = transform.parent.gameObject.GetComponent <Rigidbody2D>();
    }
Example #16
0
 //Boss has hit the mountain
 void TakeDamage()
 {
     damageCount--;
     if (damageCount == 0)
     {
         currentState = BossActionType.Die;
     }
     else
     {
         currentState = BossActionType.CircleArea;
     }
 }
Example #17
0
 void Wander()
 {
     if (Vector3.Distance(transform.position, wanderPoint) < 0.5f)
     {
         wanderPoint = RandomWanderPoint();
         eCurState   = BossActionType.PowerUp;
     }
     else
     {
         agent.SetDestination(wanderPoint);
     }
 }
Example #18
0
    private IEnumerator ScatterShot()
    {
        stateRunning = true;
        SetVulnerable();
        StartCoroutine(Delay(2f));
        miniCrystals.SetScatter(3f);
        SetInvulnerable();
        yield return(new WaitForSeconds(5f));

        miniCrystals.isSpinning = true;
        curState     = BossActionType.Idle;
        stateRunning = false;
    }
Example #19
0
    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "SphereContainer")
        {
            Debug.Log("hit border");

            currentState = BossActionType.HitBorder;

            if (aquiredLongRangeTarget == true)
            {
                aquiredLongRangeTarget = false;
            }
        }
    }
Example #20
0
    void ShortRangeAttack()
    {
        //look towards the target and move towards it
        float      attackSpeed = movementSpeed * 10;
        Quaternion newRotation = Quaternion.LookRotation(target.position - transform.position);

        transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, rotationSpeed * Time.deltaTime);
        transform.position = Vector3.MoveTowards(transform.position, target.position, shortAttackSpeed * Time.deltaTime);

        //if it reaches the position where the player was, have it circle around
        if (transform.position == target.position)
        {
            currentState = BossActionType.CircleArea;
        }
    }
Example #21
0
    void HandleAttackingType0State()
    {
        if (!isAttack)
        {
            InvokeRepeating("FireType1", 0.5f, 1f);
            isAttack = true;
        }

        if (health < (0.6 * maxHealth))
        {
            CancelInvoke();
            eCurState = BossActionType.AttackingType1;
            isAttack  = false;
        }
    }
Example #22
0
 void HandleAvoidingObstacleState()
 {
     if (!isAttack)
     {
         firstTimeMeas = Time.time;
         degRotate     = 360;
         isImmortal    = true;
         isAttack      = true;
     }
     if (Time.time - firstTimeMeas > 2)
     {
         eCurState  = BossActionType.AttackingType1;
         isAttack   = false;
         isImmortal = false;
         degRotate  = 0;
     }
 }
Example #23
0
    //Boss does a long range attack on the player
    void LongRangeAttack()
    {
        // LineRenderer line = GetComponent<LineRenderer>();

        if (aquiredLongRangeTarget == false)
        {
            CircleArea(40);
            //line.SetPosition(0, transform.position);

            Ray ray = new Ray(transform.position, player.position - transform.position);

            //see if anything hits the ray
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider != null)
                {
                    Debug.Log("collider");
                    //line.SetPosition(1, hit.point);
                    ////kill player if it hits the laser
                    if (hit.collider.gameObject.tag == "Mountain")
                    {
                        Debug.Log("hit mountain");
                    }
                    if (hit.collider.gameObject.tag == "Player")
                    {
                        Debug.Log("hit player");
                        target.position = player.position;
                        transform.LookAt(target.position);
                        aquiredLongRangeTarget = true;
                    }
                }
            }
        }
        else
        {
            Debug.Log("moving");
            transform.Translate(transform.forward * Time.deltaTime * longAttackSpeed, Space.World);
            if (transform.position == target.position)
            {
                currentState           = BossActionType.CircleArea;
                aquiredLongRangeTarget = false;
            }
        }
    }
Example #24
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         Debug.Log("hit player trigger");
         currentState = BossActionType.CircleArea;
         //target.position = player.position;
         //if(aquiredLongRangeTarget == true)
         //{
         //    currentState = BossActionType.ShortRangeAttack;
         //}
     }
     if (other.tag == "Mountain")
     {
         Debug.Log("hit mountain trigger");
         currentState = BossActionType.TakeDamage;
     }
 }
Example #25
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Debug.Log(bulletHits);
        if (health <= 0)
        {
            GameObject x = (GameObject)Instantiate(impactEffect, transform.position, transform.rotation);
            Destroy(gameObject, gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length);
            Destroy(x, x.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length);
            SceneManager.LoadScene("FutureDoneCutscene");
        }
        switch (eCurState)
        {
        case BossActionType.JumpAttack:
            transform.position = new Vector3(startingPosition.x, startingPosition.y + Mathf.PingPong(Time.time, 1), startingPosition.z);
            break;

        case BossActionType.CircleAttack:
            _angle += RotateSpeed * Time.deltaTime;
            var offset = new Vector3(Mathf.Sin(_angle), Mathf.Cos(_angle), 0) * Radius;
            transform.position = startingPosition + offset;
            break;

        case BossActionType.Idle:
            transform.position = startingPosition;
            break;
        }
        if (bulletHits == 4)
        {
            bulletHits = 0;
            if (eCurState == BossActionType.Idle)
            {
                eCurState = BossActionType.JumpAttack;
            }
            else if (eCurState == BossActionType.JumpAttack)
            {
                eCurState = BossActionType.CircleAttack;
            }
            else if (eCurState == BossActionType.CircleAttack)
            {
                eCurState = BossActionType.Idle;
            }
            Attack();
        }
    }
Example #26
0
    void Start()
    {
        boss_TransformLayer = gameObject.transform.parent.gameObject;
        boss_SpriteHolder   = boss_TransformLayer.transform.GetChild(0).gameObject;
        boss_Emitter        = boss_SpriteHolder.transform.GetChild(0).gameObject;
        player = GameObject.Find("Player");

        boss_BulletPool = new GameObject[BULLET_POOL_SIZE];

        // Bullet Pooling Spawn
        for (int i = 0; i < BULLET_POOL_SIZE; i++)
        {
            boss_BulletPool[i] = (GameObject)Instantiate(bulletOrginal, boss_BulletSpawn);
            boss_BulletPool[i].SetActive(false);
        }

        timer_RandomState = 0;
        eCurStateBoss     = BossActionType.Follow;
    }
Example #27
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (gameObject.tag == "Player")
        {
            eCurState = BossActionType.Moving;
        }
        if (gameObject.tag == "Bomb")
        {
            jump      = true;
            eCurState = BossActionType.AvoidingObstacle;
        }
        if (gameObject.tag == "Dangerous")
        {
            Debug.Log("HSK");

            Destroy(gameObject);
            Debug.Log("Dead");
        }
    }
Example #28
0
    // Provádí akce, tak jak jsou uvedeny v kombinaci
    private void StartNextAction()
    {
        _canDealDamage = true;
        _currentActionIndex++;

        if (_currentCombo == null || (_currentActionIndex >= _currentCombo.actions.Length))
        {
            _currentCombo       = ChooseNextCombo();
            _currentActionIndex = _currentWaitTimeIndex = 0;
        }

        BossActionType nextAction = _currentCombo.actions[_currentActionIndex];

        switch (nextAction)
        {
        case BossActionType.Wait:
            ChangeState(Wait(_currentCombo.waitTime[_currentWaitTimeIndex]));
            _currentWaitTimeIndex++;
            break;

        case BossActionType.Swipe:
            ChangeState(Swipe());
            break;

        case BossActionType.GroundSmash:
            ChangeState(GroundSmash());
            break;

        case BossActionType.JumpSmash:
            ChangeState(JumpSmash());
            break;

        case BossActionType.RotateTowardsTarget:
            ChangeState(RotateTowardsTarget());
            break;

        case BossActionType.MoveTowardsTarget:
            ChangeState(MoveTowardsTarget());
            break;
        }
    }
Example #29
0
 void HandleAttackingType2State()
 {
     if (!isAttack)
     {
         firstTimeMeas = Time.time;
         InvokeRepeating("FireType1", 0.5f, 0.4f);
         isAttack = true;
     }
     if (health < (0.1 * maxHealth))
     {
         CancelInvoke();
         eCurState = BossActionType.FinalAction;
         isAttack  = false;
     }
     if (Time.time - firstTimeMeas > 5)
     {
         CancelInvoke();
         eCurState = BossActionType.AvoidingObstacle;
         isAttack  = false;
     }
 }
Example #30
0
    private void BossActions()
    {
        jumpCooldown -= 1 * Time.deltaTime;
        switch (eCurState)
        {
        case BossActionType.RangedAttacking:
            HandleRangedAttackState();
            break;

        case BossActionType.Moving:
            HandleMovingState();
            break;

        //case BossActionType.AvoidingObstacle:
        //    HandleAvoidingObstacleState();
        //    break;

        //case BossActionType.Patrolling:
        //    HandlePatrollingState();
        //    break;

        case BossActionType.Attacking:
            HandleAttackingState();
            break;

        case BossActionType.JumpTowardsPlayer:



            if (jumpCooldown <= 0)
            {
                HandleJumpTowardsPlayerState();
            }


            eCurState = BossActionType.Moving;
            break;
        }
    }