Exemplo n.º 1
0
    protected override void OnUpdate()
    {
        //Componente que almacena el tiempo inicial y el total
        TemporizadorComponent temporizadorComponent = m_Temporizador.GetComponentDataArray <TemporizadorComponent>()[0];
        float t = Time.time - temporizadorComponent.startTime; //Calcular diferencia de tiempo

        //Calcular minutos y segundos, y generar el string MM:SS
        int    min = ((int)t / 60);
        string minutos;

        if (min < 10)
        {
            minutos = "0" + min.ToString();
        }
        else
        {
            minutos = min.ToString();
        }

        int    sec = ((int)t % 60);
        string segundos;

        if (sec < 10)
        {
            segundos = "0" + sec.ToString();
        }
        else
        {
            segundos = sec.ToString();
        }

        //Mostrar el string MM:SS en la UI
        GameObject.Find("Tiempo").GetComponent <Text>().text = minutos + ":" + segundos;
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Obtener el componente del temporizador
        TemporizadorComponent temporizadorComponent = m_Temporizador.GetComponentDataArray <TemporizadorComponent>()[0];
        //Calcular el tiempo que ha pasado desde el inicio del juego
        float tiempoTotal = Time.time - temporizadorComponent.startTime;
        int   v           = (int)(tiempoTotal / 20); //La velocidad va a aumentar cada 20 segundos

        var jobObstaculo = new MoverObstaculo {
            dt = Time.deltaTime,
            v  = v
        };
        JobHandle jobObs = jobObstaculo.Schedule(this, inputDeps);

        var jobPremio = new MoverPremios {
            dt = Time.deltaTime,
            v  = v
        };

        return(jobPremio.Schedule(this, jobObs));
    }
