Advertisement
KTVX94

Untitled

Aug 7th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.13 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5.  
  6.  
  7. public class Stage2 : MonoBehaviour
  8. {
  9.  
  10.     //Cosas de tiempo
  11.     public float currentTimer = 0;
  12.     public float onTime = 1;
  13.     public int countDown = 40;
  14.  
  15.     public float currentTimer2 = 0;
  16.     public float onTime2 = 0.3f;
  17.  
  18.     public float currentTimer3 = 0;
  19.     public float onTime3 = 1;
  20.  
  21.     public float currentTimerB = 0;
  22.     public float onTimeB = 5;
  23.  
  24.     public int countDownE = 40;
  25.  
  26.  
  27.     //Cosas de texto
  28.     public Text textoCountdown;
  29.     public Text textoScore;
  30.     public int score;
  31.  
  32.     //Extreme
  33.     public GameObject tres;
  34.     public GameObject moltres;
  35.     public GameObject dos;
  36.     public GameObject moldos;
  37.     public GameObject uno;
  38.     public GameObject moluno;
  39.     public GameObject xtreme;
  40.     public GameObject xtremeMol;
  41.  
  42.  
  43.     //Utiles
  44.     public GameObject biromeMol;
  45.     public GameObject birome;
  46.     public List<GameObject> biromes = new List<GameObject>();
  47.  
  48.     public GameObject lapizMol;
  49.     public GameObject lapiz;
  50.     public List<GameObject> lapices = new List<GameObject>();
  51.  
  52.     public GameObject pendriveMol;
  53.     public GameObject pendrive;
  54.     public List<GameObject> pendrives = new List<GameObject>();
  55.  
  56.     public GameObject grabadorMol;
  57.     public GameObject grabador;
  58.     public List<GameObject> grabadores = new List<GameObject>();
  59.  
  60.     public GameObject aurisMol;
  61.     public GameObject auris;
  62.     public List<GameObject> auriss = new List<GameObject>();
  63.  
  64.     public GameObject mochilaMol;
  65.     public GameObject mochila;
  66.     public float velocidad = 5;
  67.  
  68.     public Vector3 mochilaLimiteR = new Vector3(3.8f, -1.8f, 1);
  69.     public Vector3 mochilaLimiteL = new Vector3(-3.8f, -1.8f, 1);
  70.  
  71.     public GameObject fondoMol;
  72.     public GameObject fondo;
  73.  
  74.     //Power-Ups
  75.     public GameObject mochilaGold;
  76.     public GameObject mochilaGoldMol;
  77.     public List<GameObject> mochilasGold = new List<GameObject>();
  78.     public float velocidadgold = 10;
  79.     public float mochilapiso = -1.8f;
  80.  
  81.     public GameObject pugold;
  82.     public GameObject pugoldMol;
  83.     public List<GameObject> pugolds = new List<GameObject>();
  84.  
  85.     public GameObject pu2x;
  86.     public GameObject pu2xMol;
  87.     public List<GameObject> doubles = new List<GameObject>();
  88.     public float timerpu2x = 0;
  89.     public float onTimepu2x = 10;
  90.  
  91.     public GameObject pu10plus;
  92.     public GameObject pu10plusMol;
  93.     public List<GameObject> pu10pluss = new List<GameObject>();
  94.  
  95.     //Hazards
  96.     public GameObject bowling;
  97.     public GameObject bowlingMol;
  98.     public List<GameObject> bowlings = new List<GameObject>();
  99.  
  100.     //public GameObject stbounds;
  101.  
  102.  
  103.     // Use this for initialization
  104.     void Start()
  105.     {
  106.         score = 0;
  107.         fondo = Instantiate(fondoMol);
  108.         fondo.transform.position = new Vector3(0, 0, 3);
  109.  
  110.         mochila = Instantiate(mochilaMol);
  111.         mochila.transform.position = new Vector3(0, -1.8f, 1);
  112.  
  113.     }
  114.  
  115.     // Update is called once per frame
  116.     void Update()
  117.     {
  118.  
  119.         textoCountdown.text = "Tiempo: " + countDown;
  120.         textoScore.text = "Score: " + score;
  121.         MoverMochila();
  122.         EliminarLapiz();
  123.         EliminarBirome();
  124.         EliminarPendrive();
  125.         EliminarGrabador();
  126.         EliminarAuris();
  127.         TimerPartida();
  128.         TimerCreaciones();
  129.         Extreme();
  130.  
  131.         EliminarBowling();
  132.         MochilaGold();
  133.         DoubleScore();
  134.         Plus10();
  135.  
  136.     }
  137.  
  138.  
  139.  
  140.     public void TimerPartida()
  141.  
  142.     {
  143.         currentTimer += Time.deltaTime;
  144.         if (currentTimer >= onTime)
  145.         {
  146.             currentTimer = 0;
  147.             countDown--;
  148.             countDownE--;
  149.         }
  150.  
  151.         if (countDown == 0 && score >= 5000)
  152.         {
  153.             SceneManager.LoadScene("Victory");
  154.         }
  155.  
  156.         else if (countDown == 0)
  157.         {
  158.             SceneManager.LoadScene("GameOver");
  159.         }
  160.  
  161.     }
  162.  
  163.     public void Extreme()
  164.     {
  165.         if (countDownE == 23)
  166.         {
  167.             tres = Instantiate(moltres);
  168.             tres.transform.position = new Vector3(0, 0, 0);
  169.         }
  170.  
  171.         else if (countDownE == 22)
  172.         {
  173.             Destroy(tres);
  174.             dos = Instantiate(moldos);
  175.             dos.transform.position = new Vector3(0, 0, 0);
  176.         }
  177.  
  178.  
  179.         else if (countDownE == 21)
  180.         {
  181.             Destroy(dos);
  182.             uno = Instantiate(moluno);
  183.             uno.transform.position = new Vector3(0, 0, 0);
  184.         }
  185.  
  186.  
  187.         else if (countDownE == 20)
  188.         {
  189.             Destroy(uno);
  190.             xtreme = Instantiate(xtremeMol);
  191.             xtreme.transform.position = new Vector3(0, 0, 0);
  192.         }
  193.  
  194.         if (countDownE <= 20)
  195.         {
  196.             onTime2 = 0.1f;
  197.             onTimeB = 1;
  198.         }
  199.  
  200.         else if (countDownE == 19)
  201.         {
  202.             Destroy(xtreme);
  203.         }
  204.     }
  205.  
  206.  
  207.     public void TimerCreaciones()
  208.     {
  209.  
  210.         currentTimer2 += Time.deltaTime;
  211.         currentTimer3 += Time.deltaTime;
  212.         currentTimerB += Time.deltaTime;
  213.         if (currentTimer2 >= onTime2)
  214.         {
  215.             currentTimer2 = 0;
  216.             for (int i = 0; i < 2; i++)
  217.             {
  218.                 int randomA = Random.Range(0, 4);
  219.                 if (randomA == 3)
  220.                 {
  221.                     CrearUtiles();
  222.                 }
  223.  
  224.             }
  225.         }
  226.  
  227.         if (currentTimer3 >= onTime3)
  228.         {
  229.             currentTimer3 = 0;
  230.             CrearPowerups();
  231.         }
  232.  
  233.         if (currentTimerB >= onTimeB)
  234.         {
  235.             currentTimerB = 0;
  236.             CrearBowling();
  237.         }
  238.     }
  239.  
  240.     public void CrearBowling()
  241.     {
  242.         int randomB;
  243.  
  244.         randomB = Random.Range(0, 3);
  245.  
  246.         if (randomB == 0)
  247.         {
  248.             bowling = Instantiate(bowlingMol);
  249.             bowling.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  250.             bowlings.Add(bowling);
  251.  
  252.         }
  253.  
  254.     }
  255.  
  256.     public void CrearUtiles()
  257.     {
  258.         int random;
  259.  
  260.         random = Random.Range(1, 51);
  261.  
  262.         if (random <= 17)
  263.         {
  264.             CrearLapiz();
  265.         }
  266.  
  267.         else if (random <= 29)
  268.         {
  269.             CrearBirome();
  270.         }
  271.  
  272.         else if (random <= 40)
  273.         {
  274.             CrearPendrive();
  275.         }
  276.  
  277.         else if (random == 47)
  278.         {
  279.             CrearGrabador();
  280.         }
  281.  
  282.         else
  283.         {
  284.             CrearAuris();
  285.         }
  286.  
  287.     }
  288.  
  289.  
  290.     #region creaciones
  291.  
  292.     public void CrearPendrive()
  293.     {
  294.         pendrive = Instantiate(pendriveMol);
  295.         pendrive.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  296.         pendrives.Add(pendrive);
  297.  
  298.     }
  299.  
  300.     public void CrearLapiz()
  301.     {
  302.         lapiz = Instantiate(lapizMol);
  303.         lapiz.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  304.         lapices.Add(lapiz);
  305.  
  306.     }
  307.  
  308.     public void CrearBirome()
  309.     {
  310.         birome = Instantiate(biromeMol);
  311.         birome.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  312.         biromes.Add(birome);
  313.  
  314.     }
  315.  
  316.     public void CrearAuris()
  317.     {
  318.         auris = Instantiate(aurisMol);
  319.         auris.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  320.         auriss.Add(auris);
  321.  
  322.     }
  323.  
  324.     public void CrearGrabador()
  325.     {
  326.         grabador = Instantiate(grabadorMol);
  327.         grabador.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  328.         grabadores.Add(grabador);
  329.  
  330.     }
  331.  
  332.     public void CrearPowerups()
  333.     {
  334.         if (countDown > 9)
  335.         {
  336.             int randomB = Random.Range(0, 4);
  337.             if (randomB <= 1)
  338.             {
  339.                 pugold = Instantiate(pugoldMol);
  340.                 pugold.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  341.                 pugolds.Add(pugold);
  342.             }
  343.  
  344.             else if (randomB == 2)
  345.             {
  346.                 pu10plus = Instantiate(pu10plusMol);
  347.                 pu10plus.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  348.                 pu10pluss.Add(pu10plus);
  349.             }
  350.  
  351.             else
  352.             {
  353.                 pu2x = Instantiate(pu2xMol);
  354.                 pu2x.transform.position = new Vector3(Random.Range(-3.7f, 3.7f), 1.8f, 1);
  355.                 doubles.Add(pu2x);
  356.             }
  357.         }
  358.     }
  359.  
  360.     #endregion
  361.  
  362.  
  363.     #region mover mochila
  364.     float timerB = 0;
  365.     float onTimeb = 0.1f;
  366.  
  367.     public void MoverMochila()
  368.     {
  369.  
  370.  
  371.         if (Input.GetKeyDown(KeyCode.Space))
  372.         {
  373.             velocidad = 20;
  374.             timerB = 0;
  375.         }
  376.  
  377.         timerB = timerB + Time.deltaTime;
  378.  
  379.         if (timerB >= onTimeb)
  380.         {
  381.             timerB = 0;
  382.             velocidad = 5;
  383.         }
  384.  
  385.  
  386.  
  387.         if (Input.GetKey(KeyCode.LeftArrow))
  388.         {
  389.             if (mochila.transform.position.x - Time.deltaTime * velocidad <= mochilaLimiteL.x)
  390.             {
  391.                 mochila.transform.position = mochilaLimiteL;
  392.             }
  393.  
  394.             else
  395.             {
  396.                 mochila.transform.position += Vector3.left * Time.deltaTime * velocidad;
  397.             }
  398.  
  399.         }
  400.         if (Input.GetKey(KeyCode.RightArrow))
  401.         {
  402.  
  403.             if (mochila.transform.position.x + Time.deltaTime * velocidad >= mochilaLimiteR.x)
  404.             {
  405.                 mochila.transform.position = mochilaLimiteR;
  406.             }
  407.  
  408.             else
  409.             {
  410.                 mochila.transform.position += Vector3.right * Time.deltaTime * velocidad;
  411.             }
  412.         }
  413.  
  414.  
  415.     }
  416.  
  417.     #endregion
  418.  
  419.  
  420.     #region eliminar cosas
  421.     public void EliminarLapiz()
  422.     {
  423.         for (int i = 0; i < lapices.Count; i++)
  424.         {
  425.             if (ComprobarColisiones(mochila, lapices[i]) || ComprobarColisiones(mochilaGold, lapices[i]))
  426.             {
  427.                 Destroy(lapices[i]);
  428.                 lapices.RemoveAt(i);
  429.                 if (timerpu2x < onTimepu2x)
  430.                 {
  431.                     score += 20;
  432.                 }
  433.                 else
  434.                 {
  435.                     score += 10;
  436.                 }
  437.             }
  438.  
  439.  
  440.             else if (lapices[i].transform.position.y <= -2.2f)
  441.             {
  442.                 Destroy(lapices[i]);
  443.                 lapices.RemoveAt(i);
  444.             }
  445.         }
  446.  
  447.     }
  448.  
  449.     public void EliminarBirome()
  450.     {
  451.         for (int g = 0; g < biromes.Count; g++)
  452.         {
  453.             if (ComprobarColisiones(mochila, biromes[g]) || ComprobarColisiones(mochilaGold, biromes[g]))
  454.             {
  455.                 Destroy(biromes[g]);
  456.                 biromes.RemoveAt(g);
  457.                 if (timerpu2x < onTimepu2x)
  458.                 {
  459.                     score += 50;
  460.                 }
  461.                 else
  462.                 {
  463.                     score += 25;
  464.                 }
  465.             }
  466.  
  467.  
  468.             else if (biromes[g].transform.position.y <= -2.2f)
  469.             {
  470.                 Destroy(biromes[g]);
  471.                 biromes.RemoveAt(g);
  472.             }
  473.  
  474.         }
  475.  
  476.     }
  477.  
  478.     public void EliminarPendrive()
  479.     {
  480.         for (int h = 0; h < pendrives.Count; h++)
  481.         {
  482.             if (ComprobarColisiones(mochila, pendrives[h]) || ComprobarColisiones(mochilaGold, pendrives[h]))
  483.             {
  484.                 Destroy(pendrives[h]);
  485.                 pendrives.RemoveAt(h);
  486.                 if (timerpu2x < onTimepu2x)
  487.                 {
  488.                     score += 100;
  489.                 }
  490.                 else
  491.                 {
  492.                     score += 50;
  493.                 }
  494.             }
  495.  
  496.  
  497.             else if (pendrives[h].transform.position.y <= -2.2f)
  498.             {
  499.                 Destroy(pendrives[h]);
  500.                 pendrives.RemoveAt(h);
  501.             }
  502.  
  503.         }
  504.  
  505.     }
  506.  
  507.     public void EliminarGrabador()
  508.     {
  509.         for (int i = 0; i < grabadores.Count; i++)
  510.         {
  511.             if (ComprobarColisiones(mochila, grabadores[i]) || ComprobarColisiones(mochilaGold, grabadores[i]))
  512.             {
  513.                 Destroy(grabadores[i]);
  514.                 grabadores.RemoveAt(i);
  515.                 if (timerpu2x < onTimepu2x)
  516.                 {
  517.                     score += 150;
  518.                 }
  519.                 else
  520.                 {
  521.                     score += 75;
  522.                 }
  523.             }
  524.  
  525.  
  526.             else if (grabadores[i].transform.position.y <= -2.2f)
  527.             {
  528.                 Destroy(grabadores[i]);
  529.                 grabadores.RemoveAt(i);
  530.             }
  531.  
  532.         }
  533.  
  534.     }
  535.  
  536.     public void EliminarAuris()
  537.     {
  538.         for (int j = 0; j < auriss.Count; j++)
  539.         {
  540.             if (ComprobarColisiones(mochila, auriss[j]) || ComprobarColisiones(mochilaGold, auriss[j]))
  541.             {
  542.                 Destroy(auriss[j]);
  543.                 auriss.RemoveAt(j);
  544.                 if (timerpu2x < onTimepu2x)
  545.                 {
  546.                     score += 200;
  547.                 }
  548.                 else
  549.                 {
  550.                     score += 100;
  551.                 }
  552.             }
  553.  
  554.  
  555.             else if (auriss[j].transform.position.y <= -1.9f)
  556.             {
  557.                 Destroy(auriss[j]);
  558.                 auriss.RemoveAt(j);
  559.             }
  560.  
  561.         }
  562.  
  563.     }
  564.  
  565.     public void EliminarBowling()
  566.     {
  567.         for (int w = 0; w < bowlings.Count; w++)
  568.         {
  569.             if (ComprobarColisiones(mochila, bowlings[w]))
  570.             {
  571.                 Destroy(bowlings[w]);
  572.                 bowlings.RemoveAt(w);
  573.                 if (score - 100 < 0)
  574.                 {
  575.                     score = 0;
  576.                 }
  577.                 else
  578.                 {
  579.                     score -= 100;
  580.                 }
  581.             }
  582.  
  583.             else if (ComprobarColisiones(mochilaGold, bowlings[w]))
  584.             {
  585.                 Destroy(bowlings[w]);
  586.                 bowlings.RemoveAt(w);
  587.                 //Destroy(mochilaGold);
  588.  
  589.             }
  590.  
  591.  
  592.             else if (bowlings[w].transform.position.y <= -2.2f)
  593.             {
  594.                 Destroy(bowlings[w]);
  595.                 bowlings.RemoveAt(w);
  596.             }
  597.  
  598.         }
  599.  
  600.     }
  601.     #endregion
  602.  
  603.     public bool ComprobarColisiones(GameObject objA, GameObject objB)
  604.     {
  605.  
  606.         if (objA == null || objB == null)
  607.         {
  608.             return false;
  609.         }
  610.  
  611.         Collider2D collA = objA.GetComponent<Collider2D>();
  612.         Collider2D collB = objB.GetComponent<Collider2D>();
  613.  
  614.         bool colision = false;
  615.  
  616.         if (collA.bounds.Intersects(collB.bounds))
  617.         {
  618.             colision = true;
  619.         }
  620.  
  621.         return colision;
  622.  
  623.     }
  624.  
  625.     float timerGold;
  626.     float onTimeGold = 5;
  627.  
  628.     public void MochilaGold()
  629.     {
  630.  
  631.         for (int g = 0; g < pugolds.Count; g++)
  632.         {
  633.             if (ComprobarColisiones(mochila, pugolds[g]))
  634.             {
  635.                 mochilaGold = Instantiate(mochilaGoldMol);
  636.                 mochilasGold.Add(mochilaGold);
  637.                 mochilaGold.transform.position = new Vector3(0, -1.8f, 1);
  638.                 Destroy(pugolds[g]);
  639.                 pugolds.RemoveAt(g);
  640.                 timerGold = 0;
  641.             }
  642.  
  643.         }
  644.  
  645.  
  646.         timerGold += Time.deltaTime;
  647.  
  648.         for (int z = 0; z < mochilasGold.Count; z++)
  649.         {
  650.             float direccion;
  651.             direccion = Random.Range(1, 2f);
  652.  
  653.             if (direccion == 1)
  654.             {
  655.                 mochilasGold[z].transform.position += Vector3.right * Time.deltaTime * velocidadgold;
  656.             }
  657.  
  658.             else
  659.             {
  660.                 mochilasGold[z].transform.position += Vector3.left * Time.deltaTime * velocidadgold;
  661.             }
  662.  
  663.             if (mochilasGold[z].transform.position.x + Time.deltaTime * velocidad >= mochilaLimiteR.x)
  664.             {
  665.                 mochilasGold[z].transform.position = mochilaLimiteR;
  666.                 velocidadgold = -velocidadgold;
  667.             }
  668.  
  669.             else if (mochilasGold[z].transform.position.x + Time.deltaTime * velocidad <= mochilaLimiteL.x)
  670.             {
  671.                 mochilasGold[z].transform.position = mochilaLimiteL;
  672.                 velocidadgold = -velocidadgold;
  673.             }
  674.  
  675.             if (timerGold >= onTimeGold)
  676.             {
  677.                 Destroy(mochilasGold[z]);
  678.                 mochilasGold.RemoveAt(z);
  679.             }
  680.  
  681.             /*
  682.             if (mochilasGold[z] = null)
  683.             {
  684.                 mochilasGold.RemoveAt(z);
  685.  
  686.             }*/
  687.  
  688.         }
  689.     }
  690.  
  691.     public void DoubleScore()
  692.     {
  693.  
  694.         for (int d = 0; d < doubles.Count; d++)
  695.         {
  696.             if (ComprobarColisiones(mochila, doubles[d]))
  697.             {
  698.                 timerpu2x += Time.deltaTime;
  699.                 Destroy(doubles[d]);
  700.                 doubles.RemoveAt(d);
  701.  
  702.             }
  703.         }
  704.  
  705.         if (timerpu2x >= onTimepu2x)
  706.         {
  707.             timerpu2x = 0;
  708.         }
  709.  
  710.  
  711.     }
  712.  
  713.  
  714.     public void Plus10()
  715.     {
  716.         for (int p = 0; p < pu10pluss.Count; p++)
  717.         {
  718.             if (ComprobarColisiones(mochila, pu10pluss[p]))
  719.             {
  720.                 countDown += 10;
  721.                 Destroy(pu10pluss[p]);
  722.                 pu10pluss.RemoveAt(p);
  723.             }
  724.         }
  725.     }
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement