Ejemplo n.º 1
0
        private void MakeBullets()
        {
            if (Time.time > nextFire)
            {
                try
                {
                    _bulletQuantity += 1;

                    //spawn point of bullet
                    Vector3 startPoint = new Vector3(transform.position.x + offsetX, transform.position.y + offsetY, transform.position.z);
                    //shoot bullet
                    ShootInDirection.Shoot(mBullet, 1, degreeDeviation, startPoint, transform.up, mBullet.GetComponent <RicochetBulletMovement>().speed, false);
                    //play sound
                    audioManager.PlaySound(ricochetShotSoundName);

                    if (_bulletQuantity >= maxBulletQuantity)
                    {
                        nextFire        = Time.time + ricochetFireRateLong;
                        _bulletQuantity = 0;
                    }
                    else
                    {
                        nextFire = Time.time + ricochetFireRateShort;
                    }
                }
                catch
                { }
            }
        }
Ejemplo n.º 2
0
        void FixedUpdate()
        {
            //move enemy in direction
            //rb2d.MovePosition(new Vector2(xSpeed + transform.position.x, ySpeed + transform.position.y));
            transform.position += new Vector3(xSpeed, ySpeed, 0);

            //find player GO
            try
            {
                player = GameObject.Find("Player").gameObject;
            }
            catch
            {
                // ignored
            }

            //shoot
            if (willShoot && Time.time >= _nextShoot + shootRate && player != null)
            {
                _nextShoot = Time.time;
                //find vector from enemy to player
                Vector3 distToPlayer = player.transform.position - transform.position - new Vector3(offsetX, offsetY, 0);
                //spawn point of bullet
                Vector3 startPoint = new Vector3(transform.position.x + offsetX, transform.position.y + offsetY, transform.position.z);
                //shoot bullet
                ShootInDirection.ShootEqualSpread(Bullet, bulletQuantity, deviation, startPoint, distToPlayer, bulletSpeed);
                //play sound
                audioManager.PlaySound(bulletSoundName);
            }
        }
Ejemplo n.º 3
0
        void Update()
        {
            if (health <= 0)
            {
                //drop powerup if there is one
                if (powerUp != null)
                {
                    Instantiate(powerUp, transform.position, Quaternion.identity);
                }
                //spawn ricochet bullets
                for (int i = 0; i < ricochetSpawners.Length; i++)
                {
                    //spawn bullets only if ricochet spawner is active
                    if (ricochetSpawners[i].activeSelf)
                    {
                        ShootInDirection.Shoot(ricochetBullet, 1, 0, ricochetSpawners[i].transform.position, ricochetSpawners[i].transform.up, ricochetBullet.GetComponent <RicochetBulletMovement>().speed, true);
                    }
                }
                //destroys enemy gameobject when hp = 0
                Destroy(this.gameObject);

                audioManager.PlaySound(explodeSoundName);
                gameObject.GetComponent <EnemyScore>().AddScore();
                Instantiate(explosion, transform.position, Quaternion.Euler(0, 0, Random.Range(0, 359)));
            }
        }
Ejemplo n.º 4
0
        IEnumerator ShootSnipeLaser()
        {
            yield return(new WaitForSeconds(19f / 60f));

            //snipe from core
            Vector3 spawnPosition1 = coreA.transform.position;
            Vector3 distToPlayer   = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - coreA.transform.position;

            ShootInDirection.Shoot(snipeLaser, 1, 0, coreA.transform.position, distToPlayer, snipeLaser.GetComponent <EnemyBullet2Movement>().moveSpeed, true);
            //play snipe sound
            audioManager.PlaySound(snipeLaserSoundName);
        }
Ejemplo n.º 5
0
        void FixedUpdate()
        {
            //move enemy in direction
            transform.position += new Vector3(xSpeed, ySpeed, 0);

            //shoot
            if (Time.time >= _nextShoot + shootInterval)
            {
                _nextShoot = Time.time;
                ShootInDirection.Shoot(LaserGO, 1, 0, transform.position, transform.right, LaserGO.GetComponent <LaserMovement>().moveSpeed, true);
                ShootInDirection.Shoot(LaserGO, 1, 0, transform.position, -transform.right, LaserGO.GetComponent <LaserMovement>().moveSpeed, true);

                audioManager.PlaySound(laserSoundName);
            }
        }
Ejemplo n.º 6
0
        void FixedUpdate()
        {
            if (!_shoot && Time.time > _nextShoot + shootLaserCooldown)
            {
                _shoot     = true;
                _nextShoot = Time.time;
            }

            if (_shoot)
            {
                _shoot = false;
                ShootInDirection.Shoot(LaserGO, 1, 0, transform.position, shootDirection, LaserGO.GetComponent <LaserMovement>().moveSpeed, true);

                audioManager.PlaySound(laserSoundName);
            }
        }
