PRE-ENTREGA
Posted: Tue Apr 02, 2019 2:50 am
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Barra_Vida : MonoBehaviour
{
public GameObject Enemigo;
public GameObject Barra;
SpriteRenderer sr;
private Vector3 Completa;
public Unidad colision;
public Animator anim;
private Rigidbody rb;
public int vida;
// Use this for initialization
void Start()
{
rb = colision.GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
anim.SetInteger("EstadoVida", 100);
sr = Completa.GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update()
{
vida = anim.GetInteger("EstadoVida");
Debug.Log(this.name + vida);
anim.SetInteger("EstadoVida", vida);
if (colision.impacto == 1)
{
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida - 20);
}
if (colision.impacto == 2)
{
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida - 10);
}
if (vida < 0 || vida < -1 || vida == -10)
{
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida * 0);
vida = 0;
if (vida < 0 && vida < -1 && vida == -10)
{
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida * 0);
vida = 0;
}
}
if (vida == 0)
{
colision.muerte = true;
if (colision.muerte == true)
{
colision.numero_muertes = colision.numero_muertes + 1;
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida + 100);
Debug.Log(vida);
Muerte();
if (vida < 0 && vida < -1 && vida == -10)
{
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida * 0);
}
}
}
if (vida < 0 && vida < -1 && vida == -10)
{
vida = anim.GetInteger("EstadoVida");
anim.SetInteger("EstadoVida", vida * 0);
}
if (colision.numero_muertes == colision.muerte_definitiva)
{
colision.transform.position = colision.posicion_inicial;
}
}
public void Muerte()
{
colision.indice = 0;
colision.transform.position = colision.posicion_inicial;
colision.posicion_siguiente = colision.ruta.transform.GetChild(colision.indice).position;
Debug.Log("Muerte");
colision.muerte = false;
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemigos : MonoBehaviour
{
public GameObject ruta;
private int indice;
private Vector3 pos_siguiente;
public float vel;
private float dis_punto = 0.5f ;
[SerializeField]
private int vida;
private const string FLECHA = "Flecha";
private const string BASE = "Base";
private const string AURA = "Aura";
void Start()
{
pos_siguiente = ruta.transform.GetChild(0).position;
}
void Update()
{
Vector3 dir = pos_siguiente - this.transform.position;
this.transform.position += dir * vel * Time.deltaTime;
//this.transform.position = this.transform.position+("")
if (dir.magnitude <= dis_punto)
{
if (indice + 1 < ruta.transform.childCount)
{
indice++;
pos_siguiente = ruta.transform.GetChild(indice).position;
//Debug.Log("xs= " + pos_siguiente.x + ", ys= " + pos_siguiente.y);
}
else
{
indice = 0;
this.transform.position = pos_siguiente;
pos_siguiente = ruta.transform.GetChild(0).position;
}
}
}
void Muerte()
{
Oleadas.Enemigos.Remove(this.gameObject);
Destroy(this.gameObject);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag.Equals(FLECHA))
{
Debug.Log("La vida es: " + vida);
vida = vida - 2;
if (vida <= 0)
{
Muerte();
}
}
if (collision.gameObject.tag.Equals(AURA))
{
vida = vida - 3;
Debug.Log("La vid es:" + vida);
if(vida<=0)
{
Muerte();
}
}
if (collision.gameObject.tag.Equals(BASE))
{
Muerte();
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Oleadas : MonoBehaviour {
private static List<GameObject> enemigos = new List<GameObject>();
[SerializeField]
private GameObject enemigo1;
[SerializeField]
private GameObject enemigo2;
[SerializeField]
private GameObject enemigo3;
[SerializeField]
private Transform spawn;
private int waves = 5;
private int contador = 0;
private static int seg = 0;
private static int inicio_oleada = 100;
public static List<GameObject> Enemigos
{
get
{
return enemigos;
}
set
{
enemigos = value;
}
}
void Oleada1()
{
GameObject temp;
Vector3 pos_inicial = spawn.position;
Vector3 incremento = new Vector3(0, -5);
Vector3 n = new Vector3(0, -10);
for(int i=0;i<2;i++)
{
temp = Instantiate(enemigo1, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp.transform.position;
Enemigos.Add(temp);
}
}
void Oleada2()
{
GameObject temp;
Vector3 pos_inicial = spawn.position;
Vector3 incremento = new Vector3(0, -5);
for (int i = 0; i < 4; i++)
{
temp = Instantiate(enemigo1, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp.transform.position;
Enemigos.Add(temp);
}
}
void Oleada3()
{
GameObject temp;
GameObject temp2;
Vector3 pos_inicial = spawn.position;
Vector3 incremento = new Vector3(0,-5);
for(int i =0; i<4;i++)
{
temp = Instantiate(enemigo1, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp.transform.position;
Enemigos.Add(temp);
if (i>=2)
{
temp2 = Instantiate(enemigo2, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp2.transform.position;
Enemigos.Add(temp2);
}
}
}
void Oleada4()
{
GameObject temp;
GameObject temp2;
Vector3 pos_inicial = spawn.position;
Vector3 incremento = new Vector3(0, -5);
for (int i = 0; i < 6; i++)
{
temp = Instantiate(enemigo1, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp.transform.position;
Enemigos.Add(temp);
if (i >= 3)
{
temp2 = Instantiate(enemigo2, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp2.transform.position;
Enemigos.Add(temp2);
}
}
}
void Oleada5()
{
GameObject temp;
GameObject temp2;
GameObject temp3;
Vector3 pos_inicial = spawn.position;
Vector3 incremento = new Vector3(0, -5);
for (int i = 0; i < 4; i++)
{
temp = Instantiate(enemigo1, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp.transform.position;
Enemigos.Add(temp);
if (i >= 2)
{
temp2 = Instantiate(enemigo2, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp2.transform.position;
Enemigos.Add(temp2);
}
if (i == 3)
{
temp3 = Instantiate(enemigo3, pos_inicial + incremento, Quaternion.identity);
pos_inicial = temp3.transform.position;
Enemigos.Add(temp3);
}
}
}
// Update is called once per frame
void Update () {
if (Enemigos.Count == 0)
{
seg += 1;
Debug.Log(seg);
if (seg > inicio_oleada)
{
contador++;
seg = 0;
if (contador == 1)
{
Oleada1();
Debug.Log("Oleada 1");
}
else if (contador == 2)
{
Oleada2();
Debug.Log("Oleada 2");
}
else if (contador == 3)
{
Oleada3();
Debug.Log("Oleada 3");
}
else if (contador == 4)
{
Oleada4();
Debug.Log("Oleada 4");
}
else if (contador == 5)
{
Oleada5();
Debug.Log("Oleada 5");
}
if(contador>waves)
{
SceneManager.LoadScene("Ganar");
}
}
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Torres : MonoBehaviour {
private GameObject enemigo;
private float UmbraldeDistancia = 3f;
[SerializeField]
private GameObject disparo;
private float seg;
public GameObject Enemigo
{
get
{
return enemigo;
}
set
{
enemigo = value;
}
}
void Start()
{
seg=30f;
}
GameObject BuscarEnemigos()
{
List<GameObject> objetivos = Oleadas.Enemigos;
GameObject temp;
foreach(Object item in objetivos)
{
temp = (GameObject)item;
if (Vector3.Distance(temp.transform.position, this.transform.position)<UmbraldeDistancia)
{
return temp;
}
}
return null;
}
void Disparar()
{
GameObject obj = Instantiate(disparo, this.transform.position, Quaternion.identity);
Flechas flecha = obj.GetComponent<Flechas>();
flecha.ActivarFlecha(this);
}
// Update is called once per frame
void Update()
{
seg += 1 + Time.deltaTime;
Enemigo = BuscarEnemigos();
if(seg>30f)
{
seg = 0f;
if (Enemigo != null)
{
Disparar();
//Debug.Log("Disparo");
Debug.DrawLine(this.transform.position, enemigo.transform.position, Color.green);
}
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moneda : MonoBehaviour {
public GameObject centenas, decenas, unidades;
private Animator ce, de, un;
private string[] estado = { "Moneda_0", "Moneda_1", "Moneda_2", "Moneda_3", "Moneda_4", "Moneda_5", "Moneda_6", "Moneda_7", "Moneda_8", "Moneda_9" };
private float tiempoLimite = 50f;
private float tiempo = 0f;
private int dinero;
private bool compro;
private static Moneda instancia = new Moneda();
public int Dinero
{
get
{
return dinero;
}
set
{
dinero = value;
}
}
public bool Compro
{
get
{
return compro;
}
set
{
compro = value;
}
}
public static Moneda Instancia
{
get
{
return instancia;
}
set
{
instancia = value;
}
}
// Use this for initialization
void Start()
{
ce = centenas.GetComponent<Animator>();
de = decenas.GetComponent<Animator>();
un = unidades.GetComponent<Animator>();
Instancia.Dinero = 50;
ActualizadorContador(Instancia.Dinero);
}
// Update is called once per frame
void Update()
{
if(Instancia.Compro==true)
{
ActualizadorContador(Instancia.Dinero);
tiempo++;
if (tiempo > tiempoLimite)
{
Instancia.Dinero ++;
ActualizadorContador(Instancia.Dinero);
tiempo = 0;
}
}
}
public void ActualizadorContador(int numero)
{
int unidades = numero % 10;
int decenas = numero % 100 - unidades;
int centenas = numero % 1000 - decenas;
//Debug.Log("numero " + numero + " centenas " + centenas / 100 + " decenas " + decenas / 10 + " unidades " + unidades);
decenas = decenas / 10;
centenas = centenas / 100;
if (numero > 9)
{
de.Play(estado[decenas]);
}
else
{
de.Play(estado[0]);
}
if (numero > 99)
{
ce.Play(estado[centenas]);
}
else
{
ce.Play(estado[0]);
}
un.Play(estado[unidades]);
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class T_Barrera : LogicaTorres
{
[SerializeField]
private GameObject letrero;
public override void OnMouseDown()
{
if (Moneda.Instancia.Dinero >= 60)
{
Moneda.Instancia.Dinero -= 60;
Moneda.Instancia.Compro = true;
GameObject temp;
Vector3 pos = this.transform.position;
pos.y = pos.y + y;
pos.x = pos.x + x;
temp = Instantiate(torre);
temp.transform.position = pos;
temp.layer = 5;
Destroy(letrero.gameObject);
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class T_Letrero : LogicaTorres
{
public override void OnMouseDown()
{
GameObject temp;
Vector3 pos = this.transform.position;
pos.y = pos.y + y;
pos.x = pos.x + x;
temp = Instantiate(torre);
temp.transform.position = pos;
temp.layer = 5;
Destroy(this.gameObject);
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class LogicaTorres : MonoBehaviour {
// Use this for initialization
[SerializeField]
protected GameObject torre;
[SerializeField]
protected float y;
[SerializeField]
protected float x;
public abstract void OnMouseDown();
}
Code: Select all
public class T_Iglesia : LogicaTorres
{
[SerializeField]
private GameObject letrero;
public override void OnMouseDown()
{
if (Moneda.Instancia.Dinero >= 75)
{
Moneda.Instancia.Dinero -= 75;
Moneda.Instancia.Compro = true;
GameObject temp;
Vector3 pos = this.transform.position;
pos.y = pos.y + y;
pos.x = pos.x + x;
temp = Instantiate(torre);
temp.transform.position = pos;
temp.layer = 5;
Destroy(letrero.gameObject);
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class T_Arcos : LogicaTorres
{
[SerializeField]
private GameObject letrero;
public override void OnMouseDown()
{
if(Moneda.Instancia.Dinero>=50)
{
Moneda.Instancia.Dinero -= 50;
Moneda.Instancia.Compro = true;
GameObject temp;
Vector3 pos = this.transform.position;
pos.y = pos.y + y;
pos.x = pos.x + x;
temp = Instantiate(torre);
temp.transform.position = pos;
temp.layer = 5;
Destroy(letrero.gameObject);
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Iglesia : MonoBehaviour
{
[SerializeField]
private GameObject aura;
[SerializeField]
private Transform creacion;
[SerializeField]
private float tiempo_aura;
private bool activar;
public static int seg;
private const string ENEMIGO = "Enemigo";
private void Start()
{
seg = 300;
}
void Update()
{
seg = 1 + seg;
if (seg > 300)
{
activar = true;
}
else
{
activar = false;
}
}
private void ActivarAura()
{
GameObject crear_aura = Instantiate(aura, creacion.position, creacion.rotation);
Destroy(crear_aura.gameObject, tiempo_aura);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag.Equals(ENEMIGO))
{
if(activar == true)
{
ActivarAura();
seg = 0;
}
}
}
}