//Searches for the latest available index otherwise replace a random one int AvailableIndex() { for (int i = 0; i < activeBlocks.Length; i++) { if (activeBlocks[i] == -1) { return(i); } } //Looks for available slot to activate a block while avoiding blocks that are leaking for (int i = 0; i < activeBlocks.Length; i++) { // Debug.Log("Index " +i+ " " +activeBlocks[i]); BS = blocks[activeBlocks[i]].GetComponent <brickState>(); Debug.Log(BS.isLeaking); if (BS.isBroken) { Debug.Log("Index " + i + " is Broken and has been replaced"); return(i); } if (!BS.isLeaking) { Debug.Log("Index " + i + " is not Leaking or Broken and has been replaced"); return(i); } } return(-1); //All are leaking don't replace }
void OnTriggerStay(Collider other) { BS = other.gameObject.GetComponent <brickState>(); if (Input.GetKeyDown(KeyCode.Space) && BS.isLeaking) { BS.repairBlock(); RS.PlayAudio(); } }
// Update is called once per frame void Update() { if (currentState == brickState.stop) { hasMove = false; } if (currentState == brickState.move && hasMove == false) { transform.position = new Vector2(transform.position.x, transform.position.y - 1); currentState = brickState.stop; hasMove = true; } }
private void OnEnable() { hasMoved = false; currentState = brickState.stop; }
void Start() { hasMoved = false; currentState = brickState.stop; }
//Randomly activates blocks based on various conditions. //A lil gross to look at :c void ToggleBrick(float dt) { if ((int)dt == speed) { for (int i = 0; i < transform.childCount; i++) { //Don't attempt to activate broken blocks (redundant + wastes a turn) if (CheckIfBroken(i)) { //Debug.Log("Skip Broken"); continue; } //Random Chance to set block to active if (Random.Range(0, upperRange) == 0 && !BlockLimitReached() || Failures == maxFailures) { if (BlockAlreadyActive(i)) { break; } blocks[i].SendMessage("toggleBrick", i); activeBlocks[AvailableIndex()] = i; Failures = 0; break; } else if (Random.Range(0, upperRange) == 0 && BlockLimitReached() && !ignoreBlockLimit || Failures == maxFailures) { //start deactivating blocks but stay withing the block limit if (BlockAlreadyActive(i)) { break; } Debug.Log("Limit has been Reached. Swapping blocks."); int available = AvailableIndex(); //Grab available index if (available != -1) { blocks[i].SendMessage("toggleBrick", i); //Activate new block blocks[activeBlocks[available]].SendMessage("toggleBrick", activeBlocks[available]); //Disable old block Debug.Log("We got a new Block Activated "); activeBlocks[available] = i; //Store Newly Enabled Block } Failures = 0; break; } else if (ignoreBlockLimit) //Just go ham and activate everything for chaos { BS = blocks[i].GetComponent <brickState>(); if (!BS.isEnabled) { blocks[i].SendMessage("toggleBrick", i); } } else { Failures++; } } limitTimer += (int)dt; //Debug.Log("Limit: " + limitTimer); timer = 0; } if (limitTimer >= timeLimit && !ignoreBlockLimit) { ignoreBlockLimit = true; Debug.Log("BLOCK LIMIT HAS BEEN DISABLED WEE WOO WEE WOO"); } }
//Returns true is a child block is broken bool CheckIfBroken(int index) { BS = blocks[index].GetComponent <brickState>(); return(BS.isBroken); }