Ejemplo n.º 7
0
        void FixedUpdate()
        {
            //find player in case player is dead
            try
            {
                if (player == null)
                {
                    player = GameObject.Find("Player").gameObject;
                }
                playerPosition = new Vector2(player.transform.position.x, player.transform.position.y);
            }
            catch
            {
                //player is dead, do nothing
            }

            //move boss
            //float sinMovement = sinAmplitude * Easing.Sinusoidal.InOut(sinCounter);
            if (moveBoss == true)
            {
                transform.position = new Vector3(_bossMovement.x + transform.position.x, _bossMovement.y + transform.position.y, 0);
                //change y direction
                if (transform.position.y >= 3.5f + Camera.main.transform.position.y || transform.position.y >= 1.0f + playerPosition.y)
                {
                    _bossMovement.y = -bossMovement.y * Random.Range(0.7f, 1f);
                }
                else if (transform.position.y <= -3.5f + Camera.main.transform.position.y || transform.position.y <= -1.0f + playerPosition.y)
                {
                    _bossMovement.y = bossMovement.y * Random.Range(0.7f, 1f);
                }

                //change x direction
                if (transform.position.x >= 5f + Camera.main.transform.position.x)
                {
                    _bossMovement.x = -bossMovement.x * Random.Range(0.7f, 1f);
                }
                else if (transform.position.x <= 3f + Camera.main.transform.position.x)
                {
                    _bossMovement.x = bossMovement.x * Random.Range(0.7f, 1f);
                }
            }

            //make cores vulnerable
            if (Time.time > initialCoreTime + coreInvulTime && !isCoreVulnerable)
            {
                isCoreVulnerable = true;
                for (int i = 0; i < coreShieldAnim.Length; i++)
                {
                    coreShieldAnim[i].enabled = true;
                    core[i].transform.tag     = "Enemy";
                }
            }

            switch (bossState)
            {
            case (_bossState.SPAWNING):
                //to change boss phase
                if (Time.time > nextPhaseTime + spawnTime)
                {
                    nextPhaseTime = Time.time;
                    //set boss state
                    bossState = phaseAlgorithm[phaseIndex];
                    phaseIndex++;
                    //let boss move in vertical direction
                    moveBoss            = true;
                    initialBossPosition = transform.position;

                    bossBodyAnim.enabled = false;
                    for (int i = 0; i < coreShieldAnim.Length; i++)
                    {
                        coreShieldAnim[i].Play("BossCoreReveal");
                    }

                    //enable colliders after spawning
                    gameObject.GetComponent <PolygonCollider2D>().enabled = true;
                    for (int i = 0; i < core.Length; i++)
                    {
                        core[i].GetComponent <PolygonCollider2D>().enabled = true;
                    }
                    for (int i = 0; i < blade.Length; i++)
                    {
                        blade[i].GetComponent <PolygonCollider2D>().enabled = true;
                    }
                }
                break;

            case (_bossState.PHASE_1):
                //shooting algorithm
                if (Time.time > nextShoot1 + shootInterval1 && Time.time > firstShot + timeBeforeFirstShot1)
                {
                    //check if shooterIndex is overflowing before shooting
                    if (shooterIndex >= core.Length)
                    {
                        shooterIndex = 0;
                    }
                    //if current selected core is dead, move to next core
                    int coreCursor = 0;
                    while (core[shooterIndex] == null && coreCursor < core.Length)
                    {
                        shooterIndex++;
                        //check if shooterIndex is overflowing before shooting
                        if (shooterIndex >= core.Length)
                        {
                            shooterIndex = 0;
                        }
                        //increase core cursor index
                        ++coreCursor;
                    }
                    nextShoot1 = Time.time;
                    //increase shoot counter for phase check and change
                    currentShootQuantity++;

                    //spread shot from cores to player
                    if (core[shooterIndex] != null)
                    {
                        Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - core[shooterIndex].transform.position;
                        ShootInDirection.ShootEqualSpread(normalBullet, shotQuantity1, deviation1,
                                                          core[shooterIndex].transform.position, distToPlayer, bulletSpeed1);
                        audioManager.PlaySound(spreadBulletSoundName);

                        //increase shooter index to change where bullets are spawned
                        shooterIndex++;
                    }
                    else
                    {
                        Debug.Log("Core is dead");
                    }
                }

                //phase changer
                ChangePhaseOnBullet(maxShootQuantity1, phaseAlgorithm);

                //check if all cores are still alive
                BossDead();
                break;

            case (_bossState.PHASE_2):

                if (!isBladeOpen && Time.time > timeBeforeBladesOpen + bladeTime)
                {
                    isBladeOpen = true;
                    bladeAnim[0].Play("UmletBladeTopOpen");
                    bladeAnim[1].Play("UmletBladeBottomOpen");
                    audioManager.PlaySound(bladeOpenSoundName);
                }

                //shooting algorithm
                if (Time.time > nextShoot1 + shootInterval2 && Time.time > firstShot + timeBeforeFirstShot2)
                {
                    nextShoot1 = Time.time;

                    //shoot once in general direction of player for both shooters
                    for (int i = 0; i < shooters.Length; i++)
                    {
                        Vector3 spawnPosition = shooters[i].transform.position + new Vector3(shooterBulletSpawnOffset.x, shooterBulletSpawnOffset.y, 0);
                        //find vector from enemy to player
                        Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - shooters[shooterIndex].transform.position;
                        ShootInDirection.Shoot(normalBullet, 1, deviation2, spawnPosition, distToPlayer, bulletSpeed2, false);
                        Instantiate(ShootRecoil, spawnPosition, Quaternion.identity);
                    }
                    shooterAnim[0].Play("UmletShooterTopRecoil");
                    shooterAnim[1].Play("UmletShooterBottomRecoil");

                    //play sound
                    audioManager.PlaySound(normalBulletSoundName);
                    //increase shoot quantity
                    currentShootQuantity++;
                }

                //phase changer
                if (ChangePhaseOnBullet(maxShootQuantity2, phaseAlgorithm))
                {
                    isBladeOpen = false;
                    bladeAnim[0].Play("UmletBladeTopClose");
                    bladeAnim[1].Play("UmletBladeBottomClose");
                    audioManager.PlaySound(bladeCloseSoundName);
                }

                //check if all cores are still alive
                BossDead();
                break;

            case (_bossState.PHASE_3):
                //movement
                //sinCounter += sinSpeed;

                //laser shooter at middle core
                if (Time.time > nextShoot1 + shootIntervalLaser3 && Time.time > firstShot + timeBeforeFirstLaser3)
                {
                    nextShoot1 = Time.time;

                    Vector3 spawnPosition = LaserSpawnArea.transform.position;
                    ShootInDirection.Shoot(laser, 1, 0, spawnPosition, Vector2.left, laser.GetComponent <LaserMovement2>().moveSpeed, false);


                    //play sound
                    audioManager.PlaySound(laserSoundName);
                }

                //accel shooter from outer cores
                if (Time.time > nextShoot2 + shootIntervalAccel3 && Time.time > firstShot + timeBeforeFirstAccel3)
                {
                    nextShoot2 = Time.time;
                    //accel from core
                    int _shooterIndex = 0;
                    while (_shooterIndex == 0 || _shooterIndex == 2)
                    {
                        if (core[_shooterIndex] != null)
                        {
                            Vector3 spawnPosition = core[_shooterIndex].transform.position;
                            Vector3 distToPlayer  = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - core[_shooterIndex].transform.position;
                            //shoot accel bullet from core to player
                            ShootInDirection.Shoot(accelBullet, 1, 0, spawnPosition, distToPlayer.normalized, accelBulletSpeed, true);
                        }
                        //increase shooter index
                        _shooterIndex += 2;
                    }
                    //play sound
                    audioManager.PlaySound(accelBulletSoundName);
                    //increase shoot quantity counter
                    currentShootQuantity++;
                }

                //phase changer
                ChangePhaseOnBullet(maxShootQuantity3, phaseAlgorithm);
                //if (ChangePhaseOnBullet(maxShootQuantity3, phaseAlgorithm) && Mathf.Abs(sinMovement) >= 0.99)
                //{
                //    sinCounter = 0;
                //}

                //check if all cores are still alive
                BossDead();
                break;

            case (_bossState.DEAD):
                break;

            case (_bossState.DEBUG_DEAD):
                bossState = _bossState.DEAD;
                moveBoss  = false;
                StartCoroutine(BossDie());
                StartCoroutine(RandomExplosions());
                break;
            }
        }
