Esempio n. 1
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Enemy")
     {
         SCR_Enemy scrEnemy = other.gameObject.GetComponent <SCR_Enemy>();
         scrEnemy.Damage();
         Destroy(gameObject);
     }
 }
Esempio n. 2
0
    private GameObject SpawnEnemy()
    {
        int wave = SCR_Gameplay.instance.currentWave - 1;

        if (wave > SCR_Config.NUMBER_ENEMIES.Length - 1)
        {
            wave = SCR_Config.NUMBER_ENEMIES.Length - 1;
        }

        int choose = ChooseEnemy(wave);

        if (SCR_Truck.timeFromLastSpawn < SCR_Config.TRUCK_SPAWN_GAP_TIME)
        {
            while (choose == ENEMY_TRUCK)
            {
                choose = ChooseEnemy(wave);
            }
        }

        if (choose == ENEMY_TRUCK)
        {
            SCR_Truck.timeFromLastSpawn = 0;
        }

        GameObject prefab   = SCR_Gameplay.instance.PFB_ENEMY[choose];
        GameObject enemy    = Instantiate(prefab);
        SCR_Enemy  scrEnemy = enemy.GetComponent <SCR_Enemy>();

        enemy.transform.parent = transform;

        float marginX = scrEnemy.GetSpawnMarginX();
        float marginY = scrEnemy.GetSpawnMarginY();

        enemy.transform.position = new Vector3(
            Random.Range(-SCR_Gameplay.screenWidth * 0.5f + marginX, SCR_Gameplay.screenWidth * 0.5f - marginX),
            SCR_Gameplay.screenHeight * 0.5f + marginY,
            enemy.transform.position.z);

        SCR_Gameplay.instance.spawnCount++;
        if (SCR_Gameplay.instance.spawnCount >= SCR_Config.NUMBER_ENEMIES[wave])
        {
            SCR_Gameplay.instance.spawningEnemies = false;
            SCR_Gameplay.instance.gapTime         = 0;
        }

        return(enemy);
    }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        timeShowAds += Time.unscaledDeltaTime;

        if (state == GameState.PLAY)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                venom.GetComponent <SCR_Venom>().Attack(pos.x, pos.y);

                RaycastHit2D[] hits = Physics2D.RaycastAll(pos, Vector2.zero);

                foreach (RaycastHit2D hit in hits)
                {
                    SCR_Enemy scrEnemy = hit.collider.GetComponent <SCR_Enemy>();
                    if (scrEnemy != null)
                    {
                        if (scrEnemy.state == EnemyState.RUN)
                        {
                            scrEnemy.Die();
                            IncreaseScore();
                        }
                    }
                }
            }

            /*
             * if (Input.GetMouseButtonDown(1)) {
             *      venom.GetComponent<Animator>().SetTrigger("special");
             *      source.PlayOneShot(sndUltimate);
             * }
             */
            if (spawningEnemies)
            {
                spawnTime -= Time.deltaTime;
                if (spawnTime <= 0)
                {
                    float r = Random.Range(0f, 100f);
                    if (r < SCR_Config.RATE_PATTERN_2)
                    {
                        SpawnPattern(PatternType.TWO);
                    }
                    else if (r < SCR_Config.RATE_PATTERN_2 + SCR_Config.RATE_PATTERN_3)
                    {
                        SpawnPattern(PatternType.THREE);
                    }
                    else if (r < SCR_Config.RATE_PATTERN_2 + SCR_Config.RATE_PATTERN_3 + SCR_Config.RATE_PATTERN_LINE)
                    {
                        SpawnPattern(PatternType.LINE);
                    }
                    else
                    {
                        SpawnPattern(PatternType.ONE);
                    }
                    spawnTime = Random.Range(SCR_Config.SPAWN_TIME_MIN, SCR_Config.SPAWN_TIME_MAX);
                }
            }
            else if (currentWave >= 1)
            {
                gapTime += Time.deltaTime;
                if (gapTime >= SCR_Config.WAVE_GAP_TIME)
                {
                    SpawnWave(currentWave + 1);
                }
            }

            SCR_Truck.timeFromLastSpawn += Time.deltaTime;
        }

        if (state == GameState.READY)
        {
            if (Input.GetMouseButtonDown(0))
            {
                cvsMainMenu.SetActive(false);
                cvsGameplay.SetActive(true);
                txtScore.SetActive(true);
                SpawnWave(1);
                venom.GetComponent <Animator>().SetTrigger("ultimate");
                source.PlayOneShot(sndUltimate);
                ZoomCamera();
                source.clip = sndGameplay;
                source.Play();
                state = GameState.PLAY;
            }
        }

        if (state == GameState.FINISH)
        {
            if (Input.GetMouseButtonDown(0))
            {
                SceneManager.LoadScene("SCN_Gameplay");
            }
        }
    }