Exemplo n.º 3
0
    protected override void OnUpdate()
    {
        //Si hay alguna entidad que posea el FinJuegoComponent
        if (m_FinJuego.CalculateLength() > 0)
        {
            Bootstrap.bootstrap.StopMusic();  //parar musica de fondo
            Bootstrap.bootstrap.PlaySound(1); //reproducir sonido choque

            //Eliminar todas las entidades
            ComponentGroup m_Jugador = GetComponentGroup(typeof(PlayerInputComponent));
            EntityManager.DestroyEntity(m_Jugador);
            ComponentGroup m_Obstaculos = GetComponentGroup(typeof(ObstaculoComponent));
            EntityManager.DestroyEntity(m_Obstaculos);
            ComponentGroup m_Premios = GetComponentGroup(typeof(PremioComponent));
            EntityManager.DestroyEntity(m_Premios);
            ComponentGroup m_Manos = GetComponentGroup(typeof(ManoComponent));
            EntityManager.DestroyEntity(m_Manos);
            ComponentGroup m_TiempoSpawnManos = GetComponentGroup(typeof(TiempoSpawnManosComponent));
            EntityManager.DestroyEntity(m_TiempoSpawnManos);
            ComponentGroup m_TiempoSpawnObstaculos = GetComponentGroup(typeof(TiempoSpawnComponent));
            EntityManager.DestroyEntity(m_TiempoSpawnObstaculos);
            ComponentGroup m_SonidoMoneda = GetComponentGroup(typeof(SonidoMonedaComponent));
            EntityManager.DestroyEntity(m_SonidoMoneda);

            //Calcula y guarda el tiempo total que ha durado la partida
            TemporizadorComponent temporizadorComponent = m_Temporizador.GetComponentDataArray <TemporizadorComponent>()[0];
            float t = Time.time - temporizadorComponent.startTime;
            Bootstrap.bootstrap.GuardarTiempoTotal(t);

            EntityManager.DestroyEntity(m_FinJuego);
            EntityManager.DestroyEntity(m_Temporizador);

            Bootstrap.bootstrap.FinJuego();   //Metodo que muestra el pop-up de fin de partida
            Bootstrap.bootstrap.PlaySound(2); //reproducir sonido fin partida
        }
    }
    protected override void OnUpdate()
    {
        //Componente que contiene los tiempos de spawn de cada elemento
        TiempoSpawnComponent componente = m_TiempoSpawn.GetComponentDataArray <TiempoSpawnComponent>()[0];

        /****** SPAWN OBSTACULOS *******/

        //Comprobar si se ha agotado el tiempo de espera del spawner de obstaculos
        float tiempoObstaculos = componente.segundosObstaculos;

        tiempoObstaculos = Mathf.Max(0.0f, componente.segundosObstaculos - Time.deltaTime);
        bool spawnObstaculo = tiempoObstaculos <= 0.0f;

        //Resetear el tiempo de espera si se ha agotado
        if (spawnObstaculo)
        {
            //Calcular cuanto hay que reducir tiempo de spawn en funcion del tiempo de juego
            // (reducir el tiempo de spawn al aumentar la velocidad de movimiento)
            TemporizadorComponent temporizadorComponent = m_Temporizador.GetComponentDataArray <TemporizadorComponent>()[0];
            float tiempoTotal = Time.time - temporizadorComponent.startTime; //tiempo que ha pasado desde el inicio del juego
            int   t           = (int)(tiempoTotal / 20);                     //cada 20s, la velocidad aumenta y el tiempo de spawn disminuye

            tiempoObstaculos = Mathf.Max(0.5f, 1.2f - 0.15f * t);            //reducir 0.15s cada 20s, hasta un minimo de 0.5s
        }

        //Array de obstaculos que estan inactivos
        EntityArray obstaculosInactivos = m_Obstaculos.GetEntityArray();

        //Spawnear obstaculo si el tiempo de espera ha llegado a 0 y si quedan obstaculos por activar
        // (se supone que siempre van a quedar obstaculos por activar, puesto que da tiempo a que alguno se desactive)
        if (spawnObstaculo && obstaculosInactivos.Length > 0)
        {
            //Escoger tipo de obstaculo aleatoriamente
            int idObstaculo = UnityEngine.Random.Range(0, 3);
            //Escoger posicion aleatoriamente
            float posicionX;
            if (idObstaculo == 2)
            {
                //Los palillos solo pueden aparecer en los extremos
                posicionX = posiciones[UnityEngine.Random.Range(0, 2)];
            }
            else
            {
                posicionX = posiciones[UnityEngine.Random.Range(0, 3)];
            }

            JobHandle jobActivar = new ActivarObstaculo()
            {
                obstaculosInactivos = obstaculosInactivos,
                Commands            = _collisionBarrier.CreateCommandBuffer(),
                randomId            = UnityEngine.Random.Range(0, obstaculosInactivos.Length),
                posicionX           = posicionX,
                idObstaculo         = idObstaculo
            }.Schedule();
            jobActivar.Complete();
        }


        /************ SPAWN PREMIOS *******/

        //Comprobar si se ha agotado el tiempo de espera del spawner de premios
        float tiempoPremios = componente.segundosPremios;

        tiempoPremios = Mathf.Max(0.0f, componente.segundosPremios - Time.deltaTime);
        bool spawnPremios = tiempoPremios <= 0.0f;

        if (spawnPremios)
        {
            //Resetear
            tiempoPremios = 7.0f; //7 segundos entre premios (no disminuye con la velocidad)
        }

        //Array de premios que estan inactivos
        EntityArray premiosInactivos = m_Premios.GetEntityArray();

        //Spawnear premio si el tiempo de espera ha llegado a 0 y si quedan premios por activar
        if (spawnPremios && premiosInactivos.Length > 0)
        {
            //Escoger posicion aleatoriamente
            float posicionX = posiciones[UnityEngine.Random.Range(0, 3)];

            JobHandle jobActivar = new ActivarPremio()
            {
                premiosInactivos = premiosInactivos,
                Commands         = _collisionBarrier.CreateCommandBuffer(),
                randomId         = UnityEngine.Random.Range(0, premiosInactivos.Length),
                posicionX        = posicionX
            }.Schedule();
            jobActivar.Complete();
        }

        //Actualizar el tiempo que queda en el componente
        Entity ent = m_TiempoSpawn.GetEntityArray()[0];

        EntityManager.SetComponentData <TiempoSpawnComponent>(ent, new TiempoSpawnComponent {
            segundosObstaculos = tiempoObstaculos,
            segundosPremios    = tiempoPremios
        });
    }