Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class Stage2 : MonoBehaviour
- {
- //Cosas de tiempo
- public float currentTimer = 0;
- public float onTime = 1;
- public int countDown = 40;
- public float currentTimer2 = 0;
- public float onTime2 = 0.3f;
- public float currentTimer3 = 0;
- public float onTime3 = 1;
- public float currentTimerB = 0;
- public float onTimeB = 5;
- public int countDownE = 40;
- //Cosas de texto
- public Text textoCountdown;
- public Text textoScore;
- public int score;
- //Extreme
- public GameObject tres;
- public GameObject moltres;
- public GameObject dos;
- public GameObject moldos;
- public GameObject uno;
- public GameObject moluno;
- public GameObject xtreme;
- public GameObject xtremeMol;
- //Utiles
- public GameObject biromeMol;
- public GameObject birome;
- public List<GameObject> biromes = new List<GameObject>();
- public GameObject lapizMol;
- public GameObject lapiz;
- public List<GameObject> lapices = new List<GameObject>();
- public GameObject pendriveMol;
- public GameObject pendrive;
- public List<GameObject> pendrives = new List<GameObject>();
- public GameObject grabadorMol;
- public GameObject grabador;
- public List<GameObject> grabadores = new List<GameObject>();
- public GameObject aurisMol;
- public GameObject auris;
- public List<GameObject> auriss = new List<GameObject>();
- public GameObject mochilaMol;
- public GameObject mochila;
- public float velocidad = 5;
- public Vector3 mochilaLimiteR = new Vector3(3.8f, -1.8f, 1);
- public Vector3 mochilaLimiteL = new Vector3(-3.8f, -1.8f, 1);
- public GameObject fondoMol;
- public GameObject fondo;
- //Power-Ups
- public GameObject mochilaGold;
- public GameObject mochilaGoldMol;
- public List<GameObject> mochilasGold = new List<GameObject>();
- public float velocidadgold = 10;
- public float mochilapiso = -1.8f;
- public GameObject pugold;
- public GameObject pugoldMol;
- public List<GameObject> pugolds = new List<GameObject>();
- public GameObject pu2x;
- public GameObject pu2xMol;
- public List<GameObject> doubles = new List<GameObject>();
- public float timerpu2x = 0;
- public float onTimepu2x = 10;
- public GameObject pu10plus;
- public GameObject pu10plusMol;
- public List<GameObject> pu10pluss = new List<GameObject>();
- //Hazards
- public GameObject bowling;
- public GameObject bowlingMol;
- public List<GameObject> bowlings = new List<GameObject>();
- //public GameObject stbounds;
- // Use this for initialization
- void Start()
- {
- score = 0;
- fondo = Instantiate(fondoMol);
- fondo.transform.position = new Vector3(0, 0, 3);
- mochila = Instantiate(mochilaMol);
- mochila.transform.position = new Vector3(0, -1.8f, 1);
- }
- // Update is called once per frame
- void Update()
- {
- textoCountdown.text = "Tiempo: " + countDown;
- textoScore.text = "Score: " + score;
- MoverMochila();
- EliminarLapiz();
- EliminarBirome();
- EliminarPendrive();
- EliminarGrabador();
- EliminarAuris();
- TimerPartida();
- TimerCreaciones();
- Extreme();
- EliminarBowling();
- MochilaGold();
- DoubleScore();
- Plus10();
- }
- public void TimerPartida()
- {
- currentTimer += Time.deltaTime;
- if (currentTimer >= onTime)
- {
- currentTimer = 0;
- countDown--;
- countDownE--;
- }
- if (countDown == 0 && score >= 5000)
- {
- SceneManager.LoadScene("Victory");
- }
- else if (countDown == 0)
- {
- SceneManager.LoadScene("GameOver");
- }
- }
- public void Extreme()
- {
- if (countDownE == 23)
- {
- tres = Instantiate(moltres);
- tres.transform.position = new Vector3(0, 0, 0);
- }
- else if (countDownE == 22)
- {
- Destroy(tres);
- dos = Instantiate(moldos);
- dos.transform.position = new Vector3(0, 0, 0);
- }
- else if (countDownE == 21)
- {
- Destroy(dos);
- uno = Instantiate(moluno);
- uno.transform.position = new Vector3(0, 0, 0);
- }
- else if (countDownE == 20)
- {
- Destroy(uno);
- xtreme = Instantiate(xtremeMol);
- xtreme.transform.position = new Vector3(0, 0, 0);
- }
- if (countDownE <= 20)
- {
- onTime2 = 0.1f;
- onTimeB = 1;
- }
- else if (countDownE == 19)
- {
- Destroy(xtreme);
- }
- }
- public void TimerCreaciones()
- {
- currentTimer2 += Time.deltaTime;
- currentTimer3 += Time.deltaTime;
- currentTimerB += Time.deltaTime;
- if (currentTimer2 >= onTime2)
- {
- currentTimer2 = 0;
- for (int i = 0; i < 2; i++)
- {
- int randomA = Random.Range(0, 4);
- if (randomA == 3)
- {
- CrearUtiles();
- }
- }
- }
- if (currentTimer3 >= onTime3)
- {
- currentTimer3 = 0;
- CrearPowerups();
- }
- if (currentTimerB >= onTimeB)
- {
- currentTimerB = 0;
- CrearBowling();
- }
- }
- public void CrearBowling()
- {
- int randomB;
- randomB = Random.Range(0, 3);
- if (randomB == 0)
- {
- bowling = Instantiate(bowlingMol);
- bowling.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- bowlings.Add(bowling);
- }
- }
- public void CrearUtiles()
- {
- int random;
- random = Random.Range(1, 51);
- if (random <= 17)
- {
- CrearLapiz();
- }
- else if (random <= 29)
- {
- CrearBirome();
- }
- else if (random <= 40)
- {
- CrearPendrive();
- }
- else if (random == 47)
- {
- CrearGrabador();
- }
- else
- {
- CrearAuris();
- }
- }
- #region creaciones
- public void CrearPendrive()
- {
- pendrive = Instantiate(pendriveMol);
- pendrive.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- pendrives.Add(pendrive);
- }
- public void CrearLapiz()
- {
- lapiz = Instantiate(lapizMol);
- lapiz.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- lapices.Add(lapiz);
- }
- public void CrearBirome()
- {
- birome = Instantiate(biromeMol);
- birome.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- biromes.Add(birome);
- }
- public void CrearAuris()
- {
- auris = Instantiate(aurisMol);
- auris.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- auriss.Add(auris);
- }
- public void CrearGrabador()
- {
- grabador = Instantiate(grabadorMol);
- grabador.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- grabadores.Add(grabador);
- }
- public void CrearPowerups()
- {
- if (countDown > 9)
- {
- int randomB = Random.Range(0, 4);
- if (randomB <= 1)
- {
- pugold = Instantiate(pugoldMol);
- pugold.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- pugolds.Add(pugold);
- }
- else if (randomB == 2)
- {
- pu10plus = Instantiate(pu10plusMol);
- pu10plus.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- pu10pluss.Add(pu10plus);
- }
- else
- {
- pu2x = Instantiate(pu2xMol);
- pu2x.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
- doubles.Add(pu2x);
- }
- }
- }
- #endregion
- #region mover mochila
- float timerB = 0;
- float onTimeb = 0.1f;
- public void MoverMochila()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- velocidad = 20;
- timerB = 0;
- }
- timerB = timerB + Time.deltaTime;
- if (timerB >= onTimeb)
- {
- timerB = 0;
- velocidad = 5;
- }
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- if (mochila.transform.position.x - Time.deltaTime * velocidad <= mochilaLimiteL.x)
- {
- mochila.transform.position = mochilaLimiteL;
- }
- else
- {
- mochila.transform.position += Vector3.left * Time.deltaTime * velocidad;
- }
- }
- if (Input.GetKey(KeyCode.RightArrow))
- {
- if (mochila.transform.position.x + Time.deltaTime * velocidad >= mochilaLimiteR.x)
- {
- mochila.transform.position = mochilaLimiteR;
- }
- else
- {
- mochila.transform.position += Vector3.right * Time.deltaTime * velocidad;
- }
- }
- }
- #endregion
- #region eliminar cosas
- public void EliminarLapiz()
- {
- for (int i = 0; i < lapices.Count; i++)
- {
- if (ComprobarColisiones(mochila, lapices[i]) || ComprobarColisiones(mochilaGold, lapices[i]))
- {
- Destroy(lapices[i]);
- lapices.RemoveAt(i);
- if (timerpu2x < onTimepu2x)
- {
- score += 20;
- }
- else
- {
- score += 10;
- }
- }
- else if (lapices[i].transform.position.y <= -2.2f)
- {
- Destroy(lapices[i]);
- lapices.RemoveAt(i);
- }
- }
- }
- public void EliminarBirome()
- {
- for (int g = 0; g < biromes.Count; g++)
- {
- if (ComprobarColisiones(mochila, biromes[g]) || ComprobarColisiones(mochilaGold, biromes[g]))
- {
- Destroy(biromes[g]);
- biromes.RemoveAt(g);
- if (timerpu2x < onTimepu2x)
- {
- score += 50;
- }
- else
- {
- score += 25;
- }
- }
- else if (biromes[g].transform.position.y <= -2.2f)
- {
- Destroy(biromes[g]);
- biromes.RemoveAt(g);
- }
- }
- }
- public void EliminarPendrive()
- {
- for (int h = 0; h < pendrives.Count; h++)
- {
- if (ComprobarColisiones(mochila, pendrives[h]) || ComprobarColisiones(mochilaGold, pendrives[h]))
- {
- Destroy(pendrives[h]);
- pendrives.RemoveAt(h);
- if (timerpu2x < onTimepu2x)
- {
- score += 100;
- }
- else
- {
- score += 50;
- }
- }
- else if (pendrives[h].transform.position.y <= -2.2f)
- {
- Destroy(pendrives[h]);
- pendrives.RemoveAt(h);
- }
- }
- }
- public void EliminarGrabador()
- {
- for (int i = 0; i < grabadores.Count; i++)
- {
- if (ComprobarColisiones(mochila, grabadores[i]) || ComprobarColisiones(mochilaGold, grabadores[i]))
- {
- Destroy(grabadores[i]);
- grabadores.RemoveAt(i);
- if (timerpu2x < onTimepu2x)
- {
- score += 150;
- }
- else
- {
- score += 75;
- }
- }
- else if (grabadores[i].transform.position.y <= -2.2f)
- {
- Destroy(grabadores[i]);
- grabadores.RemoveAt(i);
- }
- }
- }
- public void EliminarAuris()
- {
- for (int j = 0; j < auriss.Count; j++)
- {
- if (ComprobarColisiones(mochila, auriss[j]) || ComprobarColisiones(mochilaGold, auriss[j]))
- {
- Destroy(auriss[j]);
- auriss.RemoveAt(j);
- if (timerpu2x < onTimepu2x)
- {
- score += 200;
- }
- else
- {
- score += 100;
- }
- }
- else if (auriss[j].transform.position.y <= -1.9f)
- {
- Destroy(auriss[j]);
- auriss.RemoveAt(j);
- }
- }
- }
- public void EliminarBowling()
- {
- for (int w = 0; w < bowlings.Count; w++)
- {
- if (ComprobarColisiones(mochila, bowlings[w]))
- {
- Destroy(bowlings[w]);
- bowlings.RemoveAt(w);
- if (score - 100 < 0)
- {
- score = 0;
- }
- else
- {
- score -= 100;
- }
- }
- else if (ComprobarColisiones(mochilaGold, bowlings[w]))
- {
- Destroy(bowlings[w]);
- bowlings.RemoveAt(w);
- //Destroy(mochilaGold);
- }
- else if (bowlings[w].transform.position.y <= -2.2f)
- {
- Destroy(bowlings[w]);
- bowlings.RemoveAt(w);
- }
- }
- }
- #endregion
- public bool ComprobarColisiones(GameObject objA, GameObject objB)
- {
- if (objA == null || objB == null)
- {
- return false;
- }
- Collider2D collA = objA.GetComponent<Collider2D>();
- Collider2D collB = objB.GetComponent<Collider2D>();
- bool colision = false;
- if (collA.bounds.Intersects(collB.bounds))
- {
- colision = true;
- }
- return colision;
- }
- float timerGold;
- float onTimeGold = 5;
- public void MochilaGold()
- {
- for (int g = 0; g < pugolds.Count; g++)
- {
- if (ComprobarColisiones(mochila, pugolds[g]))
- {
- mochilaGold = Instantiate(mochilaGoldMol);
- mochilasGold.Add(mochilaGold);
- mochilaGold.transform.position = new Vector3(0, -1.8f, 1);
- Destroy(pugolds[g]);
- pugolds.RemoveAt(g);
- timerGold = 0;
- }
- }
- timerGold += Time.deltaTime;
- for (int z = 0; z < mochilasGold.Count; z++)
- {
- float direccion;
- direccion = Random.Range(1, 2f);
- if (direccion == 1)
- {
- mochilasGold[z].transform.position += Vector3.right * Time.deltaTime * velocidadgold;
- }
- else
- {
- mochilasGold[z].transform.position += Vector3.left * Time.deltaTime * velocidadgold;
- }
- if (mochilasGold[z].transform.position.x + Time.deltaTime * velocidad >= mochilaLimiteR.x)
- {
- mochilasGold[z].transform.position = mochilaLimiteR;
- velocidadgold = -velocidadgold;
- }
- else if (mochilasGold[z].transform.position.x + Time.deltaTime * velocidad <= mochilaLimiteL.x)
- {
- mochilasGold[z].transform.position = mochilaLimiteL;
- velocidadgold = -velocidadgold;
- }
- if (timerGold >= onTimeGold)
- {
- Destroy(mochilasGold[z]);
- mochilasGold.RemoveAt(z);
- }
- /*
- if (mochilasGold[z] = null)
- {
- mochilasGold.RemoveAt(z);
- }*/
- }
- }
- public void DoubleScore()
- {
- for (int d = 0; d < doubles.Count; d++)
- {
- if (ComprobarColisiones(mochila, doubles[d]))
- {
- timerpu2x += Time.deltaTime;
- Destroy(doubles[d]);
- doubles.RemoveAt(d);
- }
- }
- if (timerpu2x >= onTimepu2x)
- {
- timerpu2x = 0;
- }
- }
- public void Plus10()
- {
- for (int p = 0; p < pu10pluss.Count; p++)
- {
- if (ComprobarColisiones(mochila, pu10pluss[p]))
- {
- countDown += 10;
- Destroy(pu10pluss[p]);
- pu10pluss.RemoveAt(p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement