/// <summary> /// Updates info about current score, based on user's proximity to the coin /// Precondition: Called from Update() /// </summary> private void UpdateScore() { //increase elapsed time for one second interval pointTimeElapsed += Time.deltaTime; //increment total possible points oneSecondPossiblePoints += 3; if (pointTimeElapsed >= 0.5f) { totalPoints += oneSecondPoints; totalPossibleLevelPoints += oneSecondPossiblePoints; totalPossiblePoints += oneSecondPossiblePoints; int cashToSpawn = (int)((float)oneSecondPoints / (float)oneSecondPossiblePoints * 3); //audioSrc.volume = ((float)oneSecondPoints) / oneSecondPossiblePoints; for (int i = 0; i < cashToSpawn; i++) { cashController.SpawnCash(); } //audioSrc.Play(); //now reset points Vector2 pigLoc = pig.transform.position; Vector2 targetLoc = target.transform.position; List <int> dirs = new List <int>(); if (pigLoc.x > targetLoc.x) { dirs.Add(WhenPigsFlySmartFeedbackProcessor.RIGHT); } else if (pigLoc.x < targetLoc.x) { dirs.Add(WhenPigsFlySmartFeedbackProcessor.LEFT); } if (pigLoc.y > targetLoc.y) { dirs.Add(WhenPigsFlySmartFeedbackProcessor.UP); } else if (pigLoc.y < targetLoc.y) { dirs.Add(WhenPigsFlySmartFeedbackProcessor.DOWN); } int misses = oneSecondPossiblePoints - oneSecondPoints; WhenPigsFlySmartFeedbackProcessor.AddCoinMisses(dirs.ToArray(), misses, oneSecondPossiblePoints); oneSecondPoints = 0; oneSecondPossiblePoints = 0; pointTimeElapsed = 0f; } }
/// <summary> /// Shows the game over screen. /// Precondition: Current stage has ended, and there are no stages left /// </summary> private void ShowGameOverScreen() { audioSrc.Play(); Time.timeScale = 0f; //WhenPigsFlySmartFeedbackProcessor.ScaleParameters(totalPossibleLevelPoints); gameOverScript.SetStars(GetNumStars()); string genCol1 = "coinPercentage"; string graphTitle1 = "Cash Collected Per Session"; IGameSessionData[] dataArray = dataList.ToArray(); StringData table = new StringData(dataArray, genCol1, mult: 1000, format: "0.00", unit: "$", altTite: "Cash Collected"); dataDisplay.AddTableView(table); dataDisplay.AddTextView(WhenPigsFlySmartFeedbackProcessor.LevelFinish()); dataDisplay.AddGraph(_GlobalVariables.dataRep.GetSessionData(TABLE_NAME, DATA_POINTS), genCol1, title: graphTitle1, difficulty: _GlobalVariables.difficulty); gameOverScript.gameObject.SetActive(true); dataDisplay.InitializeDisplays(); }
/// <summary> /// OnDestroy is only used to signal that the current game controller on the main thread is no longer being used, /// in case of a system shutdown, this will signal the arduino communication thread should shut itself down /// </summary> private void OnDestroy() { _GlobalVariables.mainThreadActive = false; WhenPigsFlySmartFeedbackProcessor.ResetVars(); }