Ejemplo n.º 1
0
    /*
     * Actualización por frame
     */
    private void Update()
    {
        // Agregar tiempo
        timer += Time.deltaTime;
        if (timer >= timeBetweenSpawn)
        {
            // Debug.LogWarning("Siguiente especial: " + spawnTrashCount);
            // Calcular spawn aleatorio
            int spawn = Random.Range(0, spawnPositions.Length);
            // Calcular tipo de comida aleatorio
            int foodPosition = 5;
            if (spawnTrashCount != 0)
            {
                foodPosition = Random.Range(0, 6);
            }
            else if (gameParameters.getDifficulty() == 1)
            {
                foodPosition = selectedFoodNum;
            }
            // Obtener comida
            GameObject[] food = getFoodType(foodPosition);
            // Aparecer comida
            spawnFood(food, spawn);
            // Reducir cuenta
            spawnTrashCount -= 1;
            // Reiniciar timer
            timer = 0.0f;

            if (spawnTrashCount < 0)
            {
                spawnTrashCount = Random.Range(minProbability - 1, maxProbability + 1);
                // Debug.Log("Espera: " + spawnTrashCount);
            }
        }
    }
Ejemplo n.º 2
0
    /*
     * Iniciar juego
     */
    private void Start()
    {
        // Instanciar el puntaje
        playerScore     = 0;
        timer           = 0;
        heartCount      = 2;
        spawnTrashCount = Random.Range(minProbability, maxProbability);
        gameParameters  = GetComponent <GameParameters>();
        // Parámetros de dificultad
        switch (gameParameters.getDifficulty())
        {
        // Fácil
        case 0:
            minGravityScale = minGravEasy;
            maxGravityScale = maxGravEasy;
            setEasyGame();
            break;

        case 1:
            normalFoodCount = 0;
            minGravityScale = minGravNormal;
            maxGravityScale = maxGravNormal;
            // Configurar juego en normal
            setNormalGame();
            break;

        default:
            Debug.LogWarning("No se seleccionó dificultad...");
            minGravityScale = minGravEasy;
            maxGravityScale = maxGravEasy;
            break;
        }
    }