// Use this for initialization void Start() { textValue = gameObject.GetComponent <TextMesh>(); value = initialValue; textValue.text = value.ToString(); gameObject.GetComponent <MeshRenderer>().sortingOrder = 3; if (gridPositioner != null) { gridPositioner.mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); gridPositioner.AdjustToCamera(); gridPositioner.gameObject.transform.Rotate(new Vector3(90.0f, 0.0f, 0.0f)); } }
// Update is called once per frame void Update() { //TODO: Note buildIndex references if (SceneManager.GetActiveScene().buildIndex == 2) { SendEverythingDown(); RotateCharacterPosition(possibleMoveableChars, possibleMoveableChars.Length, 2); RotateCharacterPositionWithList(spawnedEnemies, spawnedEnemies.Count, 1); Piece[] cannonPieces = new Piece[allCannons.Length]; for (int i = 0; i < cannonPieces.Length; i++) { cannonPieces[i] = allCannons[i].cannon; } RotateCharacterPosition(cannonPieces, cannonPieces.Length, 2); Piece[] generatorPieces = new Piece[generators.Length]; for (int i = 0; i < generatorPieces.Length; i++) { generatorPieces[i] = generators[i].generator; } RotateCharacterPosition(generatorPieces, generatorPieces.Length, 2); if (pirateBoss) { GridPositioner childPositionerBoss = pirateBoss.thePiece.transform.GetChild(0).GetComponent <GridPositioner>(); childPositionerBoss.mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); childPositionerBoss.AdjustToCamera(); } timer += Time.deltaTime; coinResetTimer += Time.deltaTime; } else if (SceneManager.GetActiveScene().buildIndex == 3) { SendEverythingDown(); RotateCharacterPosition(possibleMoveableChars, possibleMoveableChars.Length, 2); RotateCharacterPositionWithList(spawnedEnemies, spawnedEnemies.Count, 1); timer += Time.deltaTime; coinResetTimer += Time.deltaTime; } }
private void RotateCharacterPositionWithList(List <Piece> piecesToRotate, int numOfThesePieces, int numChildGridPositioners) { for (int i = 0; i < numOfThesePieces; i++) { GridPositioner[] tempGridPositioners = new GridPositioner[numChildGridPositioners]; for (int k = 0; k < numChildGridPositioners; k++) { GridPositioner childPositioner = piecesToRotate[i].thePiece.GetComponent <GridPositioner>(); //look for the image to rotate for (int j = 0; j < piecesToRotate[i].thePiece.transform.childCount; j++) { if (piecesToRotate[i].thePiece.transform.GetChild(j).GetComponent <GridPositioner>() != null) { if (k == 0) { childPositioner = piecesToRotate[i].thePiece.transform.GetChild(j).GetComponent <GridPositioner>(); } else { for (int g = k - 1; g >= 0; g--) { if (piecesToRotate[i].thePiece.transform.GetChild(j).GetComponent <GridPositioner>() != tempGridPositioners[g]) { childPositioner = piecesToRotate[i].thePiece.transform.GetChild(j).GetComponent <GridPositioner>(); } } } } } if (childPositioner != piecesToRotate[i].thePiece.GetComponent <GridPositioner>() && childPositioner != null) { childPositioner.mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); childPositioner.AdjustToCamera(); tempGridPositioners[k] = childPositioner; } } } }
/* * private void CoinSpawn(int numCoins, int tileWidth, int tileHeight, float midX, float midY) * { * //if the time elapsed is enough to create a coin, make a coin * if (coinResetTimer >= timeToWait) * { * //find a location for the coin * //check for the spots where the coin may not be placed * int[] disallowedRows = new int[possibleMoveableChars.Length + currentNumCoins + numDeadSpaces + spawnedEnemies.Length]; * int[] disallowedCols = new int[possibleMoveableChars.Length + currentNumCoins + numDeadSpaces + spawnedEnemies.Length]; * for (int i = 0; i < possibleMoveableChars.Length + currentNumCoins + numDeadSpaces + spawnedEnemies.Length; i++) * { * //do not get the same space as a hero * if (i < possibleMoveableChars.Length) * { * disallowedRows[i] = possibleMoveableChars[i].rowPosition; * disallowedCols[i] = possibleMoveableChars[i].colPosition; * } * //do not get the same space as another enemy * else if (i >= possibleMoveableChars.Length && i < possibleMoveableChars.Length + spawnedEnemies.Length) * { * disallowedRows[i] = allCoins[i - possibleMoveableChars.Length].rowPosition; * disallowedCols[i] = allCoins[i - possibleMoveableChars.Length].colPosition; * } * //do not get the same space a coin * else if (i >= possibleMoveableChars.Length + spawnedEnemies.Length && i < possibleMoveableChars.Length + spawnedEnemies.Length + currentNumCoins) * { * disallowedRows[i] = allCoins[i - possibleMoveableChars.Length - spawnedEnemies.Length].rowPosition; * disallowedCols[i] = allCoins[i - possibleMoveableChars.Length - spawnedEnemies.Length].colPosition; * } * //do not get a dead space * else * { * disallowedRows[i] = deadPoints[i - possibleMoveableChars.Length - currentNumCoins - spawnedEnemies.Length].y; * disallowedCols[i] = deadPoints[i - possibleMoveableChars.Length - currentNumCoins - spawnedEnemies.Length].x; * } * } * //by default, cannot place a coin until you find a space that is allowed * bool canPlace = false; * int debugCount = 0; * int row = 0; * int col = 0; * while (!canPlace) * { * //select an arbitrary row and column to place the coin * row = (int)Mathf.Floor(Random.value * universalTileHeight); * col = (int)Mathf.Floor(Random.value * universalTileWidth); * canPlace = CheckIfCanPlace(row, col, disallowedRows, disallowedCols); * //just in case every space is invalid, throw it at (0, 0) after 100 checks * debugCount++; * if (debugCount >= 100) * { * canPlace = true; * } * } * * //place the coin * //PlaceObject(tileWidth, tileHeight, row, col, pieceDistance, midX, midY, allCoins[currentNumCoins], currentNumCoins, true); * float halfWidth = (float)tileWidth / 2.0f; * float halfHeight = (float)tileHeight / 2.0f; * float finalXPos = -halfWidth + (float)col * pieceDistance + midX; * float finalYPos = halfHeight - (float)row * pieceDistance - midY; * Vector3 placement = new Vector3(finalXPos, finalYPos, 0.0f); * GameObject piece = Instantiate(allCoins[currentNumCoins].GetPiece(), placement, Quaternion.identity); * allCoins[currentNumCoins].SetName("Coin " + currentNumCoins); * piece.name = allCoins[currentNumCoins].GetName(); * allCoins[currentNumCoins].thePiece = piece; * allCoins[currentNumCoins].SetRowAndCol(row, col); * GridPositioner bringDown = piece.GetComponent<GridPositioner>(); * bringDown.mainCamera = mainCamera; * bringDown.CheckWhatsBeneath(); * * //every situation where currentNumCoins increases or decreases, adjust the timeToWait * currentNumCoins++; * timeToWait *= approxGoldenRatio; * coinResetTimer = 0.0f; * } * } */ private void SendEverythingDown() { bool sendingDown = false; for (int i = 0; i < allTiles.Length; i++) { GridPositioner sendDown = allTiles[i].GetComponent <GridPositioner>(); sendingDown = sendDown.GuideToObjectBeneath(0.1f); } for (int i = 0; i < possibleMoveableChars.Length; i++) { if (possibleMoveableChars[i].thePiece) { GridPositioner sendDown = possibleMoveableChars[i].thePiece.transform.GetComponent <GridPositioner>(); sendingDown = sendDown.GuideToObjectBeneath(0.1f); } } for (int i = 0; i < allCoins.Length; i++) { GridPositioner sendDown = allCoins[i].thePiece.GetComponent <GridPositioner>(); sendingDown = sendDown.GuideToObjectBeneath(0.1f); sendDown.AdjustToCamera(); } if (numCannons > 0) { for (int i = 0; i < allCannons.Length; i++) { GridPositioner sendDown = allCannons[i].gameObject.GetComponent <GridPositioner>(); sendingDown = sendDown.GuideToObjectBeneath(0.1f); //sendDown.AdjustToCamera(); } } if (numGenerators > 0) { for (int i = 0; i < generators.Length; i++) { GridPositioner sendDown = generators[i].gameObject.GetComponent <GridPositioner>(); sendingDown = sendDown.GuideToObjectBeneath(0.1f); //sendDown.AdjustToCamera(); } } if (pirateBoss) { sendingDown = pirateBoss.thePiece.GetComponent <GridPositioner>().GuideToObjectBeneath(0.1f); isPirateBossSpawned = true; } else if (isPirateBossSpawned) { GameObject.Find("WinScreen").GetComponentInChildren <YouWin>().youWon = true; } if (spawnedEnemies.Count > 0) { for (int i = 0; i < spawnedEnemies.Count; i++) { if (spawnedEnemies[i] == null) { spawnedEnemies.RemoveAt(i); if (i >= spawnedEnemies.Count) { break; } } GridPositioner sendDown = spawnedEnemies[i].thePiece.GetComponent <GridPositioner>(); sendingDown = sendDown.GuideToObjectBeneath(0.1f); } } if (!sendingDown) { PlaceStartingEnemies(); } }