private void SetTile() { if (nextControlAccumalator >= framesPerControlTile && numberOfControlTilesSet < maxNumberOfControlTiles) { if (initialCameraPosition == null) { initialCameraPosition = GetCameraPosition(); } // Store tiles for event cycle EventControlTile eventControlTile = null; if (isControlTile == null || isControlTile.GetValueOrDefault()) { eventControlTile = GenerateEventControlTile(GetNextTilePosition() + nextControlOffSetAsVector); isControlTile = false; numberOfControlTilesSet++; } else { eventControlTile = GenerateEventControlPlusTile(GetNextPlusTilePosition() + nextControlOffSetAsVector); isControlTile = true; } eventControlTilesInCycle.Add(eventControlTile); tilemap.SetTile(eventControlTile.position, eventControlTile.tile); nextControlAccumalator = 0; } else if (numberOfControlTilesSet == maxNumberOfControlTiles) { initialCameraPosition = null; isControlTile = null; eventDrawn = true; } else { nextControlAccumalator++; } }
private void PerformControlEvent() { nextControlAccumalator = 0; if (currentEventControl == null) { currentEventControl = eventControlTilesInCycle.First(x => !x.isPlusTile && !x.isPerformed); } else { if (buttonPressAnimationAccumalator >= framesPerControlTile) { tilemap.SetTile(currentEventControl.position, currentEventControl.isPressed ? currentEventControl.pressedTile : currentEventControl.tile); currentEventControl.isPressed = !currentEventControl.isPressed; buttonPressAnimationAccumalator = 0; } else { buttonPressAnimationAccumalator++; } } if (Input.GetKeyDown(currentEventControl.keyCode)) { currentEventControl.isPerformed = true; tilemap.SetTile(currentEventControl.position, currentEventControl.successTile); currentEventControl = null; if (eventControlTilesInCycle.Where(x => !x.isPlusTile && !x.isPerformed).Count() == 0) { numberOfEventsCount++; eventTriggered = false; eventCycleAccumalator = 0; if (maxNumberOfEvents == numberOfEventsCount) { player.EndEncounter(); isInBattle = false; // Destroy(currentEnemyCollider.gameObject); // currentEnemyCollider = null; hasFailed = false; StartCoroutine(PlayVictoryMusic()); } } return; } else if (eventCycleAccumalator >= eventCycleInSeconds * framesPerSecond * player.GetStaminaDifficultyFactor()) { eventTriggered = false; isInBattle = false; eventCycleAccumalator = 0; currentEventControl = null; numberOfEventsCount = 0; hasFailed = true; player.ThrowUserInTheAirHurt(); SoundManagerScript.PlaySound("bug laugh"); currentEnemyCollider.gameObject.GetComponent <SpriteRenderer>().enabled = true; currentEnemyCollider.gameObject.GetComponent <BugMovement>().EnableMovement(); player.EndEncounter(); return; } else if (FailedToClickCorrect(currentEventControl.keyCode)) { SoundManagerScript.PlaySound("wrong"); tilemap.SetTile(currentEventControl.position, currentEventControl.failTile); eventTriggered = false; isInBattle = false; eventCycleAccumalator = 0; currentEventControl = null; numberOfEventsCount = 0; hasFailed = true; player.ThrowUserInTheAirHurt(); currentEnemyCollider.gameObject.GetComponent <SpriteRenderer>().enabled = true; currentEnemyCollider.gameObject.GetComponent <BugMovement>().EnableMovement(); player.EndEncounter(); SoundManagerScript.PlaySound("bug laugh"); return; } eventCycleAccumalator++; }