public SquareGrid(int[,] level, float squareSize) { int nodeCountX = level.GetLength(0); int nodeCountZ = level.GetLength(1); float levelWidth = nodeCountX * squareSize; float levelHeight = nodeCountZ * squareSize; NodeController[,] nodeController = new NodeController[nodeCountX, nodeCountZ]; for (int x = 0; x < nodeCountX; x++) { for (int z = 0; z < nodeCountZ; z++) { Vector3 position = new Vector3(-levelWidth / 2 + x * squareSize + squareSize / 2, 0, -levelHeight / 2 + z * squareSize + squareSize / 2); nodeController[x, z] = new NodeController(position, level[x, z] == 1, squareSize); } } squares = new SquareSetup[nodeCountX - 1, nodeCountZ - 1]; for (int x = 0; x < nodeCountX - 1; x++) { for (int z = 0; z < nodeCountZ - 1; z++) { squares[x, z] = new SquareSetup(nodeController[x, z + 1], nodeController[x + 1, z + 1], nodeController[x + 1, z], nodeController[x, z]); } } }
public void setSquare(int oldSquareId, int newSquareID) { //float step = speed * Time.deltaTime; oldSquare = squareList [(oldSquareId) - 1]; newSquare = squareList [(newSquareID) - 1]; rsm = GetComponentInParent <rSmoothMove> (); //rsm.setSpeed (3.0F); SquareSetup oldSquareSettings = newSquare.GetComponent <SquareSetup>(); SquareSetup newSquareSettings = newSquare.GetComponent <SquareSetup>(); //transform.position = squareSettings.getCoords (); rBase = oldSquareSettings.getCoords(); if (inplay == true) { rsm.setSpeed(3.0F); rsm.destination = Vector3.MoveTowards(oldSquareSettings.getCoords(), newSquareSettings.getCoords(), (float)0.0001); /* SquareSetup rocketSquare = squareList[oldSquareId].GetComponent<SquareSetup>(); * SquareSetup preRocketSquare = squareList[currentSquare].GetComponent<SquareSetup>(); * preRocketSquare.takeRocket (); * Transform x = preRocketSquare.getRocket (); * rocketSquare.giveRocket (x);*/ } else { transform.position = Vector3.MoveTowards(oldSquareSettings.getCoords(), newSquareSettings.getCoords(), (float)0.0001); inplay = true; } currentSquare = newSquareID; }
public void setSquare(int oldSquareId, int newSquareID) { //float step = speed * Time.deltaTime; oldSquare = squareList [(oldSquareId) - 1]; newSquare = squareList [(newSquareID) - 1]; SquareSetup oldSquareSettings = newSquare.GetComponent <SquareSetup>(); SquareSetup newSquareSettings = newSquare.GetComponent <SquareSetup>(); SmoothMove sm = GetComponentInParent <SmoothMove>(); sm.setSpeed(3.0F); foreach (Transform square in squareList) { SquareSetup sq = square.GetComponent <SquareSetup>(); if (sq.isRocket()) { sq.takeRocket(); int c = sq.getRocket().GetComponent <rocketController>().move(); squareList[c - 1].GetComponent <SquareSetup>().giveRocket(sq.getRocket()); } } if (newSquareSettings.isRocket()) { Transform rocket = newSquareSettings.getRocket(); rocketController rc = rocket.GetComponent <rocketController>(); Transform tc = squareList [(rc.getTargetSquare()) - 1]; SquareSetup tcSquareSettings = tc.GetComponent <SquareSetup> (); sm.setVector(tcSquareSettings.getCoords()); rc.fireIt(tcSquareSettings.getCoords()); //transform.position = Vector3.position (oldSquareSettings.getCoords (), tcSquareSettings.getCoords (), (float)0.0001); //transform.position = tcSquareSettings.getCoords (); currentSquare = tcSquareSettings.getsquareID(); Renderer r = rocket.GetComponent <Renderer> (); //r.enabled = false; } else { sm.setVector(newSquareSettings.getCoords()); //transform.position = newSquareSettings.getCoords (); //transform.position = Vector3.MoveTowards (oldSquareSettings.getCoords (), newSquareSettings.getCoords (), (float)0.0001); currentSquare = newSquareID; } }
public SquareGrid(int[,] level, float squareSize){ int nodeCountX = level.GetLength(0); int nodeCountZ = level.GetLength(1); float levelWidth = nodeCountX * squareSize; float levelHeight = nodeCountZ * squareSize; NodeController[,] nodeController = new NodeController[nodeCountX, nodeCountZ]; for(int x = 0; x < nodeCountX; x++){ for (int z = 0; z < nodeCountZ; z++){ Vector3 position = new Vector3(-levelWidth/2 + x * squareSize + squareSize/2, 0, -levelHeight/2 + z * squareSize + squareSize/2); nodeController[x, z] = new NodeController(position, level[x, z] == 1, squareSize); } } squares = new SquareSetup[nodeCountX - 1, nodeCountZ -1]; for(int x = 0; x < nodeCountX - 1; x++){ for (int z = 0; z < nodeCountZ - 1; z++){ squares[x, z] = new SquareSetup(nodeController[x, z + 1], nodeController[x + 1, z + 1], nodeController[x + 1, z], nodeController[x, z]); } } }
// The system to do that is based on the 16 different possibilities of combinations // that a square (4 corners) and 4 node between the corners can have void BreakingSquareInTriangules(SquareSetup _square){ // switch (_square.config) { case 0: break; // in this case there is no mesh // 1 pseudo-node case 1: CreateMeshFromNodes (_square.west, _square.south, _square.southwestCorner); break; case 2: CreateMeshFromNodes (_square.southeastCorner, _square.south, _square.east); break; case 4: CreateMeshFromNodes (_square.northeastCorner, _square.east, _square.north); break; case 8: CreateMeshFromNodes (_square.northwestCorner, _square.north, _square.west); break; // 2 pseudo=nodes case 3: CreateMeshFromNodes (_square.east, _square.southeastCorner, _square.southwestCorner, _square.west); break; case 6: CreateMeshFromNodes (_square.north, _square.northeastCorner, _square.southeastCorner, _square.south); break; case 9: CreateMeshFromNodes (_square.northwestCorner, _square.north, _square.south, _square.southwestCorner); break; case 12: CreateMeshFromNodes (_square.northwestCorner, _square.northeastCorner, _square.east, _square.west); break; case 5: // diagonal CreateMeshFromNodes (_square.north, _square.northeastCorner, _square.east, _square.south, _square.southwestCorner, _square.west); break; case 10: // diagonal CreateMeshFromNodes (_square.northwestCorner, _square.north, _square.east, _square.southeastCorner, _square.south, _square.west); break; // 3 pseudo=node case 7: CreateMeshFromNodes (_square.north, _square.northeastCorner, _square.southeastCorner, _square.southwestCorner, _square.west); break; case 11: CreateMeshFromNodes (_square.northwestCorner, _square.north, _square.east, _square.southeastCorner, _square.southwestCorner); break; case 13: CreateMeshFromNodes (_square.northwestCorner, _square.northeastCorner, _square.east, _square.south, _square.southwestCorner); break; case 14: CreateMeshFromNodes (_square.northwestCorner, _square.northeastCorner, _square.southeastCorner, _square.south, _square.west); break; // 4 pseudo-nodes case 15: CreateMeshFromNodes (_square.northwestCorner, _square.northeastCorner, _square.southeastCorner, _square.southwestCorner); verticesAlreadyChecked.Add (_square.northwestCorner.vertexIndex); verticesAlreadyChecked.Add (_square.northeastCorner.vertexIndex); verticesAlreadyChecked.Add (_square.southeastCorner.vertexIndex); verticesAlreadyChecked.Add (_square.southwestCorner.vertexIndex); break; } }
void starterLevel() { int squareCount = 1; bool reverse = false; for (int y = 0; y < 8; y++) { if (reverse) { for (int x = 7; x >= 0; x--) { TextMesh[] text; Transform squareCell; List <int> dangerValues = new List <int>(new int[] { 14, 15, 16, 17, 18, 19, 25, 26, 27, 38, 39, 40, 41, 46, 47, 45, 61, 62, 63 }); if (dangerValues.Contains(squareCount)) { squareCell = Instantiate(dangerCell, new Vector3(x * 20, -40, y * 20), Quaternion.Euler(90, 0, 0)); } else { squareCell = Instantiate(cell, new Vector3(x * 20, -40, y * 20), Quaternion.Euler(90, 0, 0)); } SquareSetup squareSettings = squareCell.GetComponent <SquareSetup>(); squareSettings.setCoords(new Vector3(x * 20, -40, y * 20)); squareSettings.setsquareID(squareCount); //squareCell.transform.rotation = Vector3(90,0,0); text = squareCell.GetComponentsInChildren <TextMesh>(); if (squareCount == 64) { text[0].text = "END"; squareCell.GetComponent <SpriteRenderer> ().color = Color.green; } else { text[0].text = (squareCount - 1).ToString(); } squareCount++; squareList.Add(squareCell); } reverse = false; } else { for (int x = 0; x < 8; x++) { TextMesh[] text; Transform squareCell; List <int> dangerValues = new List <int>(new int[] { 14, 15, 16, 17, 18, 19, 25, 26, 27, 38, 39, 36, 40, 41, 46, 47, 45, 61, 62, 63 }); if (dangerValues.Contains(squareCount)) { squareCell = Instantiate(dangerCell, new Vector3(x * 20, -40, y * 20), Quaternion.Euler(90, 0, 0)); } else { squareCell = Instantiate(cell, new Vector3(x * 20, -40, y * 20), Quaternion.Euler(90, 0, 0)); } SquareSetup squareSettings = squareCell.GetComponent <SquareSetup>(); squareSettings.setCoords(new Vector3(x * 20, -40, y * 20)); squareSettings.setsquareID(squareCount); //squareCell.transform.rotation = Vector3(90,0,0); text = squareCell.GetComponentsInChildren <TextMesh>(); if (squareCount == 1) { squareCell.GetComponent <SpriteRenderer> ().color = Color.green; text[0].text = "START"; } else { text[0].text = (squareCount - 1).ToString(); } squareCount++; squareList.Add(squareCell); } reverse = true; } } mainGuy1 = Instantiate(mainChar, new Vector3(0, -40, 0), Quaternion.Euler(90, 0, 0)); mainGuy2 = Instantiate(mainChar2, new Vector3(0, -40, 0), Quaternion.Euler(90, 0, 0)); CameraFollow.player = mainGuy1; TempControllerTester controlScript = mainGuy1.GetComponent <TempControllerTester>(); controlScript.setNum(2); TempControllerTester controlScript2 = mainGuy2.GetComponent <TempControllerTester>(); controlScript2.setNum(1); controlScript2.setSwitch(); //controlScript.enabled = true; controlScript.setSquare(1, 1); //controlScript.enabled = false; //controlScript2.enabled = true; controlScript2.setSquare(1, 1); //controlScript2.enabled = false; controlScript.setIsActive(true); controlScript2.setIsActive(false); rocket1 = Instantiate(rocket, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController rocketScript = rocket1.GetComponent <rocketController>(); rocketScript.setSquare(7, 7); SquareSetup rocketSquare = squareList[7 - 1].GetComponent <SquareSetup>(); squareList[7 - 1].GetComponent <SpriteRenderer>().color = Color.blue; rocketSquare.giveRocket(rocket1); List <int> targValues = new List <int>(new int[] { 12 }); rocketScript.setTargetSquare(targValues); List <int> areaValues = new List <int>(new int[] { 7 }); rocketScript.setArea(areaValues); rocketScript.setDist(3.8F); rocket2 = Instantiate(rocket, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController rocketScript2 = rocket2.GetComponent <rocketController>(); rocketScript2.setSquare(31, 31); SquareSetup rocketSquare2 = squareList[31 - 1].GetComponent <SquareSetup>(); squareList[31 - 1].GetComponent <SpriteRenderer>().color = Color.blue; rocketSquare2.giveRocket(rocket2); targValues = new List <int>(new int[] { 41 }); rocketScript2.setTargetSquare(targValues); areaValues = new List <int>(new int[] { 31 }); rocketScript2.setArea(areaValues); rocketScript2.setDist(10F); rocket3 = Instantiate(rocket, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController rocketScript3 = rocket3.GetComponent <rocketController>(); rocketScript3.setSquare(53, 53); SquareSetup rocketSquare3 = squareList[53 - 1].GetComponent <SquareSetup>(); squareList[53 - 1].GetComponent <SpriteRenderer>().color = Color.blue; rocketSquare3.giveRocket(rocket3); targValues = new List <int>(new int[] { 60 }); rocketScript3.setTargetSquare(targValues); areaValues = new List <int>(new int[] { 53 }); rocketScript3.setArea(areaValues); rocketScript3.setDist(3.5F); ufo1 = Instantiate(ufo, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController ufoScript = ufo1.GetComponent <rocketController>(); ufoScript.setSquare(18, 18); SquareSetup ufoSquare = squareList[18 - 1].GetComponent <SquareSetup>(); ufoSquare.giveRocket(ufo1); targValues = new List <int>(new int[] { 2 }); ufoScript.setTargetSquare(targValues); areaValues = new List <int>(new int[] { 14, 15, 16, 17, 18, 19 }); ufoScript.setArea(areaValues); ufoScript.setDist(3.5F); ufo2 = Instantiate(ufo, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController ufoScript2 = ufo2.GetComponent <rocketController>(); ufoScript2.setSquare(39, 39); SquareSetup ufoSquare2 = squareList[39 - 1].GetComponent <SquareSetup>(); ufoSquare2.giveRocket(ufo2); targValues = new List <int>(new int[] { 11 }); ufoScript2.setTargetSquare(targValues); areaValues = new List <int>(new int[] { 25, 26, 27, 38, 39, 40, 41 }); ufoScript2.setArea(areaValues); ufoScript2.setDist(3.5F); ufo3 = Instantiate(ufo, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController ufoScript3 = ufo3.GetComponent <rocketController>(); ufoScript3.setSquare(63, 63); SquareSetup ufoSquare3 = squareList[63 - 1].GetComponent <SquareSetup>(); ufoSquare3.giveRocket(ufo3); targValues = new List <int>(new int[] { 11 }); ufoScript3.setTargetSquare(targValues); areaValues = new List <int>(new int[] { 61, 62, 63 }); ufoScript3.setArea(areaValues); ufoScript3.setDist(11F); ufo4 = Instantiate(ufo, new Vector3(0, -40, 0), Quaternion.Euler(90, -20, 0)); rocketController ufoScript4 = ufo4.GetComponent <rocketController>(); ufoScript4.setSquare(47, 47); SquareSetup ufoSquare4 = squareList[47 - 1].GetComponent <SquareSetup>(); ufoSquare4.giveRocket(ufo4); targValues = new List <int>(new int[] { 29 }); ufoScript4.setTargetSquare(targValues); areaValues = new List <int>(new int[] { 47, 46, 45, 36 }); ufoScript4.setArea(areaValues); ufoScript4.setDist(11F); }
// The system to do that is based on the 16 different possibilities of combinations // that a square (4 corners) and 4 node between the corners can have void BreakingSquareInTriangules(SquareSetup _square) { // switch (_square.config) { case 0: break; // in this case there is no mesh // 1 pseudo-node case 1: CreateMeshFromNodes(_square.west, _square.south, _square.southwestCorner); break; case 2: CreateMeshFromNodes(_square.southeastCorner, _square.south, _square.east); break; case 4: CreateMeshFromNodes(_square.northeastCorner, _square.east, _square.north); break; case 8: CreateMeshFromNodes(_square.northwestCorner, _square.north, _square.west); break; // 2 pseudo=nodes case 3: CreateMeshFromNodes(_square.east, _square.southeastCorner, _square.southwestCorner, _square.west); break; case 6: CreateMeshFromNodes(_square.north, _square.northeastCorner, _square.southeastCorner, _square.south); break; case 9: CreateMeshFromNodes(_square.northwestCorner, _square.north, _square.south, _square.southwestCorner); break; case 12: CreateMeshFromNodes(_square.northwestCorner, _square.northeastCorner, _square.east, _square.west); break; case 5: // diagonal CreateMeshFromNodes(_square.north, _square.northeastCorner, _square.east, _square.south, _square.southwestCorner, _square.west); break; case 10: // diagonal CreateMeshFromNodes(_square.northwestCorner, _square.north, _square.east, _square.southeastCorner, _square.south, _square.west); break; // 3 pseudo=node case 7: CreateMeshFromNodes(_square.north, _square.northeastCorner, _square.southeastCorner, _square.southwestCorner, _square.west); break; case 11: CreateMeshFromNodes(_square.northwestCorner, _square.north, _square.east, _square.southeastCorner, _square.southwestCorner); break; case 13: CreateMeshFromNodes(_square.northwestCorner, _square.northeastCorner, _square.east, _square.south, _square.southwestCorner); break; case 14: CreateMeshFromNodes(_square.northwestCorner, _square.northeastCorner, _square.southeastCorner, _square.south, _square.west); break; // 4 pseudo-nodes case 15: CreateMeshFromNodes(_square.northwestCorner, _square.northeastCorner, _square.southeastCorner, _square.southwestCorner); verticesAlreadyChecked.Add(_square.northwestCorner.vertexIndex); verticesAlreadyChecked.Add(_square.northeastCorner.vertexIndex); verticesAlreadyChecked.Add(_square.southeastCorner.vertexIndex); verticesAlreadyChecked.Add(_square.southwestCorner.vertexIndex); break; } }