Ejemplo n.º 8
0
        void FixedUpdate()
        {
            //find player in case player is dead
            try
            {
                if (player == null)
                {
                    player = GameObject.Find("Player").gameObject;
                }
                playerPosition = new Vector2(player.transform.position.x, player.transform.position.y);
            }
            catch
            {
                //player is dead, do nothing
            }

            //add camera movement to miniboss
            transform.position += new Vector3(Camera.main.GetComponent <CameraMovement>().moveSpeed.x, Camera.main.GetComponent <CameraMovement>().moveSpeed.y, 0);

            try
            {
                switch (enemyState)
                {
                case (_enemyState.SPAWNING):
                    //enemy moves in from right into screen then stops
                    transform.position += new Vector3(spawnSpeed.x, spawnSpeed.y, 0);

                    if (Time.time > nextPhaseTime + spawnTime)
                    {
                        nextPhaseTime = Time.time;
                        timeToDespawn = Time.time;
                        enemyState    = _enemyState.ALIVE1;
                    }
                    break;

                case (_enemyState.ALIVE1):
                    //enemy shoots a few ricochet bullets at player a few times before going to alive2
                    //movement
                    if (Time.time > nextMove1 + moveTime1)
                    {
                        nextMove1 = Time.time;
                        if (playerPosition.y < gameObject.transform.position.y)
                        {
                            //move down if player is down
                            rb2d.AddForce(-moveSpeed1);
                        }
                        else if (playerPosition.y >= gameObject.transform.position.y)
                        {
                            //move up if player is up
                            rb2d.AddForce(moveSpeed1);
                        }
                    }
                    //shooting
                    if (Time.time > nextShoot1 + shootDuration1)
                    {
                        nextShoot1 = Time.time;
                        try
                        {
                            //find vector from enemy to player
                            Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - ricochetShooter.transform.position;
                            //spawn point of bullet
                            Vector3 startPoint = new Vector3(ricochetShooter.transform.position.x + offsetRicochet.x, ricochetShooter.transform.position.y + offsetRicochet.y, transform.position.z);
                            //shoot bullets
                            ShootInDirection.ShootEqualSpread(ricochetBullet, numberOfRicochetBullets, degreeDeviation, startPoint, distToPlayer.normalized, ricochetBullet.GetComponent <RicochetBulletMovement>().speed);
                            //play sound
                            audioManager.PlaySound(ricochetSoundName);
                        }
                        catch
                        {
                            //player is dead, do nothing
                        }
                    }
                    //attack phase change
                    if (Time.time > nextPhaseTime + phase1Time)
                    {
                        nextPhaseTime = Time.time;
                        enemyState    = _enemyState.ALIVE2;
                    }
                    //despawn
                    if (Time.time > timeToDespawn + despawnTime)
                    {
                        enemyState = _enemyState.DESPAWN;
                    }
                    break;

                case (_enemyState.ALIVE2):
                    //enemy shoots bullets at player a few times before going back to alive1
                    //shooting
                    if (Time.time > nextShoot2 + shootDuration2)
                    {
                        nextShoot2 = Time.time;
                        try
                        {
                            for (int i = 0; i < normalShooter.Length; i++)
                            {
                                //find vector from enemy to player
                                Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - normalShooter[i].transform.position;
                                //spawn point of bullet
                                Vector3 startPoint = new Vector3(normalShooter[i].transform.position.x + offsetNormal.x, normalShooter[i].transform.position.y + offsetNormal.y, transform.position.z);
                                //instantiate bullet
                                GameObject bullet = (GameObject)Instantiate(normalBullet, startPoint, Quaternion.identity);
                                //set velocity of bullet using unit vector of distance from enemy to player
                                bullet.GetComponent <Rigidbody2D>().velocity = distToPlayer.normalized * normalBulletSpeed;
                                //play sound
                                audioManager.PlaySound(bulletSoundName);
                            }
                        }
                        catch
                        {
                            //player is dead, do nothing
                        }
                    }
                    //attack phase change
                    if (Time.time > nextPhaseTime + phase2Time)
                    {
                        nextPhaseTime = Time.time;
                        enemyState    = _enemyState.ALIVE1;
                    }
                    //despawn
                    if (Time.time > timeToDespawn + despawnTime)
                    {
                        enemyState = _enemyState.DESPAWN;
                    }
                    break;

                case (_enemyState.DESPAWN):
                    //if time elapsed is more than despawn time, enter god mode and move right and get destroyed by out of camera trigger
                    transform.position += new Vector3(despawnSpeed.x, despawnSpeed.y, 0);
                    break;

                case (_enemyState.DEAD):
                    //probably nothing
                    break;
                }
            }
            catch { }
        }
