Beispiel #1
0
 private void MoveEnemy(List <GameEntity> enemies, GameEntity player, Dictionary <Vector2Int, TileType> map)
 {
     enemies.ForEach(enemy => {
         PathNode result = BreadthFirst.GetRoute(enemy.gridCoordinate.value, player.gridCoordinate.value, map, 4);
         if (result != null)
         {
             enemy.ReplacePosition(result.GetFirstStep());
             enemy.ReplaceGridCoordinate(result.GetFirstStep());
         }
         else
         {
             Vector2Int randomPos = new List <Vector2Int> {
                 enemy.gridCoordinate.value + Vector2Int.up,
                 enemy.gridCoordinate.value + Vector2Int.down,
                 enemy.gridCoordinate.value + Vector2Int.left,
                 enemy.gridCoordinate.value + Vector2Int.right
             }.FindAll(pos => IsFloorTile(pos, map)).RandomItem();
             enemy.ReplacePosition(randomPos);
             enemy.ReplaceGridCoordinate(randomPos);
         }
         enemy.isMoveCompleted = true;
     });
 }