private IEnumerator Move() { ele = GO.GetComponent <Unite>(); deplacement = ele.deplacement; mouvement = ele.mouvement; if (deplacement != null) { if (deplacement.Count == 0) { ele.deplacement = null; mouvement = 0; } else { StartCoroutine("MoveTowards"); } } else { int rand = UnityEngine.Random.Range(7, 19); if (ele.camp.Equals("Ours")) { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 50, rand); } else { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 2, rand); } } yield break; }
public override bool Execute() { List <GameObject> ennemi = new List <GameObject>(); if (Go.GetComponent <Element>().camp == "Ours") { if (Niveau.list_element[1].Count > 0) { ennemi = Niveau.list_element[1]; } } else { if (Niveau.list_element[0].Count > 0) { ennemi = Niveau.list_element[0]; } } float distance = 1000; bool ispassed = false; Vector3 proche = new Vector3(); if (ennemi.Count > 0) { foreach (GameObject game in ennemi) { if (Vector3.Distance(Go.transform.position, game.transform.position) < distance) { distance = Vector3.Distance(Go.transform.position, game.transform.position); proche = game.transform.position; ispassed = true; } } } if (Niveau.list_element[2].Count > 0) { ennemi = Niveau.list_element[2]; foreach (GameObject game in ennemi) { if (Vector3.Distance(Go.transform.position, game.transform.position) < distance) { distance = Vector3.Distance(Go.transform.position, game.transform.position); proche = game.transform.position; ispassed = true; } } } if (ispassed) { Go.GetComponent <Unite>().deplacement = Niveau.boucle_path((int)Go.transform.position.x, (int)Go.transform.position.y, (int)proche.x, (int)proche.y); } return(true); }
private IEnumerator MoveTowards() { float tParam = 0; Vector3 pos = GO.transform.position; char direction = deplacement[0]; for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + GO.transform.position.x - 0.5), (int)(j + GO.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = false; ele.list_case[i, j].GetComponent <Case>().element = null; } } if (deplacement.Count != 0) { switch (direction) { case 'D': if (!Niveau.grille[(int)(GO.transform.position.x + 0.5), (int)(GO.transform.position.y - 0.5)].GetComponent <Case>().occupe) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + GO.transform.position.x + 0.5), (int)(j + GO.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = true; ele.list_case[i, j].GetComponent <Case>().element = GO.gameObject; } } GO.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 270)); while (GO.transform.position.x < pos.x + 1.0f) { tParam += Time.deltaTime; GO.transform.position = new Vector3(Mathf.Lerp(pos.x, pos.x + 1f, tParam), pos.y, pos.z); yield return(new WaitForSeconds(0.01f)); } deplacement.RemoveAt(0); } else { int rand = UnityEngine.Random.Range(7, 19); if (ele.camp.Equals("Ours")) { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 50, rand); } else { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 2, rand); } } break; case 'G': if (!Niveau.grille[(int)(GO.transform.position.x - 1.5), (int)(GO.transform.position.y - 0.5)].GetComponent <Case>().occupe) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + GO.transform.position.x - 1.5), (int)(j + GO.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = true; ele.list_case[i, j].GetComponent <Case>().element = GO.gameObject; } } GO.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90)); while (GO.transform.position.x > pos.x - 1.0f) { tParam += Time.deltaTime; GO.transform.position = new Vector3(Mathf.Lerp(pos.x, pos.x - 1f, tParam), pos.y, pos.z); yield return(new WaitForSeconds(0.01f)); } deplacement.RemoveAt(0); } else { int rand = UnityEngine.Random.Range(7, 19); if (ele.camp.Equals("Ours")) { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 50, rand); } else { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 2, rand); } } break; case 'H': if (!Niveau.grille[(int)(GO.transform.position.x - 0.5), (int)(GO.transform.position.y + 0.5)].GetComponent <Case>().occupe) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + GO.transform.position.x - 0.5), (int)(j + GO.transform.position.y + 0.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = true; ele.list_case[i, j].GetComponent <Case>().element = GO.gameObject; } } GO.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); while (GO.transform.position.y < pos.y + 1.0f) { tParam += Time.deltaTime; GO.transform.position = new Vector3(pos.x, Mathf.Lerp(pos.y, pos.y + 1f, tParam), pos.z); yield return(new WaitForSeconds(0.01f)); } deplacement.RemoveAt(0); } else { int rand = UnityEngine.Random.Range(7, 19); if (ele.camp.Equals("Ours")) { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 50, rand); } else { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 2, rand); } } break; case 'B': if (!Niveau.grille[(int)(GO.transform.position.x - 0.5), (int)(GO.transform.position.y - 1.5)].GetComponent <Case>().occupe) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + GO.transform.position.x - 0.5), (int)(j + GO.transform.position.y - 1.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = true; ele.list_case[i, j].GetComponent <Case>().element = GO.gameObject; } } GO.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 180)); while (GO.transform.position.y > pos.y - 1.0f) { tParam += Time.deltaTime; GO.transform.position = new Vector3(pos.x, Mathf.Lerp(pos.y, pos.y - 1f, tParam), pos.z); yield return(new WaitForSeconds(0.01f)); } deplacement.RemoveAt(0); } else { int rand = UnityEngine.Random.Range(7, 19); if (ele.camp.Equals("Ours")) { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 50, rand); } else { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 2, rand); } } break; } mouvement--; } else { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + GO.transform.position.x - 0.5), (int)(j + GO.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = true; ele.list_case[i, j].GetComponent <Case>().element = this.gameObject; } } } if (mouvement > 0 && deplacement[0] != null) { StartCoroutine("MoveTowards"); } yield break; }
public override bool Execute() { ele = Go.GetComponent <Unite>(); deplacement = ele.deplacement; mouvement = ele.mouvement; State etat = Go.GetComponent <State>(); Variable var = new Variable(); etat.GetVariable("prox", out var); if ((int)var.GetValue() == 1) { if (!calcule) { direction = 1; Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); deplacement = ele.deplacement; calcule = true; init = 1; } } else if ((int)var.GetValue() == 2) { if (!calcule) { direction = 2; Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); calcule = true; if (Go.GetComponent <Element>().camp == "Ours") { Score.ressource_IA[0] += Unite.stockage * init; Score.ressourcediv_IA[0][0] += Unite.stockage * init * Batiment.aggressivite / 100; Score.ressourcediv_IA[0][1] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100; Score.ressourcediv_IA[0][2] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100; } else if (Go.GetComponent <Element>().camp == "Poulpe") { Score.ressource_IA[1] += Unite.stockage * init; Score.ressourcediv_IA[1][0] += Unite.stockage * init * Batiment.aggressivite / 100; Score.ressourcediv_IA[1][1] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100; Score.ressourcediv_IA[1][2] += Unite.stockage * init * (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100; } } } else if ((int)var.GetValue() == 0) { calcule = false; } if (deplacement != null) { if (deplacement.Count != 0) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + Go.transform.position.x - 0.5), (int)(j + Go.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent <Case>().occupe = false; ele.list_case[i, j].GetComponent <Case>().element = null; } } StartCoroutine("MoveTowards"); } else { Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); mouvement = 0; } } return(true); }