Ejemplo n.º 9
0
        void FixedUpdate()
        {
            //find player in case player is dead
            try
            {
                if (player == null)
                {
                    player = GameObject.Find("Player").gameObject;
                }
                playerPosition = new Vector2(player.transform.position.x, player.transform.position.y);
            }
            catch
            {
                //player is dead, do nothing
            }

            //add camera movement to boss
            if (moveBoss == true)
            {
                transform.position += new Vector3(Camera.main.GetComponent <CameraMovement>().moveSpeed.x, Camera.main.GetComponent <CameraMovement>().moveSpeed.y, 0);
            }

            //rotate core B
            if (rotateCoreB && coreB != null)
            {
                coreB.transform.parent.transform.Rotate(0, 0, rotateSpeed);
            }

            switch (bossState)
            {
            case (_bossState.SPAWNING):
                if (Time.time > nextPhaseTime + spawnTime)
                {
                    nextPhaseTime = Time.time;
                    //set boss state
                    bossState = phaseAAlgorithm[phaseIndex];
                    phaseIndex++;
                    //set core to be vulnerable
                    coreAShieldAnim.Play("BossCoreReveal");
                    coreA.transform.tag = "Enemy";
                    //change core phase
                    //core.GetComponent<RicochetCoreMovement>().enemyState = RicochetCoreMovement._enemyState.PHASE1;
                }
                break;

            case (_bossState.PHASE_A1):
                //shooting algorithm
                if (Time.time > nextShoot1 + shootIntervalA1 && Time.time > firstShot + timeBeforeFirstShotA1)
                {
                    nextShoot1 = Time.time;
                    //increase shoot counter
                    currentShootQuantity++;

                    //find vector from enemy to player
                    Vector3 distToPlayer  = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - outerShooters[shooterIndex].transform.position;
                    Vector3 spawnPosition = outerShooters[shooterIndex].transform.position + new Vector3(bulletSpawnOffset.x, bulletSpawnOffset.y, 0);
                    //shoot
                    ShootInDirection.ShootEqualSpread(ricochetBullet, shotQuantityA1, deviationA1, spawnPosition, distToPlayer, ricochetBullet.GetComponent <RicochetBulletMovement>().speed);
                    //play sound
                    audioManager.PlaySound(ricochetSpreadSoundName);
                    //increase shooter index to change where bullets are spawned
                    shooterIndex++;
                    if (shooterIndex >= outerShooters.Length)
                    {
                        shooterIndex = 0;
                    }
                }

                //phase changer
                ChangePhaseOnBullet(maxShootQuantityA1, phaseAAlgorithm);

                //check core hp for phase B
                CheckCoreHP();
                break;

            case (_bossState.PHASE_A2):
                if (Time.time > nextShoot1 + shootIntervalShortA2 && Time.time > nextShoot2 + shootIntervalLongA2)
                {
                    nextShoot1 = Time.time;

                    //change shoot direction after each 'wave' of shots
                    if (changeShootDirectionA2)
                    {
                        changeShootDirectionA2 = false;
                        _tempRotate            = Quaternion.AngleAxis(Random.Range(-deviationA2, deviationA2), Vector3.forward);
                    }

                    //shoot a few times in mirrored directions for both shooters
                    Vector3 spawnPosition = outerShooters[0].transform.position + new Vector3(bulletSpawnOffset.x, bulletSpawnOffset.y, 0);
                    rotatedUnitVector = _tempRotate * shootDirectionA2.normalized;
                    ShootInDirection.Shoot(ricochetInvulBullet, 1, 0, spawnPosition, rotatedUnitVector.normalized, ricochetInvulBullet.GetComponent <RicochetBulletMovement>().speed, true);

                    spawnPosition     = outerShooters[1].transform.position + new Vector3(bulletSpawnOffset.x, bulletSpawnOffset.y, 0);
                    rotatedUnitVector = Vector2.Reflect(rotatedUnitVector, Vector3.down);
                    ShootInDirection.Shoot(ricochetInvulBullet, 1, 0, spawnPosition, rotatedUnitVector.normalized, ricochetInvulBullet.GetComponent <RicochetBulletMovement>().speed, true);
                    //play sound
                    audioManager.PlaySound(ricochetInvulBulletSoundName);
                    // increase shoot quantity after each 'wave' of shots
                    _shotQuantityA2++;
                    if (_shotQuantityA2 >= shotQuantityA2)
                    {
                        nextShoot2      = Time.time;
                        _shotQuantityA2 = 0;
                        currentShootQuantity++;
                        changeShootDirectionA2 = true;
                    }
                }

                //phase changer
                ChangePhaseOnBullet(maxShootQuantityA2, phaseAAlgorithm);

                //check core hp for phase B
                CheckCoreHP();
                break;

            case (_bossState.PHASE_A3):
                //laser shooter using Laser2D
                if (!isFiringLaser && Time.time > nextShoot1 + timeBeforeFirstLaserA3)
                {
                    isFiringLaser = true;
                    for (int i = 0; i < laser.Length; i++)
                    {
                        laser[i].GetComponent <LaserBeam>().rayDuration = laserDurationA3;
                        laser[i].GetComponent <LaserBeam>().canFire     = true;
                    }
                    //play charge up sound
                    audioManager.PlaySound(chargeUpSoundName);
                }

                //snipe shooter
                if (Time.time > nextShoot2 + shootIntervalSnipeA3 && Time.time > firstShot + timeBeforeFirstSnipeA3)
                {
                    nextShoot2 = Time.time;

                    chargeUpAnim.Play("ChargeUp");
                    //snipe from core
                    StartCoroutine(ShootSnipeLaser());
                    //play charge up sound
                    audioManager.PlaySound(chargeUpSoundName);
                    //increasse shoot quantity counter
                    currentShootQuantity++;
                }

                //phase changer
                ChangePhaseOnTime(laserDurationA3 + timeBeforeFirstLaserA3, phaseAAlgorithm);

                //check core hp for phase B
                CheckCoreHP();
                break;

            case (_bossState.PHASE_B_INITIALIZE):
                //accel core B rotation
                rotateSpeed += rotateAccel;

                if (Time.time > nextPhaseTime + timeBeforeMove)
                {
                    //redirect camera
                    Camera.main.GetComponent <CameraMovement>().moveSpeed = new Vector2(-0.024f, 0f);
                    //set core to be vulnerable
                    coreBShieldAnim.Play("BossCoreReveal");
                    coreB.transform.tag = "Enemy";
                    //set boss state
                    bossState = phaseBAlgorithm[phaseIndex];
                    moveBoss  = true;
                    phaseIndex++;
                }
                break;

            case (_bossState.PHASE_B1):
                //shooting algorithm
                if (Time.time > nextShoot1 + shootIntervalA1 && Time.time > firstShot + timeBeforeFirstShotB1)
                {
                    nextShoot1 = Time.time;
                    //increase shoot counter
                    currentShootQuantity++;

                    if (shooterIndex == 0)
                    {
                        rotatedUnitVector = Quaternion.AngleAxis(Random.Range(-deviationB1, deviationB1), Vector3.forward) * shootDirectionB1.normalized;
                    }
                    else
                    {
                        rotatedUnitVector = Vector2.Reflect(rotatedUnitVector, Vector3.down);
                    }

                    //shoot at direction
                    Vector3 spawnPosition = outerShooters[shooterIndex].transform.position + new Vector3(bulletSpawnOffset.x, bulletSpawnOffset.y, 0);
                    ShootInDirection.ShootEqualSpread(ricochetBullet, shotQuantityB1, deviationB1, spawnPosition, rotatedUnitVector.normalized, ricochetBullet.GetComponent <RicochetBulletMovement>().speed);
                    //play sound
                    audioManager.PlaySound(ricochetSpreadSoundName);
                    //increase shooter index to change where bullets are spawned
                    shooterIndex++;
                    if (shooterIndex >= outerShooters.Length)
                    {
                        shooterIndex = 0;
                    }
                }

                //phase changer
                ChangePhaseOnBullet(maxShootQuantityB1, phaseBAlgorithm);

                //check if boss is dead
                BossDead();
                break;

            case (_bossState.PHASE_B2):
                //laser shooter using Laser2D
                if (!isFiringLaser && Time.time > nextShoot1 + timeBeforeLaserB2)
                {
                    isFiringLaser = true;
                    for (int i = 0; i < laser.Length; i++)
                    {
                        laser[i].GetComponent <LaserBeam>().rayDuration = phaseB2Time;
                        laser[i].GetComponent <LaserBeam>().canFire     = true;
                    }
                    //play charge up sound
                    audioManager.PlaySound(chargeUpSoundName);
                }

                //ricochet shooter
                if (Time.time > nextShoot2 + shootIntervalSnipeB2 && Time.time > firstShot + timeBeforeFirstShotB2)
                {
                    nextShoot2 = Time.time;
                    //shoot from core
                    Vector3 spawnPosition1 = coreB.transform.position;
                    Vector3 distToPlayer   = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - coreB.transform.position;
                    ShootInDirection.Shoot(spreadBullet, 1, deviationB2, coreB.transform.position, distToPlayer, spreadBullet.GetComponent <RicochetBulletMovement>().speed, true);
                    //play sound
                    audioManager.PlaySound(ricochetSlowBulletSoundName);
                    //increase shoot quantity counter
                    currentShootQuantity++;
                }

                //phase changer
                ChangePhaseOnTime(phaseB2Time + timeBeforeFirstShotB2, phaseBAlgorithm);

                //check if boss is dead
                BossDead();
                break;

            case (_bossState.PHASE_B3):
                //spread shooting
                if (Time.time > nextShoot1 + shootIntervalB3 && Time.time > firstShot + timeBeforeFirstShotB3)
                {
                    nextShoot1 = Time.time;
                    //shoot from core
                    Vector3 spawnPosition = coreB.transform.position;
                    ShootInDirection.Shoot(spreadBullet, 1, deviationB3, spawnPosition, Vector3.left, spreadBullet.GetComponent <RicochetBulletMovement>().speed, false);
                    //play sound
                    audioManager.PlaySound(ricochetSlowBulletSoundName);
                }

                //phase changer
                ChangePhaseOnTime(phaseB3Time + timeBeforeFirstShotB3, phaseBAlgorithm);

                //check if boss is dead
                BossDead();
                break;

            case (_bossState.DEAD):
                break;
            }
        }
