Esempio n. 1
0
    public void Start()
    {
        cantSitiosOcultos   = 0;
        jugadorEnRoom       = false;
        alarmTriggered      = false;
        altTecho            = ALT_HAB;
        limiteIzquierdo     = new Vector3();
        limiteDerecho       = new Vector3();
        generadoresDecorado = new List <GameObject>();

        suelo   = transform.Find("ParedSuelo").gameObject;
        techo   = transform.Find("Techo").gameObject;
        spawner = transform.Find("Spawner").gameObject;

        if (listaLaterales.Length == 0)
        {
            initListaLaterales();
        }


        if (listaTrampas == null)
        {
            listaTrampas = new List <GeneradorObjetos.trapStruct>();
        }

        if (tipoHabitacion == tipo.Entrada && listaTrampas.Count == 0)
        {
            GeneradorObjetos.trapStruct auxElement = new GeneradorObjetos.trapStruct();
            auxElement.tipo          = GeneradorObjetos.tipo.RedLaser;
            auxElement.level         = dificultad;
            auxElement.verticalSpeed = getRandomVerticalSpeed();
            listaTrampas.Add(auxElement);
        }

        techo.SetActive(hasTecho);

        if (tipoHabitacion == tipo.Entrada)
        {
            spawner.SetActive(true);
        }
        else
        {
            spawner.SetActive(false);
        }

        rellenarSala();
    }
