示例#1
0
        private IEnumerator Setup(int level)
        {
            int          difficulty   = (int)Mathf.Log(level, 2f);
            MapGenerator mapGenerator = new MapGenerator(mapSize + difficulty);

            while (!mapGenerator.IsEnd())
            {
                mapGenerator.Update();
                yield return(null);
            }

            int[,] chip = mapGenerator.MapChip;

            //Creates the outer walls and floor.
            BoardSetup(chip);

            //Reset our list of gridpositions.
            InitialiseList(chip);

            //Instantiate a random number of wall tiles based on minimum and maximum, at randomized positions.
            LayoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum);

            //Instantiate a random number of food tiles based on minimum and maximum, at randomized positions.
            LayoutObjectAtRandom(foodTiles, foodCount.minimum, foodCount.maximum);

            //Determine number of enemies based on current level number, based on a logarithmic progression
            int enemyCount = (int)(difficulty + mapSize / 5);

            //Instantiate a random number of enemies based on minimum and maximum, at randomized positions.
            LayoutObjectAtRandom(enemyTiles, enemyCount, enemyCount);


            //Instantiate the exit tile in the upper right hand corner of our game board
            //Instantiate (exit, new Vector3 (columns - 1, rows - 1, 0f), Quaternion.identity);

            isSetup = true;
        }
示例#2
0
        void OnTriggerEnter2D(Collider2D triggerCollider)
        {
            //Check if the tag of the trigger is exit and load the next level
            if (triggerCollider.CompareTag("Exit"))
            {
                MapGenerator map = GameObject.Find("MapGenerator").GetComponent <MapGenerator>();
                map.UpdateMapSize(explorationCount);

                int numberofFloorTiles       = GameObject.Find("MapGenerator").GetComponent <MapGenerator>().numberofFloorTiles;
                int mapExplorationPercentage = (int)((float)explorationCount / numberofFloorTiles * 100);
                GameObject.FindWithTag("GameManager").GetComponent <AIMovementSpeed>().updateGenerator(mapExplorationPercentage);

                //Disable the exit collider component so it doesn't continue to trigger
                triggerCollider.GetComponent <Collider2D>().enabled = false;

                //Disable the player since the level is over
                enabled = false;

                //Stop the player from moving
                banditBody.velocity = Vector2.zero;

                //Reset explorationCount for the next level
                explorationCount = 0;

                GameObject.FindWithTag("GameManager").GetComponent <CaveGameManager>().SetDirChanges(dirChanges);
                //GameObject.FindWithTag("GameManager").GetComponent<AIFoodDecrement>().updateGenerator(dirChanges);
                GameObject.FindWithTag("GameManager").GetComponent <AIPlayerDamage>().updateGenerator(weaponSwings);
                GameObject.FindWithTag("GameManager").GetComponent <AIFoodDecrementContinuous>().updateGenerator(dirChanges);
                GameObject.FindWithTag("GameManager").GetComponent <AIWeaponCount>().updateGenerator(weaponSwings);
                GameObject.FindWithTag("GameManager").GetComponent <AIFoodCount>().updateGenerator(flippedCount);
                GameObject.FindWithTag("GameManager").GetComponent <AIEnemyHealth>().updateGenerator(weaponSwings);

                Restart();
            }
            //Check if the tag of the trigger collided with is Food.
            else if (triggerCollider.CompareTag("Fruit"))
            {
                //Add pointsPerFruit to the players current food total.
                food += pointsPerFruit;

                //Update foodText to represent current total and notify player that they gained points
                StartCoroutine(ShowFoodGain(pointsPerFruit));

                //Call the RandomizeSfx function of SoundManager and pass in two eating sounds to choose between to play the eating sound effect.
                SoundManager.instance.RandomizeSfx(eatSound1, eatSound2);

                //Disable the food object the player collided with.
                triggerCollider.gameObject.SetActive(false);
            }

            //Check if the tag of the trigger collided with is Soda.
            else if (triggerCollider.CompareTag("Drink"))
            {
                //Add pointsPerDrink to players food points total
                food += pointsPerDrink;

                //Update foodText to represent current total and notify player that they gained points
                StartCoroutine(ShowFoodGain(pointsPerDrink));

                //Call the RandomizeSfx function of SoundManager and pass in two drinking sounds to choose between to play the drinking sound effect.
                SoundManager.instance.RandomizeSfx(drinkSound1, drinkSound2);

                //Disable the soda object the player collided with.
                triggerCollider.gameObject.SetActive(false);
            }
            else if (triggerCollider.CompareTag("Veg"))
            {
                //Add pointsPerVeg to players food points total
                food += pointsPerVeg;

                //Update foodText to represent current total and notify player that they gained points
                StartCoroutine(ShowFoodGain(pointsPerVeg));;

                //Call the RandomizeSfx function of SoundManager and pass in two eating sounds to choose between to play the eating sound effect.
                SoundManager.instance.RandomizeSfx(eatSound1, eatSound2);

                //Disable the soda object the player collided with.
                triggerCollider.gameObject.SetActive(false);
            }
            else if (triggerCollider.CompareTag("Meat"))
            {
                //Add pointsPerMeat to players food points total
                food += pointsPerMeat;

                //Update foodText to represent current total and notify player that they gained points
                StartCoroutine(ShowFoodGain(pointsPerMeat));

                //Call the RandomizeSfx function of SoundManager and pass in two eating sounds to choose between to play the eating sound effect.
                SoundManager.instance.RandomizeSfx(eatSound1, eatSound2);

                //Disable the soda object the player collided with.
                triggerCollider.gameObject.SetActive(false);
            }
            else if (triggerCollider.CompareTag("Floor"))
            {
                //Add this tile to the exploration count
                explorationCount += 1;

                //Disable the trigger on this tile so it doesn't get added to the count again if the player revisits the tile
                triggerCollider.GetComponent <Collider2D>().enabled = false;
            }

            else if (triggerCollider.CompareTag("Symbol"))
            {
                //Disable the symbol object the player collided with.
                triggerCollider.gameObject.SetActive(false);
            }
        }
        // Start is called before the first frame update
        void Start()
        {
            MapGenerator map = GameObject.Find("MapGenerator").GetComponent <MapGenerator>();

            transform.position = map.randomStartingLocation;
        }