Beispiel #1
0
        //Start overrides the Start function of MovingObject
        protected override void Start()
        {
            //Get a component reference to the Player's animator component
            // diff = GameObject.Find("DifficultyLevel").GetComponent<Player>();

            animator = GetComponent <Animator>();
            //playerHealth = GameObject.Find("PlayerHealth").GetComponent<Slider>();
            //foodText=GetComponent<Text>();
            foodText      = GameObject.Find("FoodText").GetComponent <Text>();
            scoreText     = GameObject.Find("ScoreText").GetComponent <Text>();
            highScoreText = GameObject.Find("HighScore").GetComponent <Text>();
            timeLimit     = GameObject.Find("TimeLimit").GetComponent <Text>();
            difficulty    = GameObject.Find("UI").GetComponent <DifficultyLevel>();
            //Get the current health,damage total and score stored in GameManager.instance between levels.
            health          = GameManager.instance.health;
            damage          = GameManager.playerDamage;
            score           = GameManager.score;
            enemiesDefeated = GameManager.enemiesDefeated;

            // playerHealth.maxValue = 300;
            // playerHealth.value = health;

            score  = score + 100;
            score += health;

            if (difficulty.medium)
            {
                timeLeft = 90.0f;
            }
            else
            {
                timeLeft = 120.0f;
            }

            //Set the foodText to reflect the current player food total.
            foodText.text      = " Health: " + health + " Damage: " + damage;
            scoreText.text     = "Score: " + score;
            highScoreText.text = "High Score : " + PlayerPrefs.GetInt("highscore", 0);
            //Call the Start function of the MovingObject base class.
            base.Start();
        }
Beispiel #2
0
        //SetupScene initializes our level and calls the previous functions to lay out the game board
        public void SetupScene(int level)
        {
            //Creates the outer walls and floor.
            BoardSetup();
            difficulty = GameObject.Find("UI").GetComponent <DifficultyLevel>();
            //Instantiate a random number of wall tiles based on minimum and maximum, at randomized positions.
            LayoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum);

            PathFinder path = new PathFinder();

            //find path from start to exit
            path.FindPath(board[1, 1], board[rows - 2, columns - 2], board, false);

            List <Cell> list = path.CellsFromPath();

            //setup wall cells around path
            setupPaths(list);

            Instantiate(exit, new Vector3(columns - 2, rows - 2, 0f), Quaternion.identity);

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

            //Instantiate a random number of health  tiles based on minimum and maximum, at randomized positions.
            LayoutObjectAtRandom(healthTiles, healthCount.minimum, healthCount.maximum);

            LayoutObjectAtRandom(damageTiles, damageCount.minimum, damageCount.maximum);

            //Determine number of enemies based on current level number, based on a logarithmic progression
            // int enemyCount = (int)Mathf.Log(level, 2f);
            // DifficultyLevel difficulty = GameObject.Find("UI").GetComponent<DifficultyLevel>();
            int enemyCount = 2;

            //int difficulty;
            // Debug.Log("count " + PlayerPrefs.GetInt("Score") + " NUM " + enemyCount);



            if (difficulty.Easy)
            {
                enemyCount += 1;
            }
            else if (difficulty.medium)
            {
                enemyCount += 2;
            }
            // Debug.Log("count " + PlayerPrefs.GetInt("Score") + " NUM " + enemyCount);


            // Debug.Log("countlast " + PlayerPrefs.GetInt("Difficulty") + " NUM " + enemyCount);

            int healthEnemyCount = 3;

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

            //they are spawned on damage tiles
            //LayoutObjectAtRandom (healthEnemyTiles, healthEnemyCount, healthEnemyCount);
            LayoutObjectAtRandom(SpeedEnemyTiles, 1, 1);

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