Esempio n. 2
0
    public void loadLevel(int hueco)
    {
        FileInfo     theSourceFile = null;
        StreamReader reader        = null;
        string       text          = " ";

        theSourceFile = new FileInfo("Nivel" + hueco + ".txt");
        bool listo = false;

        if (theSourceFile != null)
        {
            reader = theSourceFile.OpenText();
            string[] strArr;
            List <Edificio.estructuraPisos> listaPisos = new List <Edificio.estructuraPisos>();
            Edificio.estructuraPisos        auxPiso    = new Edificio.estructuraPisos();
            Edificio.estructuraHabitacion   auxRoom    = new Edificio.estructuraHabitacion();
            Edificio.condicionesVictoria    condicion0 = new Edificio.condicionesVictoria();
            Edificio.condicionesVictoria    condicion1 = new Edificio.condicionesVictoria();
            int dificultad = 1;

            while (!listo)
            {
                text = reader.ReadLine();
                if (text != null)
                {
                    strArr = text.Split(' ');
                    int pisoActual = 0;

                    switch (strArr[0])
                    {
                    case "dificultad":
                        dificultad = int.Parse(strArr[1]);
                        break;

                    case "objetivo0":
                        switch (int.Parse(strArr[1]))
                        {
                        case 0:
                            condicion0 = Edificio.condicionesVictoria.conseguirDocumentos;
                            break;

                        case 1:
                            condicion0 = Edificio.condicionesVictoria.conseguirPiezas;
                            break;

                        case 2:
                            condicion0 = Edificio.condicionesVictoria.desactivarTrampas;
                            break;
                        }
                        break;

                    case "objetivo1":
                        switch (int.Parse(strArr[1]))
                        {
                        case 0:
                            condicion1 = Edificio.condicionesVictoria.conseguirDocumentos;
                            break;

                        case 1:
                            condicion1 = Edificio.condicionesVictoria.conseguirPiezas;
                            break;

                        case 2:
                            condicion1 = Edificio.condicionesVictoria.desactivarTrampas;
                            break;
                        }
                        break;

                    case "NewFloor":
                        if (int.Parse(strArr[1]) != 0)
                        {
                            auxPiso.habitaciones.Add(auxRoom);
                            listaPisos.Add(auxPiso);
                            pisoActual++;
                        }
                        auxPiso = new Edificio.estructuraPisos();
                        auxPiso.habitaciones = new List <Edificio.estructuraHabitacion>();
                        break;

                    case "NewRoom":
                        if (int.Parse(strArr[1]) != 0)
                        {
                            auxPiso.habitaciones.Add(auxRoom);
                        }
                        auxRoom = new Edificio.estructuraHabitacion();
                        auxRoom.listaLaterales = new RoomController.tiposParedes[4];
                        auxRoom.listaTrampas   = new List <GeneradorObjetos.trapStruct>();
                        auxRoom.conectaCon     = new List <Edificio.estructuraHabitacion>();
                        auxRoom.id             = int.Parse(strArr[1]);
                        break;

                    case "piso":
                        auxRoom.piso = pisoActual;
                        break;

                    case "estilo":
                        auxRoom.estiloHabitacion = int.Parse(strArr[1]) == 0 ? Edificio.listaEstilos.oficina : Edificio.listaEstilos.casaNormal;
                        break;

                    case "tipo":
                        switch (int.Parse(strArr[1]))
                        {
                        case 0:
                            auxRoom.tipoHabitacion = RoomController.tipo.Entrada;
                            break;

                        case 1:
                            auxRoom.tipoHabitacion = RoomController.tipo.HabitacionPrincipal;
                            break;

                        case 2:
                            auxRoom.tipoHabitacion = RoomController.tipo.Banyo;
                            break;
                        }
                        break;

                    case "nivel":
                        auxRoom.nivel = int.Parse(strArr[1]);
                        break;

                    case "coordenadas":
                        auxRoom.coordenadas = new Vector2(float.Parse(strArr[1]), float.Parse(strArr[2]));
                        break;

                    case "tam":
                        auxRoom.tam = int.Parse(strArr[1]);
                        break;

                    case "techo":
                        auxRoom.hasTecho = int.Parse(strArr[1]) == 1 ? true : false;
                        break;

                    case "tall":
                        auxRoom.tall = int.Parse(strArr[1]) == 1 ? true : false;
                        break;

                    case "camara":
                        auxRoom.cameraPosition = int.Parse(strArr[1]);
                        break;

                    case "ocultos":
                        auxRoom.cantSitiosOcultos = int.Parse(strArr[1]);
                        break;

                    case "reward":
                        switch (int.Parse(strArr[1]))
                        {
                        case 0:
                            auxRoom.reward = ObjetoRecompensa.tipoRecompensa.ninguno;
                            break;

                        case 1:
                            auxRoom.reward = ObjetoRecompensa.tipoRecompensa.documentos;
                            break;

                        case 2:
                            auxRoom.reward = ObjetoRecompensa.tipoRecompensa.piezasSecretas;
                            break;

                        case 3:
                            auxRoom.reward = ObjetoRecompensa.tipoRecompensa.conjuntoPuntos;
                            break;
                        }
                        break;

                    case "lateral":
                        for (int i = 1; i <= 4; i++)
                        {
                            switch (int.Parse(strArr[i]))
                            {
                            case 0:
                                auxRoom.listaLaterales[i - 1] = RoomController.tiposParedes.nada;
                                break;

                            case 1:
                                auxRoom.listaLaterales[i - 1] = RoomController.tiposParedes.pared;
                                break;

                            case 2:
                                auxRoom.listaLaterales[i - 1] = RoomController.tiposParedes.puerta;
                                break;

                            case 3:
                                auxRoom.listaLaterales[i - 1] = RoomController.tiposParedes.trampilla;
                                break;
                            }
                        }
                        break;

                    case "trampa0":
                        GeneradorObjetos.trapStruct auxStruct = new GeneradorObjetos.trapStruct();

                        if (int.Parse(strArr[1]) < 3)
                        {
                            if (int.Parse(strArr[1]) == 0)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.Mina;
                            }
                            else if (int.Parse(strArr[1]) == 1)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.Cepo;
                            }
                            else if (int.Parse(strArr[1]) == 2)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.PlacaPresion;
                            }
                            auxStruct.level = int.Parse(strArr[2]);
                        }
                        else     //Es la red laser
                        {
                            auxStruct.tipo          = GeneradorObjetos.tipo.RedLaser;
                            auxStruct.level         = int.Parse(strArr[2]);
                            auxStruct.verticalSpeed = float.Parse(strArr[3]);
                        }
                        auxRoom.listaTrampas.Add(auxStruct);
                        break;

                    case "trampa1":
                        auxStruct = new GeneradorObjetos.trapStruct();

                        if (int.Parse(strArr[1]) < 3)
                        {
                            if (int.Parse(strArr[1]) == 0)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.Mina;
                            }
                            else if (int.Parse(strArr[1]) == 1)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.Cepo;
                            }
                            else if (int.Parse(strArr[1]) == 2)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.PlacaPresion;
                            }
                            auxStruct.level = int.Parse(strArr[2]);
                        }
                        else     //Es la red laser
                        {
                            auxStruct.tipo          = GeneradorObjetos.tipo.RedLaser;
                            auxStruct.level         = int.Parse(strArr[2]);
                            auxStruct.verticalSpeed = float.Parse(strArr[3]);
                        }
                        auxRoom.listaTrampas.Add(auxStruct);
                        break;

                    case "trampa2":
                        auxStruct = new GeneradorObjetos.trapStruct();

                        if (int.Parse(strArr[1]) < 3)
                        {
                            if (int.Parse(strArr[1]) == 0)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.Mina;
                            }
                            else if (int.Parse(strArr[1]) == 1)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.Cepo;
                            }
                            else if (int.Parse(strArr[1]) == 2)
                            {
                                auxStruct.tipo = GeneradorObjetos.tipo.PlacaPresion;
                            }
                            auxStruct.level = int.Parse(strArr[2]);
                        }
                        else     //Es la red laser
                        {
                            auxStruct.tipo          = GeneradorObjetos.tipo.RedLaser;
                            auxStruct.level         = int.Parse(strArr[2]);
                            auxStruct.verticalSpeed = float.Parse(strArr[3]);
                        }
                        auxRoom.listaTrampas.Add(auxStruct);
                        break;
                    }
                }
                else
                {
                    auxPiso.habitaciones.Add(auxRoom);
                    listaPisos.Add(auxPiso);

                    listo = true;
                }
            }
            GameObject obj = new GameObject();
            obj.name = "Edificio";
            obj.transform.SetParent(this.transform);
            obj.AddComponent <Edificio>();
            obj.GetComponent <Edificio>().loadedMap(listaPisos, condicion0, condicion1, dificultad);
            obj.GetComponent <Edificio>().setInitialTime(Time.time);
            enableCamera(false);
            setEstado(4);
        }
        else
        {
            print("Error al leer Nivel" + hueco + ".txt");
        }
        reader.Close();
    }
