Beispiel #1
0
    protected void Fire()
    {
        if (hammer.cocked && !barrel.isOut)
        {
            // check cylinder to be fired, check filled for fire / blank
            bool firedBullet = barrel.GetCurrentCylinder().Expel();
            hammer.Reset();
            if (firedBullet)
            {
                muzzleFlash.Flash();
                Camera.main.GetComponent <CameraBehavior>().Shake();
                audioSource.PlayOneShot(SoundManager.LoadSoundClip("shot" + Random.Range(1, 3)));

                Vector3 dir = (body.sightPoint - Camera.main.transform.position) * 100f;

                Debug.DrawRay(body.sightPoint, dir, Color.red, 100f);

                int        layerMask = 1 << LayerMask.NameToLayer("Enemies");
                RaycastHit hit       = new RaycastHit();
                if (Physics.Raycast(body.sightPoint, dir, out hit, 100f, layerMask))
                {
                    SlimeEnemy slime = hit.transform.gameObject.GetComponent <SlimeEnemy>();
                    slime.Damage(100);
                    score += 1;
                }
            }
            else
            {
                audioSource.PlayOneShot(SoundManager.LoadSoundClip("dryfire"));
            }
        }
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        SlimeEnemy slimeEnemy = collision.collider.GetComponent <SlimeEnemy>();

        if (slimeEnemy != null)
        {
            takeDamage(slimeEnemy.damage);
        }
    }
Beispiel #3
0
    private void SpawnMonsters()
    {
        for (int i = 0; i < 12; i++)
        {
            while (true)
            {
                int x = Random.Range(0, generatorInstance.GetWorldSize().x);
                int y = Random.Range(0, generatorInstance.GetWorldSize().y - 34);

                // Dont spawn on top of the player or right next to them
                if (generatorSpec.GetSpawn().x > x - 5 && generatorSpec.GetSpawn().x < x + 5)
                {
                    continue;
                }
                if (generatorInstance.IsValidMonsterSpawn(new Vector2Int(x, y)))
                {
                    SlimeEnemy slime = Instantiate(slimeEnemyPrefab, new Vector2(x, y), Quaternion.identity);
                    slime.SetLightColor(Random.ColorHSV());
                    break;
                }
            }
        }

        for (int i = 0; i < 6; i++)
        {
            while (true)
            {
                int x = Random.Range(0, generatorInstance.GetWorldSize().x);
                int y = Random.Range(0, generatorInstance.GetWorldSize().y - 34);

                // Dont spawn on top of the player or right next to them
                if (generatorSpec.GetSpawn().x > x - 5 && generatorSpec.GetSpawn().x < x + 5)
                {
                    continue;
                }
                if (generatorInstance.IsValidMonsterSpawn(new Vector2Int(x, y)))
                {
                    DopplerEnemy doppler = Instantiate(dopplerEnemyPrefab, new Vector2(x, y), Quaternion.identity);
                    doppler.gameManager = this;
                    break;
                }
            }
        }
        SpiderEnemy spider = Instantiate(spiderEnemyPrefab, new Vector2(31, 146), Quaternion.identity);

        spider.gameManager = this;
    }
Beispiel #4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        AudioSource.PlayClipAtPoint(audioSource, GameObject.FindGameObjectWithTag("Player").transform.position, 10);
        SlimeEnemy slimeEnemy = collision.GetComponent <SlimeEnemy>();

        if (slimeEnemy != null)
        {
            slimeEnemy.TakeDamage(damage);
        }
        SlimeBoss slimeBoss = collision.GetComponent <SlimeBoss>();

        if (slimeBoss != null)
        {
            slimeBoss.TakeDamage(damage);
        }

        Destroy(gameObject);
    }