League of Morgan - Hackveneno

Programación Orientada a Objetos (Tower defense - kingdom rush)

Moderator: julianmartinez16

User avatar
HugoHernandez2000
Posts: 22
Joined: Tue Jan 22, 2019 2:06 pm

Re: League of Morgan - Hackveneno

Post by HugoHernandez2000 » Sun May 19, 2019 11:30 pm

Semana 14-15-16
Actividades:
  • Debido a tantos errores en el juego tomamos la decisión de empezar de cero el juego sin cambiar la esencia del juego antes planeado.
  • Se realizó el diseño de un nuevo mapa, se implementaron nuevos diseños en el juego, como lo son un zombie(representa las enfermedades que trajeron los conquistadores a America), caballeros y una choza la cual da monedas para poder poder las torretas
  • Se diseñaron e implemetaron las clases; Barco, Barco2, Caballero, Flecha, GameManager, InstaciadorDeBarcos, Torre, Unidades, Zombie
  • Realizar el diagrama de Clases del nuevo Juego
  • Realizar las diapositivas de la EntregaFinal
  • Organizar la planeación del juego
  • Realizar el GameOver del juego
Arte del Juego:
Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Codigo:
  • Zombie

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Zombie : MonoBehaviour
{
    public int vida = 8;
    public float velocidad;
    public LayerMask layerTorre;

    public float cadencia = 1f;

    float cadAux = 0;

    void Update()
    {

        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector3.left, .5f, layerTorre);
        if (hit.collider != null)
        {
            cadAux += Time.deltaTime;
            if (cadAux >= cadencia)
            {
                cadAux = 0;
                hit.collider.SendMessage("Atacar");
            }


        }
        else
        {
            cadAux = 0;
            transform.position -= Vector3.right * velocidad * Time.deltaTime;
        }

    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Flecha"))
        {
            vida--;
            Destroy(col.gameObject);

            if (vida <= 0)
                Destroy(gameObject);
        }

    }
}
  • Unidades

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Unidades : MonoBehaviour
{
    public GameObject ruta;
    private int indice;
    private Vector3 posicion_siguiente;
    private float vel=0.7f;
    private float distacia_punto = 0.5f;

     void Start()
    {
        posicion_siguiente = ruta.transform.GetChild(0).position;
    }

    void Update()
    {
        Vector3 dir = posicion_siguiente - this.transform.position;
        this.transform.position += dir * vel * Time.deltaTime;

        if(dir.magnitude <= distacia_punto)
        {
            if(indice+1 < ruta.transform.childCount)
            {
                indice++;
                posicion_siguiente = ruta.transform.GetChild(indice).position;
                Debug.Log("xs" + posicion_siguiente.x + "ys" + posicion_siguiente.y);
            }
        }
    }
}
  • Torre

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class Torre : MonoBehaviour
{
    public Sprite cartaAsignada;
    public int precioMonedas;
    public int vida;
    
    void Atacar()
    {
        vida--;
        if (vida <= 0)
            Destroy(gameObject);
    }
}
  • Instanciador de Barcos

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InstanciadorDeBarcos : MonoBehaviour
{

    public int[] tiempos;

    public float frecuenciaBarcos = 10;
    public GameObject Barco;

    void Start()
    {
       for(int i =0; i<tiempos.Length; i++)
        {
            Invoke("InstanciarBarco", tiempos[i]);
        }
    }
    void InstanciarBarco()
    {
         Instantiate(Barco, transform.position, Barco.transform.rotation) ;
    }
}
  • Game Manager

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager1 : MonoBehaviour
{
    public List<Torre> torreAUsar;

    
    public GameObject Deck;
    public GameObject PrefabCarta;

    public Text TxtMonedas;

    int Monedas = 200;
    int TorreAusar = 0;
   
    void Start()
    {
        ActualizarMonedas(0);
        for (int i = 0; i<torreAUsar.Count; i++)
        {
            GameObject go = Instantiate(PrefabCarta) as GameObject;
            go.transform.SetParent(Deck.transform);
            go.transform.position = Vector3.zero;
            go.transform.localScale = Vector3.one;

            Image img = go.GetComponent<Image>();
            img.sprite = torreAUsar[i].cartaAsignada;

            Button bot = go.GetComponent<Button>();
            bot.onClick.RemoveAllListeners();
            int u =i;
            bot.onClick.AddListener(() => { TorreAusar =   u; });
        }
    }

    void Update ()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(r.origin,r.direction);
            if(hit.collider != null)
            {
                if (hit.collider.CompareTag("cuadricula"))
                {
                    Transform t = hit.collider.transform;
                    CrearTorre(TorreAusar, t);
                }
                else if (hit.collider.CompareTag("Monedas"))
                {
                    ActualizarMonedas(50);
                    Destroy(hit.collider.gameObject);
                }
                
                
            }
        }
    }

    void CrearTorre(int numero, Transform t)
    {
        if (torreAUsar[numero].precioMonedas > Monedas)
            return;
        if (t.childCount != 0)
            return;

        GameObject g = Instantiate(torreAUsar[TorreAusar].gameObject, t.position, gameObject.transform.rotation) as GameObject;
        g.transform.SetParent(t);

        ActualizarMonedas(-torreAUsar[numero].precioMonedas);
    }

    public void ActualizarMonedas(int Add)
    {
        Monedas += Add;
        TxtMonedas.text = Monedas.ToString();
    }
}
  • Flecha

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Flecha : MonoBehaviour
{
    public int velocidad = 3;
    public int dano = 1;


    private void Update()
    {
        transform.position += Vector3.right * velocidad * Time.deltaTime;
    }
}
  • Caballero

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Caballero : MonoBehaviour
{
    public int vida = 4;
    public float velocidad;
    public LayerMask layerTorre;

    public float cadencia = 1f;

    float cadAux = 0;

    void Update()
    {

        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector3.left, .5f, layerTorre);
        if (hit.collider != null)
        {
            cadAux += Time.deltaTime;
            if (cadAux >= cadencia)
            {
                cadAux = 0;
                hit.collider.SendMessage("Atacar");
            }


        }
        else
        {
            cadAux = 0;
            transform.position -= Vector3.right * velocidad * Time.deltaTime;
        }

    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Flecha"))
        {
            vida--;
            Destroy(col.gameObject);

            if (vida <= 0)
                Destroy(gameObject);
        }

    }
}
  • Barco

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Barco : MonoBehaviour
{
    public int vida = 4;
    public float velocidad;
    public LayerMask layerTorre;

    public float cadencia = 1f;

    float cadAux = 0;

   void Update()
    {
        
        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector3.left, .5f, layerTorre);
        if(hit.collider != null)
        {
            cadAux += Time.deltaTime;
            if(cadAux >= cadencia)
            {
                cadAux = 0;
                hit.collider.SendMessage("Atacar");
            }
            

        }
        else
        {
            cadAux = 0;
            transform.position -= Vector3.right * velocidad * Time.deltaTime;
        }
        
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Flecha"))
        {
            vida--;
            Destroy(col.gameObject);

            if (vida <= 0) 
                Destroy(gameObject);   
        }
        if (col.CompareTag("FailState"))
        {
            Destroy(gameObject);
            print("Has perdido");
        }
    }


}
  • Barco2

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Barco2 : MonoBehaviour
{
    public int vida = 8;
    public float velocidad;
    public LayerMask layerTorre;

    public float cadencia = 1f;

    float cadAux = 0;

    void Update()
    {

        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector3.left, .5f, layerTorre);
        if (hit.collider != null)
        {
            cadAux += Time.deltaTime;
            if (cadAux >= cadencia)
            {
                cadAux = 0;
                hit.collider.SendMessage("Atacar");
            }


        }
        else
        {
            cadAux = 0;
            transform.position -= Vector3.right * velocidad * Time.deltaTime;
        }

    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Flecha"))
        {
            vida--;
            Destroy(col.gameObject);

            if (vida <= 0)
                Destroy(gameObject);
        }

    }
}
Hugo Alejandro Hernández Cárdenas
POO#2

User avatar
HugoHernandez2000
Posts: 22
Joined: Tue Jan 22, 2019 2:06 pm

Re: League of Morgan - Hackveneno

Post by HugoHernandez2000 » Fri May 24, 2019 10:31 am

  • Diagrama de Clases
Image
Hugo Alejandro Hernández Cárdenas
POO#2

Post Reply