private void bfs(Queue <Utility.Coord> cellQueue, int i, int distance, int movementCells, bool[,] visitedMap) { while (cellQueue.Count > 0 && distance <= movementCells * 2) { Utility.Coord currentCell = cellQueue.Dequeue(); Debug.Log(currentCell.x + " " + currentCell.y); if (currentCell.x >= 0 && currentCell.x < mapSize.x && currentCell.y >= 0 && currentCell.y < mapSize.y) { tileclass = map[currentCell.x, currentCell.y].GetComponent <TileClass>(); if (tileclass.getType() != 2 && distance <= movementCells) { //paint blue Debug.Log("Cell " + currentCell.x + " " + currentCell.y + " is painted BLUE"); //cellQueue.Enqueue(currentCell); if (tileclass.getType() == 1) { distance += 2; } else { distance++; } for (int j = 0; j < 8; j++) { cellQueue.Enqueue(currentCell.Add(neighbours[i])); bfs(cellQueue, j, distance, movementCells, visitedMap); } } else if (tileclass.getType() != 2 && distance <= movementCells * 2) { //paint yellow Debug.Log("Cell " + currentCell.x + " " + currentCell.y + " is painted YELLOW"); //cellQueue.Enqueue(currentCell); if (tileclass.getType() == 1) { distance += 2; } else { distance++; } for (int j = 0; j < 8; j++) { cellQueue.Enqueue(currentCell.Add(neighbours[i])); bfs(cellQueue, j, distance, movementCells, visitedMap); } } } } }
private void showPlayerMovementArea(int movementCells) { //Debug.Log("Movement Range = " + movementCells); int distance = 0; Queue <Utility.Coord> cellQueue = new Queue <Utility.Coord>(); visitedMap = new bool[(int)mapSize.x, (int)mapSize.y]; //cellQueue.Enqueue (playerCoords); Debug.Log("Boris is in: " + playerCoords.x + " " + playerCoords.y); for (int i = 0; i < 8; i++) { Debug.Log("volta de bucle: " + i + " cellQueue size: " + cellQueue.Count); cellQueue.Enqueue(playerCoords.Add(neighbours[i])); bfs(cellQueue, i, distance, movementCells, visitedMap); } }
// Update is called once per frame void Update() { switch (currentState) { case GameState.StandBy: break; case GameState.Idle: if (!Cooldown) { temporal = cursorCoords; //Debug.Log(temporal.x + " " + temporal.y); //Debug.Log(cursorCoords.x + " " + cursorCoords.y); //Debug.Log("Idle"); //if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)) CursorMove("DUpLeft"); //else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)) CursorMove("DUpRight"); //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)) CursorMove("DDownRight"); //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)) CursorMove("DDownLeft"); if (Input.GetKey(KeyCode.A)) { CursorMove("Left"); } else if (Input.GetKey(KeyCode.W)) { CursorMove("Up"); } else if (Input.GetKey(KeyCode.D)) { CursorMove("Right"); } else if (Input.GetKey(KeyCode.S)) { CursorMove("Down"); } Invoke("ResetCoodldown", 0.10f); Cooldown = true; } if (Input.GetKeyDown(KeyCode.Space)) { SetStateStandBy(); //for(int i = 0; i <= 1000; i++) {Debug.Log(i);} combatControllerScript.EndTurn(); } break; case GameState.PlayerMovement: //Debug.Log(position.x + " " + position.y); temporal = cursorCoords; if (!Cooldown) { //Debug.Log("PlayerMovement"); //Debug.Log(playerCoords.Difference(cursorCoords.Add(new Utility.Coord(-1,0)))); //Debug.Log(playerCoords.x + " " + playerCoords.y); //Debug.Log(temporal.x + " " + temporal.y); //Debug.Log(cursorCoords.x + " " + cursorCoords.y); //if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)) CursorMove("DUpLeft"); //else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)) CursorMove("DUpRight"); //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)) CursorMove("DDownRight"); //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)) CursorMove("DDownLeft"); (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(-1, 0)))).getType(); if (Input.GetKey(KeyCode.A) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(-1, 0)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(-1, 0))) <= maxplayerDistance) { //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0)))); CursorMove("Left"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } else if (Input.GetKey(KeyCode.W) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(0, 1)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, 1))) <= maxplayerDistance) { //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0)))); CursorMove("Up"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } else if (Input.GetKey(KeyCode.D) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(1, 0)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(1, 0))) <= maxplayerDistance) { //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0)))); CursorMove("Right"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } else if (Input.GetKey(KeyCode.S) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(0, -1)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, -1))) <= maxplayerDistance) { //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0)))); //Debug.Log("MAX IS: "+ maxplayerDistance); CursorMove("Down"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } } if (Input.GetKeyDown(KeyCode.Alpha1) && !cursorCoords.Equals(playerCoords)) { //Debug.Log("Moving here!"); movePlayer(); goBack(); } if (Input.GetKey(KeyCode.Q)) { goBack(); } if (Input.GetKey(KeyCode.Space)) { SetStateStandBy(); combatControllerScript.EndTurn(); } break; case GameState.PlayerAttack: temporal = cursorCoords; if (!Cooldown) { //Debug.Log("PlayerAttack"); //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(-1,0)))); //Debug.Log(playerCoords.x + " " + playerCoords.y); //Debug.Log(temporal.x + " " + temporal.y); //Debug.Log(cursorCoords.x + " " + cursorCoords.y); if (Input.GetKey(KeyCode.A) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(-1, 0))) <= maxAttackRange) { //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(-1,0)))); CursorMove("Left"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } else if (Input.GetKey(KeyCode.W) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, 1))) <= maxAttackRange) { //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(0,1)))); CursorMove("Up"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } else if (Input.GetKey(KeyCode.D) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(1, 0))) <= maxAttackRange) { //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(1,0)))); CursorMove("Right"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } else if (Input.GetKey(KeyCode.S) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, -1))) <= maxAttackRange) { //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(0,-1)))); CursorMove("Down"); Invoke("ResetCoodldown", 0.10f); Cooldown = true; } } if (Input.GetKeyDown(KeyCode.Alpha2) && cursorCoords.Equals(enemyCoords)) { Debug.Log("Attack: 1d20 + bab + strengthMod"); playerScript.MeleeAttack(enemyScript); goBack(); } if (Input.GetKey(KeyCode.Q)) { goBack(); } if (Input.GetKey(KeyCode.Space)) { SetStateStandBy(); combatControllerScript.EndTurn(); } break; } }