private void Awake() { level = new byte[levelTexture.width, levelTexture.height]; hexToIndex = new Dictionary <string, byte>(); foreach (TileTypes t in tileTypes) { hexToIndex.Add(t.hex, t.index); } for (int x = 0; x < levelTexture.width; x++) { for (int y = 0; y < levelTexture.height; y++) { Color color = levelTexture.GetPixel(x, y); string hex = ColorUtility.ToHtmlStringRGB(color); byte index = hexToIndex[hex]; level[x, y] = index; } } for (int x = 0; x < levelTexture.width; x++) { for (int y = 0; y < levelTexture.height; y++) { byte cell = level[x, y]; GameObject obj; if (cell == 0) //isAir { continue; } if (tileTypes[cell].isWall == true) { if (tileTypes[level[x, y - 1]].isWalkable || tileTypes[level[x, y - 1]].index == 5) { obj = Instantiate(tileTypes[cell].prefab[0], new Vector3(x, y), Quaternion.identity); obj.transform.parent = this.transform; } else { obj = Instantiate(tileTypes[cell].prefab[1], new Vector3(x, y), Quaternion.identity); obj.transform.parent = this.transform; } } else { obj = Instantiate(tileTypes[cell].prefab[0], new Vector3(x, y), Quaternion.identity); obj.transform.parent = this.transform; } } } grid.CreateGrid(level, levelTexture.width, levelTexture.height, tileTypes); }
private void actuallyCreateRoute(int roomIndex, Vector3 startPos, Vector3 endPos) { List <Vector3> tempRoute = new List <Vector3>(); //pathFinder.logThis("start = " + startPos + ", and end = " + endPos); grid.CreateGrid(rooms[roomIndex]); tempRoute = pathFinder.FindPathForOther(startPos - rooms[roomIndex].mapOffSet, endPos - rooms[roomIndex].mapOffSet, rooms[roomIndex].mapOffSet, false, -1); AddToRoute(tempRoute); }
public void Activate() { Vector3 global_max_pos = transform.TransformPoint(GetComponent <Room>().max_and_min_cam_pos[0]); Vector3 global_min_pos = transform.TransformPoint(GetComponent <Room>().max_and_min_cam_pos[1]); for (int i = 0; i < enemy_to_place.Count; i++) { GameObject new_enemy = Instantiate(enemy_to_place[i], transform.TransformPoint(location_to_place[i]), Quaternion.identity); new_enemy.GetComponent <Enemy>().SetRoomPosition(global_max_pos, global_min_pos); enemies.Add(new_enemy.GetComponent <Enemy>()); } Camera.main.GetComponent <CameraFollow>().SetMaxMinCameraPosForRoom(global_max_pos, global_min_pos); AddDoors(); activated = true; room_complete = false; pathfinding_grid.CreateGrid(); if (GetComponentInChildren <Flag>() != null) { GetComponentInChildren <Flag>().Activate(); } }
void UpdateVisibleChunks() { bool pathFound = false; CreateSpawn c = new CreateSpawn(); float maxHeight = mapGen.noiseSettings.maxHeight; WaterLevel.Instance.HasWater(WorldSettings.Instance.GetNoiseSettings().hasWater); int numTerrainsCreated = 0; while (!pathFound) { numTerrainsCreated++; //if(Input.GetKey(KeyCode.Escape)) break; createChunks(); grid.CreateGrid(maxHeight); pathFound = c.SpawnRandomAndFindPath(terrainChunkDictionary, numVisible, chunkSize, maxHeight); if (!pathFound) { mapGen.seed += 1; } } GameObject th = c.playerSpawn(townHall); GameObject eth = c.enemySpawn(enemyTownHall); spawn.SetBuildings(th, eth); grid.SetNodeUnwakable(th); grid.SetNodeUnwakable(eth); spawn.spawnTrees(maxHeight); Debug.Log("Terrins Created: " + numTerrainsCreated); }
private void Start() { gridScript.CreateGrid(); CreateResources(); UpdateNextToCityPlayer(casillaCityPlayer); UpdateNextToCityAI(casillaCityAI); }
private void PlaceBuilding() { layoutManager.SpawnStructure(curDraBuilding, toBeColorized, new Vector2(2, 2)); grid.CreateGrid(); StopDragging(); SwipeToEmpty(); }
// Use this for initialization void Start() { Grid grid = new Grid(rows, columns); ParseAndPopulateMap(); grid.CreateGrid(start_posX, start_posY, node_size, node_prefab, coordToType); }
private void UnitOrderer() { //Raycast yapıyoruz Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero); //Gerekli kontrolleri yapıp rayin buildarea ya çarptığına bakıyoruz if (hit != null && hit.collider != null && hit.transform.tag == "BuildArea") { //Gridi güncelliyoruz grid.CreateGrid(); //Ekranı oynatmamızı engelliyoruz movementStoperImage.gameObject.SetActive(true); foreach (UnitSelectionManager selected in UnitSelectionManager.currentlySelected) { // GetComponent optimize edilebilir. Seçili askerin myTarget değişkenine mouseun worldposition değerini atıyoruz. selected.GetComponent <Unit>().myTarget = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Seçili askerin GoToPosition metodunu çalıştırarak hedefe yolluyoruz. selected.GetComponent <Unit>().GoToPosition(); } } else { movementStoperImage.gameObject.SetActive(false); } }
public void buildingBuilt() { gr.CreateGrid(); foreach (GameObject broda in family) { broda.GetComponent <Unit>().ReCalcPath(); // REVIEW possible bottleneck } }
public override void OnInspectorGUI() { //displays the public variables base.OnInspectorGUI(); if (GUILayout.Button("Generate")) { grid = (Grid)target; grid.CreateGrid(); grid.CreateGrid(); } if (GUILayout.Button("Reset")) { grid = (Grid)target; grid.Reset(); } }
void Start () { //coloredGrid.AddComponent<RotateTowardsMouse> ().enabled = false; grid = gameObject.AddComponent<Grid> (); grid.CreateGrid (rows, columns); startPiece = Prefabs.CreateRandomPiece (0,0); startPiece.gameObject.AddComponent<DragDrop> (); }
//230*300 // Use this for initialization void Start() { enabled = false; Grid.CreateGrid(gridWidth, gridHeight, wallBlock); nextBlock = GetNewBlock(); NewBlock(); }
// Use this for initialization void Start() { grid = FindObjectOfType <Grid>(); unit = FindObjectOfType <Unit>(); pathFind = FindObjectOfType <pathfinding>(); map1.SetActive(true); //map2.SetActive(false); mapIndex = 1; grid.CreateGrid(); }
public List <Vector2> FindPath(Vector2 a_startPos, Vector2 a_targetPos) { grid.CreateGrid(); Node startNode = grid.NodeFromWorldPos(a_startPos); Node targetNode = grid.NodeFromWorldPos(a_targetPos); List <Node> OpenList = new List <Node>(); HashSet <Node> ClosedList = new HashSet <Node>(); OpenList.Add(startNode); while (OpenList.Count > 0) { Node currentNode = OpenList[0]; for (int i = 1; i < OpenList.Count; i++) { if (OpenList[i].FCost < currentNode.FCost || OpenList[i].FCost == currentNode.FCost && OpenList[i].hCost < currentNode.hCost) { currentNode = OpenList[i]; } } OpenList.Remove(currentNode); ClosedList.Add(currentNode); if (currentNode == targetNode) { return(GetFinalPath(startNode, targetNode)); } foreach (Node NeighborNode in grid.GetNeighborNodes(currentNode)) { if (NeighborNode.blocked || ClosedList.Contains(NeighborNode)) { continue; } int MoveCost = currentNode.gCost + GetManhattenDistance(currentNode, NeighborNode); if (MoveCost < NeighborNode.gCost || !OpenList.Contains(NeighborNode)) { NeighborNode.gCost = MoveCost; NeighborNode.hCost = GetManhattenDistance(NeighborNode, targetNode); NeighborNode.parent = currentNode; if (!OpenList.Contains(NeighborNode)) { OpenList.Add(NeighborNode); } } } } return(new List <Vector2>()); }
public override void OnInspectorGUI() { DrawDefaultInspector(); Grid grid = (Grid)target; if (GUILayout.Button("Build Grid")) { grid.CreateGrid(); } }
//Esta es la funcion que hay que llamar para que un objeto se mueva //Target --> Transform.Position o Vector3() a donde se movera la ficha. NULL EN CASO DE ATACAR VALOR SI NOS MOVEMOS A UN HUECO VACIO //maxPasos --> Pasos maximos que puede hacer la ficha //estaAtacando --> Booleano de si el objetivo esta atacando a una ficha o se esta moviendo // enemyTarget --> GameObject del objeto que vamos a atacar. NULL SI NO ESTAMOS MOVIENDO A UN TILE VACIO public void camino(Transform target, int maxpasos, bool estaAtacando, GameObject enemyTarget) { maxPasos = maxpasos; if (estaAtacando) { setLayers0(enemyTarget); setLayers0(this.gameObject); grid.CreateGrid(); PathRequestManager.RequestPath(transform.position, enemyTarget.transform.position, OnPathFound); setLayers9(enemyTarget); setLayers9(this.gameObject); } else { grid.CreateGrid(); PathRequestManager.RequestPath(transform.position, target.transform.position, OnPathFound); } }
public bool GenerateLevel() { level = new int[width, height]; RandomFillLevel(); for (int i = 0; i < smoothAmount; i++) { SmoothLevel(); } ProcessLevel(); int borderSize = 1; int[,] borderedLevel = new int[width + borderSize * 2, height + borderSize * 2]; for (int x = 0; x < borderedLevel.GetLength(0); x++) { for (int y = 0; y < borderedLevel.GetLength(1); y++) { if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize) { borderedLevel[x, y] = level[x - borderSize, y - borderSize]; } else { borderedLevel[x, y] = 0; } } } LevelMeshGenerator meshGen = GetComponent <LevelMeshGenerator>(); levelMeshData = meshGen.GenerateMesh(borderedLevel, sizeMultiplier); LevelPopulation popGen = GetComponent <LevelPopulation>(); popGen.DepopulateLevel(); if (populateLevel) { if (!popGen.PopulateLevel(borderedLevel, sizeMultiplier, levelMeshData)) { fillAmount++; GenerateLevel(); } } if (generateGrid) { Grid pathfindingGrid = GetComponent <Grid>(); pathfindingGrid.CreateGrid(); } return(true); }
public void StartMarching() { _gridScript.CreateGrid(); for (int i = 0; i < activeEnemyList.Count; i++) { if (activeEnemyList[i].gameObject.activeInHierarchy) { activeEnemyList[i].StartPath(); } } }
void Start() { GetInitialEntities(); GenerateBounds(); GenerateBuildings(); scoreCounter.UpdateLabel(score); grid.CreateGrid(); audioManager = GameObject.Find("Audio Manager").GetComponent <AudioManager>(); StartCoroutine(StartGame()); }
protected override Vector3 GeneratePosition() { GridReference.CreateGrid(); var path = FindPath(transform.position, PlayerMovement._destination); if (path != null && path.Any()) { var vec = new Vector3(path[0].vPosition.x, 0, path[0].vPosition.z); return(vec - transform.position); } return(Vector3.zero); }
public override void OnInspectorGUI() { myTarget = ( Grid )target; DrawDefaultInspector(); // Generate grid button if (GUILayout.Button("Generate Grid")) { GridConfigData gridData = GridDataReader.ReadData(myTarget.gridConfigFile); int [,] nodeData = NodeDataReader.ReadData(myTarget.nodeConfigFile); myTarget.CreateGrid(gridData, nodeData); } }
public void MakeMap() { map.NewMap(mapWidth, mapHeight); //map.UsePreset(1); int noOfEmptyRoom = 0; noOfEmptyRoom = map.CreateFloorsStartingFromTile(Mathf.Clamp(Random.Range(1, (map.rows) / 2 + 1), 1, ((map.rows) / 2) - 4), noOfEmptyRoom); //Mathf.Clamp(Random.Range(1, (map.rows) / 2+1),1, ((map.rows) / 2)-3) //Debug.Log(noOfEmptyRoom); map.CreateFloorsStartingFromTile(map.endRow + 1, noOfEmptyRoom); map.CreateWalls(); map.CompleteTheHouse(doorCount, percentOfWindows); grid.CreateGrid(map, tileSize, tilePrefab, mapContainer, wallTexture); }
public Bitmap Draw(string Value) { byte[] hash = new LemureHash().Compute(Value, HashType); Color = CreateBrushColor(hash); Grid = new Grid(this.Heigth, Width, SizeBlocks); Grid.CreateGrid(hash); List <BlockDrawing> blockDrawings = CreateBlockDrawing(Grid); return(CreateImageIcon(blockDrawings)); }
public void InitGame() { boardScript.SetupScene(level); turnScript.initObjects(); gridScript.gridWorldSize = new Vector2(boardScript.columns * boardScript.scale, boardScript.rows * boardScript.scale); gridScript.nodeRadius = boardScript.scale / 2; gridScript.CreateGrid(); //moved this to initgame so we can access player gold to display to this screen player = GameObject.Find("Player(Clone)").GetComponent <Unit>(); playerActive = true; levelCounter.text = "Level: " + level; totalGoldCounter.text = "Gold: " + player.gold; }
// Update is called once per frame void FixedUpdate() { if (health <= 0) { Instantiate(explosion, transform.position, transform.rotation); gameObject.SetActive(false); //Calls to update pathfinding grid for new map gridUpdater.CreateGrid(); if (Vector2.Distance(player.position, transform.position) <= 5) { player_script.curHealth -= 10; // If the player is too close he will be damaged } } }
public void StartBattle(Troop troop1, Control control1, Troop troop2, Control control2){ // OnUnitStackDeath += CheckIfBattleHasEnded; player1.id = PlayerID.LEFT; player1.troop = troop1; player1.control = control1; player1.losses = new Troop(); for (int i=0; i<troop1.units.Count; ++i){ if (troop1.units[i]!=null){ troop1.units[i].owner = player1.id; // for (int i2=0; i2<troop1.units[i].abilities.Count; ++i2) { // if (troop1.units[i].abilities[i2] is IOnStartMovement){ // ((IOnStartMovement)troop1.units[i].abilities[i2]).OnStartMovement(troop1.units[i]); // } // } } } player2.id = PlayerID.RIGTH; player2.troop = troop2; player2.control = control2; player2.losses = new Troop(); for (int i=0; i<troop2.units.Count; ++i){ if (troop2.units[i]!=null){ troop2.units[i].owner = player2.id; // for (int i2=0; i2<troop2.units[i].abilities.Count; ++i2) { // if (troop2.units[i].abilities[i2] is IOnStartMovement){ // ((IOnStartMovement)troop2.units[i].abilities[i2]).OnStartMovement(troop2.units[i]); // } // } } } grid.CreateGrid(); grid.SetUnitsToGrid (player1.troop, player1.id); grid.SetUnitsToGrid (player2.troop, player2.id); mouseInput.enabled =true; turn = PlayerID.NULL; mouseInput.OnMouseOnTile += OnMouseOverTile; mouseInput.OnMouseExitTile += OnMouseExitTile; mouseInput.OnMouseRigthClickTile += HandeMouseRigthClickTile; mouseInput.OnMouseRigthButtonkUp+= HandleOnMouseRigthButtonUp; OnTurnChange += ScaleVisualsToZeroOrDefault; OnTurnChange += RefreshVisualizationTilesOnTurnChange; StartCoroutine (ProcessAttackVisuals()); NextTurn (); }
void SetUpMap() { SpawnerManager.Instance.ResetSpawnerManager(); player_obj_script.SetLevel(player_obj_script.GetpStats().level + 1); player_prev_room = -1; spawned_exit = false; portal_obj_script.gameObject.SetActive(false); for (int i = 0; i < total_spawners.Length; ++i) { total_spawners[i].GetComponent <SpawnerBlock>().Reset(); total_spawners[i].SetActive(false); } for (int i = 0; i < total_quads.Length; ++i) { total_quads[i].SetActive(false); } GameObject [] delete_array = GameObject.FindGameObjectsWithTag("Coin"); for (int i = 0; i < delete_array.Length; ++i) { Destroy(delete_array[i]); } delete_array = GameObject.FindGameObjectsWithTag("Blessing"); for (int i = 0; i < delete_array.Length; ++i) { Destroy(delete_array[i]); } SetupTilesArray(); CreateRoomsAndCorridors(); SetTilesValuesForRooms(); SetTilesValuesForCorridors(); InstantiateTiles(); InstantiateOuterWalls(); AI_Controller_Grid.CreateGrid(); canvas_layout.GetComponent <UIScript>().SetRoomLevelLayout(); //canvas_layout.GetComponent<UIScript>().SetRoomObjective("Explore"); }
public void TestFromGrid() { var grid = Grid.CreateGrid(3, 4); var mazeBuilder = new BinaryTree(); mazeBuilder.Build(grid); var originalDefinition = GridTextConversion.ToText(grid); var newGrid = GridTextConversion.FromText(originalDefinition); Assert.NotNull(newGrid); var newDefinition = GridTextConversion.ToText(newGrid); StringAssert.Contains(originalDefinition, newDefinition); }
void Start() { Walls = new List <GameObject>(); Agent = GetComponentInChildren <RobotAgent>(); grid = GetComponent <Grid>(); grid.WorldBottomLeft = transform.position - Vector3.right * grid.gridWorldSize.x / 2 - Vector3.forward * grid.gridWorldSize.y / 2; grid.CreateGrid(); aStarPath = GetComponent <AStarPathFinding>(); aStarPath.grid = grid; aStarPath.seeker = Agent.transform; aStarPath.target = Target.transform; grid.player = Agent.transform; SetTargetAtRandomPosition(); initializeMap(); aStarPath.enabled = false; }
// Use this for initialization void Start() { grid = new Grid(); int[] types = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; grid.CreateGrid(width, height, types); Hex[][] map = grid.Map; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float xPos = x * xOffset; //Odd row? if (y % 2 == 1) { xPos = xPos + xOffset / 2f; } Hex t = map[x][y]; GameObject pref = tilesPrefabs[(int)t.type]; GameObject hex_go = (GameObject)Instantiate(pref, new Vector3(xPos, y * yOffset, 0f), Quaternion.identity, gameObject.transform); hex_go.name = t.type.ToString(); //Name and order game objects hex_go.GetComponentInChildren <SpriteRenderer>().sortingOrder = y * -1; hex_go.name = "Hex_" + x + "_" + y; hex_go.GetComponent <Hex>().x = x; hex_go.GetComponent <Hex>().y = y; //Parent this hex to the map hex_go.transform.SetParent(this.transform); } } Unit hound = GameObject.Find("Hellhound sprite").GetComponent <Unit>(); GameObject hex = GameObject.Find("Hex_0_0"); hound.currentHex = hex; //GameObject.Find("Hellhound sprite").GetComponent<Unit>().currentHex = GameObject.Find("Hex_0_0"); }
//Populates Nodes of grid with parents void PopulateGrid() { processQueue = new Queue(); grid.CreateGrid(); Node endNode = grid.NodeFromPos(end.position); endNode.Distance = 0; endNode.DegreesSeperation = 0; processQueue.Enqueue(endNode); while (processQueue.Count > 0) { EnqueueAdjacentNodes((Node)processQueue.Dequeue()); } }