public Salve getSalve()
    {
        if (salveList.Count > 0)
        {
            for (int i = 0; i < salveList.Count; i++)
            {
                if (!salveList[i].gameObject.activeInHierarchy)
                {
                    Debug.Log("Use salve");
                    return(salveList[i]);
                }
            }
        }

        if (notEnoughtProjectiles)
        {
            Debug.Log("New salve");
            Salve newSalve = Instantiate(salvePrefab);
            newSalve.gameObject.SetActive(false);
            for (int i = 0; i < newSalve.projectiles.Length; i++)
            {
                newSalve.projectiles[i].gameObject.SetActive(false);
            }

            salveList.Add(newSalve);
            return(newSalve);
        }

        Debug.Log("Null");
        return(null);
    }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     //Busca o Jogador
     Usuario = GameObject.FindGameObjectWithTag("Player");
     //Busca o Salve do Jogo
     Salvador = GameObject.FindGameObjectWithTag("GameController").GetComponent <Salve>();
     //Faz o jogo iniciar em tempo 1
     Time.timeScale = 1;
 }
    public void initializePool(int numberOfProjectile)
    {
        for (int i = 0; i < numberOfProjectile; i++)
        {
            Salve newSalve = Instantiate(salvePrefab);
            newSalve.gameObject.SetActive(false);
            for (int j = 0; j < newSalve.projectiles.Length; j++)
            {
                newSalve.projectiles[j].gameObject.SetActive(false);
            }

            salveList.Add(newSalve);
        }
    }
    public void Start()
    {
        animator = gameObject.GetComponent <Animator>();
        col      = GetComponent <CapsuleCollider2D>();
        salve    = GetComponentInParent <Salve>();

        if (isAccelerating && !isDeccelerating)
        {
            accDecCoroutine = Acceleration();
            StartCoroutine(accDecCoroutine);
        }
        if (isDeccelerating && !isAccelerating)
        {
            accDecCoroutine = Decceleration();
            StartCoroutine(accDecCoroutine);
        }

        //Destroy(gameObject, 15);
    }
Exemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     Salvador = GameObject.FindGameObjectWithTag("GameController").GetComponent <Salve>();
 }
    IEnumerator BurstFire()
    {
        yield return(new WaitForSeconds(0.1f));

        //Looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.playDefaultSoundEffect();
        }

        // rate of fire in weapons is in rounds per minute (RPM), therefore we should calculate how much time passes before firing a new round in the same burst.
        for (int i = 0; i < nbrBullet; i++)
        {
            animator.Play("Firing");

            //Mono sound effect
            if (!soundEffectsGenerator.isLooping)
            {
                soundEffectsGenerator.playDefaultSoundEffect();
            }

            //Calculate angle
            float angle = angleViseur - 90 + Random.Range(-deviationFactor, deviationFactor);

            //Change turret angle
            transform.rotation = Quaternion.Euler(new Vector3(0, 0, angleViseur - 90));

            //Set bullet position and turret rotation according to its angle
            Vector3 bulletPosition = new Vector3(transform.position.x, transform.position.y, 0);

            //Create salve gameobject
            Salve salve = new Salve();
            salve = pooler.getSalve();
            salve.transform.position = bulletPosition;
            salve.transform.rotation = Quaternion.Euler(new Vector3(0, 0, (angleViseur - 90) + Random.Range(-deviationFactor, deviationFactor)));
            salve.gameObject.SetActive(true);

            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].transform.localPosition = salve.projectilesInitialPosition[j];
                salve.projectiles[j].transform.localRotation = salve.projectilesInitialRotation[j];
                salve.projectiles[j].gameObject.SetActive(true);
                salve.projectiles[j].col.enabled = true;
            }

            //Initialize objects stats
            salve.globalDamage      = damage;
            salve.globalHealth      = bulletHealth;
            salve.globalBulletSpeed = bulletSpeed;
            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].damage      = salve.globalDamage;
                salve.projectiles[j].health      = salve.globalHealth;
                salve.projectiles[j].bulletSpeed = salve.globalBulletSpeed;
            }

            yield return(new WaitForSeconds(fireRate)); // wait till the next round
        }

        if (maxAmmo > 0) //Turret with ammunitions
        {
            actualAmmo -= nbrBullet;
            animator.Play("OnCD");

            if (cooldownTimer == 0)
            {
                cooldownTimer = cooldown;
            }
        }
        else //Normal turret
        {
            animator.Play("OnCD");
            cooldownTimer = cooldown;
        }

        //Stop looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.stopSoundEffect();
        }

        //Reset viseur
        if (viseur != null)
        {
            viseur.GetComponent <Animator>().Play("Idle");
            viseur.isLocked = false;
        }

        lockMode = false;
        isFiring = false;

        //Overdrive reverse boost stats
        if (turretOverdriveActivated)
        {
            switch (descritpion.projectileType)
            {
            case ProjectileType.Laser:
                bulletSpeed /= 1.5f;
                break;

            case ProjectileType.Kinetic:
                nbrBullet /= 2;
                break;

            case ProjectileType.Ion:
                bulletSpeed /= 2f;
                break;

            case ProjectileType.Plasma:
                break;

            case ProjectileType.Shield:
                bulletHealth /= 2;
                break;

            case ProjectileType.Missile:
                break;
            }
            turretOverdriveActivated = false;
        }
    }