Esempio n. 3
0
    private void disposicionGeneradoresObjetos()
    {
        int aux       = 0;
        int auxCamera = 0;

        switch (dificultad)
        {
        case 1:
            aux       = Random.Range(0, 2);
            auxCamera = Random.Range(0, 2);
            break;

        case 2:
            aux       = 1;
            auxCamera = Random.Range(0, 2);
            break;

        case 3:
            aux       = Random.Range(1, 3);
            auxCamera = Random.Range(0, 3);
            break;

        case 4:
            aux       = 2;
            auxCamera = Random.Range(0, 3);
            break;

        case 5:
            aux       = Random.Range(2, 4);
            auxCamera = Random.Range(1, 3);
            break;

        case 6:
            aux       = 3;
            auxCamera = Random.Range(1, 3);
            break;
        }

        if (auxCamera == 1)
        {
            cameraPosition = Random.Range(auxCamera, 3);
        }
        else if (auxCamera == 2)
        {
            cameraPosition = 3;
        }

        if (tipoHabitacion == tipo.Entrada || tipoHabitacion == tipo.Banyo)
        {
            cameraPosition = 0;
        }

        edificio.setCameraPosition(cameraPosition, this.id);

        aux++;

        if (tipoHabitacion == tipo.Banyo)
        {
            aux = 0;
            if (reward == ObjetoRecompensa.tipoRecompensa.ninguno)
            {
                int auxPuntos = Random.Range(0, 3);
                if (auxPuntos == 0)
                {
                    reward = ObjetoRecompensa.tipoRecompensa.conjuntoPuntos;
                    edificio.setReward(reward, this.id);
                }
            }
        }

        if (reward == ObjetoRecompensa.tipoRecompensa.ninguno)
        {
            if (listaTrampas.Count != 0)
            {
                aux = listaTrampas.Count;
            }
            else
            {
                aux--;
            }

            if (aux > 0)
            {
                bool generoNuevas = true;

                if (listaTrampas.Count != 0)
                {
                    generoNuevas = false;
                }

                Vector3 position;
                for (int i = 0; i < aux; i++)
                {
                    position   = limiteIzquierdo;
                    position.x = position.x + (i + 1) * (tHab / (aux + 1));

                    //print (position.x + " + " + i +" * (" +tHab+" / "+aux+")");

                    GameObject objeto = Instantiate(generadorPrefab, position, Quaternion.identity);
                    objeto.GetComponent <GeneradorObjetos>().nivel  = dificultad;
                    objeto.GetComponent <GeneradorObjetos>().estilo = estilo;
                    GameObject auxObj;
                    if (generoNuevas)
                    {
                        GeneradorObjetos.trapStruct auxItem = new GeneradorObjetos.trapStruct();

                        auxItem.tipo          = GeneradorObjetos.getRandomObject();
                        auxItem.level         = dificultad;
                        auxItem.verticalSpeed = 0;
                        auxObj = objeto.GetComponent <GeneradorObjetos>().generateObjects(auxItem.tipo);

                        if (auxItem.tipo == GeneradorObjetos.tipo.RedLaser)
                        {
                            auxItem.verticalSpeed = getRandomVerticalSpeed();
                            auxObj.GetComponent <RedLaserController>().setVerticalSpeed(auxItem.verticalSpeed);
                        }

                        listaTrampas.Add(auxItem);
                    }
                    else
                    {
                        if (listaTrampas[i].tipo == GeneradorObjetos.tipo.RedLaser)
                        {
                            auxObj = objeto.GetComponent <GeneradorObjetos>().generateObjects(listaTrampas[i].tipo);
                            auxObj.GetComponent <RedLaserController>().setVerticalSpeed(listaTrampas[i].verticalSpeed);
                        }
                        else
                        {
                            auxObj = objeto.GetComponent <GeneradorObjetos>().generateObjects(listaTrampas[i].tipo);
                        }
                    }

                    objeto.transform.SetParent(this.transform);
                    auxObj.transform.SetParent(this.transform);
                }
                edificio.setListaTrampas(listaTrampas, this.id);
            }
        }
        else
        {
            Vector3 position;
            position   = limiteIzquierdo;
            position.x = position.x + (tHab / 2);

            //print (position.x + " + " + i +" * (" +tHab+" / "+aux+")");

            GameObject objeto = Instantiate(generadorPrefab, position, Quaternion.identity);
            objeto.GetComponent <GeneradorObjetos>().nivel  = dificultad;
            objeto.GetComponent <GeneradorObjetos>().estilo = estilo;

            GameObject auxObj = objeto.GetComponent <GeneradorObjetos>().generateObjects(GeneradorObjetos.tipo.Recompensa);
            auxObj.GetComponent <ObjetoRecompensa>().tipoObjeto = reward;
            objeto.transform.SetParent(this.transform);
            auxObj.transform.SetParent(this.transform);
            edificio.setListaTrampas(listaTrampas, this.id);
        }
    }