private void Awake() { npcObject = gameObject.GetComponent <ActivityObject>(); manager = GameObject.FindObjectOfType <WorldManager>(); algo = new ASTAR(); currentState = new State(); path = new List <Node>(); durration_stemp = Time.time; self_name = gameObject.name; health = status.good; canvas = new CanvasActivity(transform.name, 6); canvas_object.setViewParameterForCanvas(canvas); }
private void RunFewestPaths(object e) { object[] cbs = (object[])e; ComboBox from = (ComboBox)cbs[0]; ComboBox to = (ComboBox)cbs[1]; if (from.SelectedIndex == -1 || to.SelectedIndex == -1) { return; } ASTAR.Search(from.SelectedIndex, to.SelectedIndex, graph, false); }
public override void Movement() { Rotation(); if (Vector2.Distance(transform.position, playerOffset.position) <= viewDistance.TotalValue && path.Count <= 0) { path = ASTAR.FindPath(Vector2Int.FloorToInt(Offset.position), Vector2Int.FloorToInt(playerOffset.position)); CombatSystem.AddCombatant(this); } if (path is null || path.Count <= 0) { CombatSystem.RemoveCombatant(this); return; } var pos = path.Peek().GetVectorInt() - Vector2Int.FloorToInt(Offset.localPosition); movement = (pos - (Vector2)transform.position).normalized; transform.position += (Vector3)movement * speed.TotalValue * Time.deltaTime; if (Vector2.Distance(transform.position, pos) < .1f) path.Pop(); }
void Awake() { aStarAlgorithm = GetComponent <ASTAR>(); instance = this; }
private void Decode_ASTAR_Contenu(Communication.Communication_Message message) { ASTAR.Reception_Message_Astar(message.Trame); }
public static void GameLoop() { var ret = string.Empty; List <Point> newPositions = new List <Point> { new Point { x = game.Explorateurs[0].Position.x + 1, y = game.Explorateurs[0].Position.y }, new Point { x = game.Explorateurs[0].Position.x - 1, y = game.Explorateurs[0].Position.y }, new Point { x = game.Explorateurs[0].Position.x, y = game.Explorateurs[0].Position.y + 1 }, new Point { x = game.Explorateurs[0].Position.x, y = game.Explorateurs[0].Position.y - 1 }, }; Point bestPosition = null; //Eviter les slashers foreach (var slasher in game.Slashers) { if ((game.Explorateurs[0].IsVisibleBy(slasher, game.Map))) { Console.Error.WriteLine("EN DANGER SLASHER!!!!"); //On doit se déplacer à un endroit sans risque foreach (var newPosition in newPositions) { if (game.Map[(int)newPosition.x, (int)newPosition.y] == '.' && newPosition.x != slasher.Position.x && newPosition.y != slasher.Position.y) { ret = "MOVE " + newPosition.x + " " + newPosition.y + " Tentative d'esquive du slasher"; continue; } } } } //Si en danger, on prend un soin if (string.IsNullOrEmpty(ret) && game.Explorateurs[0].health < 100 && game.Explorateurs[0].state > 0) { ret = "PLAN"; } if (string.IsNullOrEmpty(ret) && game.Shelters.Count(s => s.health > 0) > 0) { //On prend l'abri le plus proche var nearest = game.Shelters.OrderBy(s => s.Position.DistanceTo(game.Explorateurs[0].Position)).Where(s => s.health > 0).FirstOrDefault(); if (nearest != null) { var chemin = new ASTAR(); var nextCase = chemin.GetChemin(game.Explorateurs[0].Position, nearest.Position, game.Map); ret = "MOVE " + nextCase.x + " " + nextCase.y; } } if (string.IsNullOrEmpty(ret)) { //On essaye de se déplacer foreach (var newPosition in newPositions) { List <Player> enemyList = new List <Player>(); enemyList.AddRange(game.Wanderers.Where(w => w.state != (int)State.SPAWNING)); enemyList.AddRange(game.Slashers.Where(w => (w.state != (int)State.SPAWNING) && w.state != (int)State.STUNNED)); if (game.Map[(int)newPosition.x, (int)newPosition.y] == '.' && enemyList.Count > 0) { Console.Error.WriteLine("Test de " + newPosition.x + " " + newPosition.y); if (bestPosition == null) { bestPosition = newPosition; } var nearest = enemyList.OrderBy(w => w.Position.DistanceTo(game.Explorateurs[0].Position)).FirstOrDefault(); Console.Error.WriteLine("best Distance " + bestPosition.DistanceTo(nearest.Position)); Console.Error.WriteLine("new Distance " + newPosition.DistanceTo(nearest.Position)); //On teste si on s'éloigne du minion, on doitaussi tester que la nouvelle position ne va pas nous mettre sur la case d'un Slasher if (bestPosition.DistanceTo(nearest.Position) < newPosition.DistanceTo(nearest.Position)) { foreach (var slasher in game.Slashers) { if (newPosition.x != slasher.Position.x && newPosition.y != slasher.Position.y) { bestPosition = newPosition; continue; } } } ret = "MOVE " + bestPosition.x + " " + bestPosition.y; } } } if (!string.IsNullOrEmpty(ret)) { Console.WriteLine(ret); // MOVE <x> <y> | WAIT } else { Console.WriteLine("WAIT"); } }
protected override void Awake() { base.Awake(); Tilemap map = GameObject.Find("Walkable").GetComponent<Tilemap>(); ASTAR.SetTilemap(map); }