Exemplo n.º 7
0
    IEnumerator BurstFire()
    {
        yield return(new WaitForSeconds(0.1f));

        //Looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.playDefaultSoundEffect();
        }

        // rate of fire in weapons is in rounds per minute (RPM), therefore we should calculate how much time passes before firing a new round in the same burst.
        for (int i = 0; i < nbrBullet; i++)
        {
            animator.Play("Firing");

            //Mono sound effect
            if (!soundEffectsGenerator.isLooping)
            {
                soundEffectsGenerator.playDefaultSoundEffect();
            }

            //Set bullet position and turret rotation according to its angle
            Vector3 bulletPosition = new Vector3(transform.position.x, transform.position.y, 0);

            //Create salve gameobject
            Salve salve = new Salve();
            if (descritpion.turretSize == TurretSize.Standard)
            {
                Debug.Log("Create frontal salve");
                salve = pooler.getSalve();
                salve.transform.position = bulletPosition;
                salve.transform.rotation = Quaternion.Euler(new Vector3(0, 0, -90 + Battleship.current.transform.eulerAngles.z + Random.Range(-deviationFactor, deviationFactor)));
            }
            salve.gameObject.SetActive(true);

            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].transform.localPosition = salve.projectilesInitialPosition[j];
                salve.projectiles[j].transform.localRotation = salve.projectilesInitialRotation[j];
                salve.projectiles[j].gameObject.SetActive(true);
                salve.projectiles[j].col.enabled = true;
            }

            //Initialize objects stats
            salve.globalDamage      = damage;
            salve.globalHealth      = bulletHealth;
            salve.globalBulletSpeed = bulletSpeed;
            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].damage      = salve.globalDamage;
                salve.projectiles[j].health      = salve.globalHealth;
                salve.projectiles[j].bulletSpeed = salve.globalBulletSpeed;
            }

            yield return(new WaitForSeconds(fireRate)); // wait till the next round
        }

        if (maxAmmo > 0) //Turret with ammunitions
        {
            actualAmmo -= nbrBullet;
            animator.Play("OnCD");

            if (cooldownTimer == 0)
            {
                cooldownTimer = cooldown;
            }
        }
        else //Normal turret
        {
            animator.Play("OnCD");
            cooldownTimer = cooldown;
        }

        //Stop looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.stopSoundEffect();
        }

        isFiring = false;
    }
Exemplo n.º 8
0
    public IEnumerator BurstFire()
    {
        yield return(new WaitForSeconds(0.1f));

        // rate of fire in weapons is in rounds per minute (RPM), therefore we should calculate how much time passes before firing a new round in the same burst.

        //Looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.playDefaultSoundEffect();
        }

        for (int i = 0; i < nbrShots; i++)
        {
            //Mono sound effect
            if (!soundEffectsGenerator.isLooping)
            {
                soundEffectsGenerator.playDefaultSoundEffect();
            }

            //Calculate angle
            float angle = 0;
            if (targetingType == TargetingType.circle)
            {
                angle = angleViseur + 90 + Random.Range(-precisionFactor, precisionFactor);
            }
            else if (targetingType == TargetingType.front)
            {
                angle = -90 + Random.Range(-precisionFactor, precisionFactor);
            }

            //Calculate position
            Vector3 bulletPosition = new Vector3(transform.position.x, transform.position.y, 1);

            //Generate salve object
            Salve salve = new Salve();
            salve = pooler.getSalve();
            salve.transform.position = bulletPosition;
            salve.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
            salve.gameObject.SetActive(true);
            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].transform.localPosition = salve.projectilesInitialPosition[j];
                salve.projectiles[j].transform.localRotation = salve.projectilesInitialRotation[j];
                salve.projectiles[j].gameObject.SetActive(true);
                salve.projectiles[j].col.enabled = true;
            }

            //Initiate object stats
            salve.globalDamage      = globalDamage;
            salve.globalHealth      = globalHealth;
            salve.globalBulletSpeed = globalBulletSpeed;
            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].damage      = globalDamage;
                salve.projectiles[j].health      = globalHealth;
                salve.projectiles[j].bulletSpeed = globalBulletSpeed;
            }

            yield return(new WaitForSeconds(fireRate)); // wait till the next round
        }

        //Stop looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.stopSoundEffect();
        }

        ennemy.isMoving = true;
        isFiring        = false;
        cooldownTimer   = cooldown;
    }