Ejemplo n.º 10
0
        void FixedUpdate()
        {
            //get player position
            try
            {
                player = GameObject.Find("Player").gameObject;
            }
            catch
            {
            }

            //add accel/decel movement to enemy
            _accelPower        += _accel * Time.deltaTime;
            transform.position += new Vector3(0, -_accelPower, 0);

            //state machine
            switch (enemyState)
            {
            case _enemyState.DECELERATING:
                //change phase
                if (_accelPower <= 0)
                {
                    _accel     = 0;
                    enemyState = _enemyState.STOPPED;
                    _nextShoot = Time.time - shootInterval;
                    _nextMove  = Time.time;
                }
                break;

            case _enemyState.STOPPED:
                //shoot laser
                if (Time.time >= _nextShoot + shootInterval)
                {
                    _nextShoot = Time.time;
                    try
                    {
                        player = GameObject.Find("Player").gameObject;
                    }
                    catch
                    {
                    }
                    try
                    {
                        //find vector from enemy to player
                        Vector3 distToPlayer = player.transform.position - transform.position;
                        //shoot
                        ShootInDirection.Shoot(LaserStarGO, 1, 0, transform.position, distToPlayer, LaserStarGO.GetComponent <LaserSpinMovement>().moveSpeed, true);
                        //play sound
                        audioManager.PlaySound(laserSoundName);
                    }
                    catch
                    {
                    }
                }

                //change phase
                if (Time.time >= _nextMove + timeBeforeMove)
                {
                    enemyState = _enemyState.ACCELERATING;
                }
                break;

            case _enemyState.ACCELERATING:
                _accel = acceleration;
                break;
            }
        }
