Esempio n. 1
0
        //DamageEnemy is called when the player attacks a enemy.
        IEnumerator DamageEnemy(int loss)
        {
            //Subtract loss from hit point total.
            hp -= loss;
            yield return(new WaitForSeconds(.3f));

            //Call the RandomizeSfx function of SoundManager to play one of two chop sounds.
            SoundManager.instance.RandomizeSfx(chopSound1, chopSound2);

            yield return(new WaitForSeconds(.3f));

            //If hit points are less than or equal to zero:
            healthBar.SetHealth(hp, originalHp);
            if (hp <= 0)
            {
                healthBar.SetHealth(0, originalHp);
                //Disable the gameObject.
                DeleteEnemy();

                if (player.firstKill == false)
                {
                    player.firstKill = true;
                    int level = CaveGameManager.instance.GetLevel();
                    if (level == 6 || level == 11 || level == 16 || level == 21)
                    {
                        float x = transform.position.x + Random.Range(-0.5f, 0.5f);
                        float y = transform.position.y + Random.Range(-0.5f, 0.5f);
                        GameObject.FindWithTag("WeaponManager").GetComponent <WeaponManager>().GenerateWeapon(new Vector2(x, y), false);
                        for (int i = 0; i < 4; i++)
                        {
                            x = transform.position.x + Random.Range(-0.5f, 0.5f);
                            y = transform.position.y + Random.Range(-0.5f, 0.5f);
                            itemSpawn.SpawnItem(x, y, 5, false, 9);
                        }
                    }
                    // spawn food as reward
                    else
                    {
                        SpawnFoodReward();
                    }
                }
                else
                {
                    SpawnFoodReward();
                }
            }
        }
Esempio n. 2
0
        public void GenerateFirstMap()
        {
            if (currentLevelTiles.Count > 1)
            {
                DeleteMap();
            }
            exitCoord              = new Coordinate();
            mapFloorTiles          = new List <Coordinate>();
            mapEdgeTiles           = new List <Coordinate>();
            allMapRooms            = new List <List <Coordinate> >();
            originalRooms          = new List <Room>();
            passageEdgeTiles       = new List <Coordinate>();
            randomStartingLocation = new Vector2();
            itemSpawn              = GameObject.FindWithTag("GameManager").GetComponent <ItemSpawn>();
            GenerateMap();
            GenerateStartAndExit();
            DrawMap();
            int currEnemyCount = 0;

            foreach (Coordinate coord in mapFloorTiles)
            {
                if (UnityEngine.Random.Range(0, 150) >= 7)
                {
                    int randomNumber = UnityEngine.Random.Range(5, 1000);
                    itemSpawn.SpawnItem(-baseWidth / 2 - 0.5f + coord.x, -baseHeight / 2 - 0.5f + coord.y, randomNumber);
                }
                else
                {
                    if (currEnemyCount <= enemyCount)
                    {
                        GameObject enemyChoice = enemyTiles[UnityEngine.Random.Range(0, enemyTiles.Length)];
                        Instantiate(enemyChoice, new Vector2(-baseWidth / 2 - 0.5f + coord.x, -baseHeight / 2 - 0.5f + coord.y), Quaternion.identity);
                        currEnemyCount++;
                    }
                    else
                    {
                        int randomNumber = UnityEngine.Random.Range(5, 1000);
                        itemSpawn.SpawnItem(-baseWidth / 2 - 0.5f + coord.x, -baseHeight / 2 - 0.5f + coord.y, randomNumber);
                    }
                }
            }
        }
Esempio n. 3
0
        public void SpawnFoodReward()
        {
            if (originalHp >= 30)
            {
                float x = transform.position.x + Random.Range(-0.5f, 0.5f);
                float y = transform.position.y + Random.Range(-0.5f, 0.5f);
                GameObject.FindWithTag("WeaponManager").GetComponent <WeaponManager>().GenerateWeapon(new Vector2(x, y));
            }
            // generate fruit
            int foodType;

            if (originalHp >= 0 && originalHp < 20)
            {
                foodType = 4;
            }
            // generate drinks
            else if (originalHp >= 20 && originalHp < 30)
            {
                foodType = 6;
            }
            // generate veg
            else if (originalHp >= 30 && originalHp < 40)
            {
                foodType = 8;
            }
            // generate meat
            else if (originalHp >= 40 && originalHp < 50)
            {
                foodType = 9;
            }
            else
            { //generate weapon
                foodType = -1;
            };
            if (foodType > 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    float x = transform.position.x + Random.Range(-0.5f, 0.5f);
                    float y = transform.position.y + Random.Range(-0.5f, 0.5f);
                    itemSpawn.SpawnItem(x, y, 5, false, foodType);
                }
            }
        }