Ejemplo n.º 11
0
        void FixedUpdate()
        {
            //find player in case player is dead
            try
            {
                if (player == null)
                {
                    player = GameObject.Find("Player").gameObject;
                }
                //test
                player = GameObject.Find("Player").gameObject;

                playerPosition = new Vector2(player.transform.position.x, player.transform.position.y);
            }
            catch
            {
                //player is dead, do nothing
            }

            //add camera movement to boss
            //transform.position += new Vector3(Camera.main.GetComponent<CameraMovement>().moveSpeed.x, Camera.main.GetComponent<CameraMovement>().moveSpeed.y, 0);

            //check cores for phase change
            if (bossSuperstate == _bossState.SPAWNING || bossSuperstate == _bossState.DEAD)
            {
                //do nothing
            }
            else if (bossSuperstate != _bossState.DEAD && outerCores[0].gameObject == null && outerCores[1].gameObject == null && innerCores[0].gameObject == null && innerCores[1].gameObject == null && centerCore == null)
            {
                bossSuperstate = _bossState.DEAD;
                StartCoroutine(BossDie());
                StartCoroutine(RandomExplosions());
            }
            else if (!hasBeenA && bossSuperstate != _bossState.PHASE_A && outerCores[0].gameObject != null && outerCores[1].gameObject != null && innerCores[0].gameObject != null && innerCores[1].gameObject != null && centerCore != null)
            {
                hasBeenA       = true;
                bossSuperstate = _bossState.PHASE_A;
                StartCoroutine(InvulBoss());
                //reset all variables
                currentShootQuantity = 0;
                shooterIndex         = 0;
                phaseIndex           = 1;
                nextShoot1           = Time.time + phaseChangeInvulDuration;
                nextShoot2           = Time.time + phaseChangeInvulDuration;
                nextPhaseTime        = Time.time + phaseChangeInvulDuration;
            }
            else if (!hasBeenF && bossSuperstate != _bossState.PHASE_F && outerCores[0].gameObject == null && outerCores[1].gameObject == null && innerCores[0].gameObject == null && innerCores[1].gameObject == null && centerCore != null)
            {
                hasBeenF       = true;
                hasBeenC       = true;
                bossSuperstate = _bossState.PHASE_F;
                StartCoroutine(InvulBoss());
                //reset all variables
                currentShootQuantity = 0;
                shooterIndex         = 0;
                phaseIndex           = 0;
                nextShoot1           = Time.time + phaseChangeInvulDuration;
                nextShoot2           = Time.time + phaseChangeInvulDuration;
                nextPhaseTime        = Time.time + phaseChangeInvulDuration;
            }
            else if (!hasBeenD && bossSuperstate != _bossState.PHASE_D && outerCores[0].gameObject == null && outerCores[1].gameObject == null && centerCore == null)
            {
                hasBeenD       = true;
                hasBeenB       = true;
                hasBeenC       = true;
                bossSuperstate = _bossState.PHASE_D;
                StartCoroutine(InvulBoss());
                //reset all variables
                currentShootQuantity = 0;
                shooterIndex         = 0;
                phaseIndex           = 1;
                nextShoot1           = Time.time + phaseChangeInvulDuration;
                nextShoot2           = Time.time + phaseChangeInvulDuration;
                nextPhaseTime        = Time.time + phaseChangeInvulDuration;
            }
            else if (!hasBeenE && bossSuperstate != _bossState.PHASE_E && innerCores[0].gameObject == null && innerCores[1].gameObject == null && centerCore == null)
            {
                hasBeenE       = true;
                hasBeenB       = true;
                bossSuperstate = _bossState.PHASE_E;
                StartCoroutine(InvulBoss());
                //reset all variables
                currentShootQuantity = 0;
                shooterIndex         = 0;
                phaseIndex           = 1;
                nextShoot1           = Time.time + phaseChangeInvulDuration;
                nextShoot2           = Time.time + phaseChangeInvulDuration;
                nextPhaseTime        = Time.time + phaseChangeInvulDuration;
            }
            else if (!hasBeenB && bossSuperstate != _bossState.PHASE_B && centerCore == null)
            {
                hasBeenB       = true;
                bossSuperstate = _bossState.PHASE_B;
                StartCoroutine(InvulBoss());
                //reset all variables
                currentShootQuantity = 0;
                shooterIndex         = 0;
                phaseIndex           = 1;
                nextShoot1           = Time.time + phaseChangeInvulDuration;
                nextShoot2           = Time.time + phaseChangeInvulDuration;
                nextPhaseTime        = Time.time + phaseChangeInvulDuration;
            }
            else if (!hasBeenC && bossSuperstate != _bossState.PHASE_C && outerCores[0].gameObject == null && outerCores[1].gameObject == null)
            {
                hasBeenC       = true;
                bossSuperstate = _bossState.PHASE_C;
                StartCoroutine(InvulBoss());
                //reset all variables
                currentShootQuantity = 0;
                shooterIndex         = 0;
                phaseIndex           = 1;
                nextShoot1           = Time.time + phaseChangeInvulDuration;
                nextShoot2           = Time.time + phaseChangeInvulDuration;
                nextPhaseTime        = Time.time + phaseChangeInvulDuration;
            }

            switch (bossSuperstate)
            {
            case (_bossState.SPAWNING):
                //change phase
                if (Time.time > nextPhaseTime + spawnTime)
                {
                    nextPhaseTime = Time.time;

                    bossSuperstate = _bossState.PHASE_A;

                    bossSubstateA = phaseAAlgorithm[phaseIndex];
                    ++phaseIndex;
                }
                break;

            case (_bossState.PHASE_A):
                switch (bossSubstateA)
                {
                case (_bossStateA.PHASE_1):
                    //laser shooter
                    if (!hasShotA1 && Time.time >= nextPhaseTime + firstShootA1)
                    {
                        hasShotA1 = true;
                        GameObject _shooter = Instantiate(laserShooter, centerCore.transform.position, transform.rotation);
                        _shooter.transform.parent = gameObject.transform;

                        audioManager.PlaySound(laserShooterSoundName);

                        ShieldBoss();
                    }

                    //change phase
                    if (Time.time >= nextPhaseTime + invulTimeA1 + firstShootA1)
                    {
                        UnshieldBoss();

                        hasShotA1 = false;

                        currentShootQuantity = 0;
                        shooterIndex         = 0;
                        if (phaseIndex >= phaseAAlgorithm.Length)
                        {
                            phaseIndex = 0;
                        }
                        bossSubstateA = phaseAAlgorithm[phaseIndex];
                        phaseIndex++;
                        nextShoot1    = Time.time;
                        nextShoot2    = Time.time;
                        nextPhaseTime = Time.time;
                    }
                    break;

                case (_bossStateA.PHASE_2):
                    //spread shoot
                    if (Time.time >= shootIntervalA2 + nextShoot1 + firstShootA2)
                    {
                        nextShoot1 = Time.time - firstShootA2;

                        //change bullet spawn position
                        if (innerCores[0].gameObject == null)
                        {
                            shooterIndex = 1;
                        }
                        else if (innerCores[1].gameObject == null)
                        {
                            shooterIndex = 0;
                        }

                        if (innerCores[shooterIndex].gameObject != null)
                        {
                            Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - innerCores[shooterIndex].transform.position;
                            ShootInDirection.ShootEqualSpread(bigBullet, shotQuantityA2, deviationA2, innerCores[shooterIndex].transform.position, distToPlayer, bulletSpeedA2);
                        }

                        audioManager.PlaySound(bigBulletSoundName);

                        //change bullet spawn position
                        if (innerCores[0].gameObject == null)
                        {
                            shooterIndex = 1;
                        }
                        else if (innerCores[1].gameObject == null)
                        {
                            shooterIndex = 0;
                        }
                        else if (shooterIndex == 0)
                        {
                            ++shooterIndex;
                        }
                        else
                        {
                            shooterIndex = 0;
                        }

                        ++currentShootQuantity;
                    }

                    ChangePhaseAOnBullet(maxShootQuantityA2, phaseAAlgorithm);
                    break;

                case (_bossStateA.PHASE_3):
                    //missile
                    if (Time.time >= shootIntervalA3 + nextShoot1 + firstShootA3)
                    {
                        nextShoot1 = Time.time - firstShootA3;

                        for (int i = 0; i < 2; i++)
                        {
                            if (outerCores[i].gameObject != null)
                            {
                                Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - outerCores[i].transform.position;
                                Instantiate(homingMissile, outerCores[i].transform.position, Quaternion.Euler(0, 0, 180f));
                            }
                        }

                        audioManager.PlaySound(homingMissileSoundName);

                        ++currentShootQuantity;
                    }

                    ChangePhaseAOnBullet(maxShootQuantityA3, phaseAAlgorithm);
                    break;
                }
                break;

            case (_bossState.PHASE_B):
                switch (bossSubstateB)
                {
                case (_bossStateB.PHASE_1):
                    //spread shoot
                    if (Time.time >= shootIntervalB1 + nextShoot1 + firstShootB1)
                    {
                        nextShoot1 = Time.time - firstShootB1;

                        //change bullet spawn position
                        if (innerCores[0].gameObject == null)
                        {
                            shooterIndex = 1;
                        }
                        else if (innerCores[1].gameObject == null)
                        {
                            shooterIndex = 0;
                        }

                        if (innerCores[shooterIndex].gameObject != null)
                        {
                            Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - innerCores[shooterIndex].transform.position;
                            ShootInDirection.ShootEqualSpread(bigBullet, shotQuantityA2, deviationA2, innerCores[shooterIndex].transform.position, distToPlayer, bulletSpeedA2);
                        }

                        audioManager.PlaySound(bigBulletSoundName);

                        //change bullet spawn position
                        if (innerCores[0].gameObject == null)
                        {
                            shooterIndex = 1;
                        }
                        else if (innerCores[1].gameObject == null)
                        {
                            shooterIndex = 0;
                        }
                        else if (shooterIndex == 0)
                        {
                            ++shooterIndex;
                        }
                        else
                        {
                            shooterIndex = 0;
                        }

                        ++currentShootQuantity;
                    }

                    ChangePhaseBOnBullet(maxShootQuantityB1, phaseBAlgorithm);
                    break;

                case (_bossStateB.PHASE_2):
                    //missile
                    if (Time.time >= shootIntervalB2 + nextShoot1 + firstShootB2)
                    {
                        nextShoot1 = Time.time - firstShootB2;

                        for (int i = 0; i < 2; i++)
                        {
                            if (outerCores[i].gameObject != null)
                            {
                                Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - outerCores[i].transform.position;
                                Instantiate(homingMissile, outerCores[i].transform.position, Quaternion.Euler(0, 0, 180f));
                            }
                        }

                        audioManager.PlaySound(homingMissileSoundName);

                        ++currentShootQuantity;
                    }

                    ChangePhaseBOnBullet(maxShootQuantityB2, phaseBAlgorithm);
                    break;

                case (_bossStateB.PHASE_3):
                    //bomb
                    if (!hasShotB3 && Time.time >= nextPhaseTime + firstShootB3)
                    {
                        hasShotB3 = true;
                        for (int i = 0; i < 2; i++)
                        {
                            if (outerCores[i].gameObject != null)
                            {
                                GameObject _bomb = Instantiate(bomb, outerCores[i].transform.position, transform.rotation);
                                //_bomb.transform.parent = gameObject.transform;
                            }
                        }

                        audioManager.PlaySound(bombSoundName);

                        ShieldBoss();
                    }

                    //change phase
                    if (Time.time >= nextPhaseTime + invulTimeB3 + firstShootB3)
                    {
                        UnshieldBoss();

                        hasShotB3 = false;

                        currentShootQuantity = 0;
                        shooterIndex         = 0;
                        if (phaseIndex >= phaseBAlgorithm.Length)
                        {
                            phaseIndex = 0;
                        }
                        bossSubstateB = phaseBAlgorithm[phaseIndex];
                        phaseIndex++;
                        nextShoot1    = Time.time;
                        nextShoot2    = Time.time;
                        nextPhaseTime = Time.time;
                    }

                    break;
                }
                break;

            case (_bossState.PHASE_C):
                switch (bossSubstateC)
                {
                case (_bossStateC.PHASE_1):
                    //spread shoot
                    if (Time.time >= shootIntervalC1 + nextShoot1 + firstShootC1)
                    {
                        nextShoot1 = Time.time - firstShootC1;

                        //change bullet spawn position
                        if (innerCores[0].gameObject == null)
                        {
                            shooterIndex = 1;
                        }
                        else if (innerCores[1].gameObject == null)
                        {
                            shooterIndex = 0;
                        }

                        if (innerCores[shooterIndex].gameObject != null)
                        {
                            Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - innerCores[shooterIndex].transform.position;
                            ShootInDirection.ShootEqualSpread(bigBullet, shotQuantityC1, deviationC1, innerCores[shooterIndex].transform.position, distToPlayer, bulletSpeedC1);
                        }

                        audioManager.PlaySound(bigBulletSoundName);

                        //change bullet spawn position
                        if (innerCores[0].gameObject == null)
                        {
                            shooterIndex = 1;
                        }
                        else if (innerCores[1].gameObject == null)
                        {
                            shooterIndex = 0;
                        }
                        else if (shooterIndex == 0)
                        {
                            ++shooterIndex;
                        }
                        else
                        {
                            shooterIndex = 0;
                        }

                        ++currentShootQuantity;
                    }

                    ChangePhaseCOnBullet(maxShootQuantityC1, phaseCAlgorithm);
                    break;

                case (_bossStateC.PHASE_2):

                    //laser shooter
                    if (!hasShotC2 && Time.time >= nextPhaseTime + firstShootC2)
                    {
                        hasShotC2 = true;
                        GameObject _shooter = Instantiate(laserShooter, centerCore.transform.position, transform.rotation);
                        _shooter.transform.parent = gameObject.transform;

                        audioManager.PlaySound(laserShooterSoundName);

                        ShieldBoss();
                    }

                    //change phase
                    if (Time.time >= nextPhaseTime + invulTimeC2 + firstShootC2)
                    {
                        UnshieldBoss();

                        hasShotC2 = false;

                        currentShootQuantity = 0;
                        shooterIndex         = 0;
                        if (phaseIndex >= phaseCAlgorithm.Length)
                        {
                            phaseIndex = 0;
                        }
                        bossSubstateC = phaseCAlgorithm[phaseIndex];
                        phaseIndex++;
                        nextShoot1    = Time.time;
                        nextShoot2    = Time.time;
                        nextPhaseTime = Time.time;
                    }
                    break;
                }
                break;

            case (_bossState.PHASE_D):
                //spread shoot
                if (Time.time >= shootIntervalD + nextShoot1 + firstShootD)
                {
                    nextShoot1 = Time.time - firstShootD;

                    //change bullet spawn position
                    if (innerCores[0].gameObject == null)
                    {
                        shooterIndex = 1;
                    }
                    else if (innerCores[1].gameObject == null)
                    {
                        shooterIndex = 0;
                    }

                    if (innerCores[shooterIndex].gameObject != null)
                    {
                        Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - innerCores[shooterIndex].transform.position;
                        ShootInDirection.Shoot(bigBullet, shotQuantityD, deviationD, innerCores[shooterIndex].transform.position, distToPlayer, bulletSpeedD, true);
                    }

                    audioManager.PlaySound(bigBulletSoundName);

                    //change bullet spawn position
                    if (innerCores[0].gameObject == null)
                    {
                        shooterIndex = 1;
                    }
                    else if (innerCores[1].gameObject == null)
                    {
                        shooterIndex = 0;
                    }
                    else if (shooterIndex == 0)
                    {
                        ++shooterIndex;
                    }
                    else
                    {
                        shooterIndex = 0;
                    }

                    ++currentShootQuantity;
                }
                break;

            case (_bossState.PHASE_E):
                switch (bossSubstateE)
                {
                case (_bossStateE.PHASE_1):
                    //missile
                    if (Time.time >= shootIntervalE1 + nextShoot1 + firstShootE1)
                    {
                        nextShoot1 = Time.time - firstShootE1;

                        for (int i = 0; i < 2; i++)
                        {
                            if (outerCores[i].gameObject != null)
                            {
                                Vector3 distToPlayer = new Vector3(playerPosition.x, playerPosition.y, transform.position.z) - outerCores[i].transform.position;
                                Instantiate(homingMissile, outerCores[i].transform.position, Quaternion.Euler(0, 0, 180f));
                            }
                        }

                        audioManager.PlaySound(homingMissileSoundName);

                        ++currentShootQuantity;
                    }

                    ChangePhaseEOnBullet(maxShootQuantityE1, phaseEAlgorithm);
                    break;

                case (_bossStateE.PHASE_2):
                    //bomb
                    if (!hasShotE2 && Time.time >= nextPhaseTime + firstShootE2)
                    {
                        hasShotE2 = true;
                        for (int i = 0; i < 2; i++)
                        {
                            if (outerCores[i].gameObject != null)
                            {
                                GameObject _bomb = Instantiate(bomb, outerCores[i].transform.position, transform.rotation);
                                //_bomb.transform.parent = gameObject.transform;
                            }
                        }

                        audioManager.PlaySound(bombSoundName);

                        ShieldBoss();
                    }

                    //change phase
                    if (Time.time >= nextPhaseTime + invulTimeE2 + firstShootE2)
                    {
                        UnshieldBoss();

                        hasShotE2 = false;

                        currentShootQuantity = 0;
                        shooterIndex         = 0;
                        if (phaseIndex >= phaseEAlgorithm.Length)
                        {
                            phaseIndex = 0;
                        }
                        bossSubstateE = phaseEAlgorithm[phaseIndex];
                        phaseIndex++;
                        nextShoot1    = Time.time;
                        nextShoot2    = Time.time;
                        nextPhaseTime = Time.time;
                    }
                    break;
                }
                break;

            case (_bossState.PHASE_F):
                //rotating laser shooter
                if (Time.time >= shootIntervalF + nextShoot1 + firstShootF)
                {
                    nextShoot1 = Time.time - firstShootF;
                    GameObject _shooter = Instantiate(rotatingLaserShooter, centerCore.transform.position, transform.rotation);
                    _shooter.transform.parent = gameObject.transform;

                    audioManager.PlaySound(laserShooterSoundName);
                }
                break;

            case (_bossState.DEAD):
                //do nothing for now
                break;
            }
        }