void StartChopping() { float dist1 = Vector3.Distance(cursor.position, beatMarkers[0].transform.position); float dist2 = Vector3.Distance(cursor.position, beatMarkers[1].transform.position); currentMarker = dist1 < dist2 ? beatMarkers[0] : beatMarkers[1]; int j = beatMarkers.IndexOf(currentMarker); beatMarkers.Remove(currentMarker); timeTracker.Remove(timeTracker[j]); movingVeggie = true; if (chopMaster.chosenIngredient == null) { chopMaster.chosenIngredient = currentMarker.gameObject; chopMaster.Activate(); } else { chopMaster.Reset(); chopMaster.chosenIngredient = currentMarker.gameObject; chopMaster.Activate(); } }
// Update is called once per frame void Update() { if (gameStarted) { timer += Time.deltaTime; delay += Time.deltaTime; volumeTemp += timer / (totalTime * totalTime * totalTime); scoreTxt.text = "Score: " + ((completedRecipes + 1) * (totalIngredientsChopped - wrongIngredientsChopped * 2) * 1000 - ((hand.transform.childCount - hand.GetFingerCount()) * completedRecipes * totalIngredientsChopped)); } else { scoreTxt.text = ""; review.transform.GetChild(1).gameObject.SetActive(false); review.transform.localScale = new Vector3(1.5f, 1.5f, 20.7f); if (Input.anyKeyDown) { audioManager.GetComponent <AudioManager>().potboilingEvent.setVolume(volumeTemp); audioManager.GetComponent <AudioManager>().ambientEvent.start(); audioManager.GetComponent <AudioManager>().potboilingEvent.start(); audioManager.GetComponent <AudioManager>().PlayBackgroundMusic(); review.transform.GetChild(1).gameObject.SetActive(true); review.transform.GetChild(0).gameObject.SetActive(false); review.transform.localScale = new Vector3(0f, 1.5f, 20.7f); gameStarted = true; audioManager.GetComponent <AudioManager>().PlayMenuAdvance(); } } //No more fingers if (flagLostAllFingers && !hasFingers && !hand.isBleeding()) { scoreTxt.text = ""; lives = 0; delay = 0; flagLostAllFingers = false; hand.GoToGrabPos(); audioManager.GetComponent <AudioManager>().potboilingEvent.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); string reviewString = reviewGenerator.Generate(recipe, GetWrongIngredients(choppedIngredients), fingersLostThisRound, timer > totalTime, hasFingers); review.transform.localScale = new Vector3(1.5f, 1.5f, 20.7f); inspection.GetComponent <Text>().text = reviewString; chopMaster.Reset(); } //Other loss condition else if (flagLiveLost && total <= 0 && (numWrongIngredients != 0 || fingersLostThisRound != 0 || timer > totalTime)) { scoreTxt.text = ""; lives--; delay = 0; flagLiveLost = false; if (timer > totalTime) { timeVar1 = 8.0f; timeVar2 = 10.0f; } audioManager.GetComponent <AudioManager>().potboilingEvent.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); string reviewString = reviewGenerator.Generate(recipe, GetWrongIngredients(choppedIngredients), fingersLostThisRound, timer > totalTime, hasFingers); review.transform.localScale = new Vector3(1.5f, 1.5f, 20.7f); inspection.GetComponent <Text>().text = reviewString; chopMaster.Reset(); } //Round over else if (delay < 3.0f) { hand.GoToGrabPos(); if (!hasFingers) { if (delay % 1 < .5) { starSet.transform.localScale = new Vector3(.45f, 1f, .45f); } else { starSet.transform.localScale = new Vector3(0f, 1f, .45f); } } update_lives(lives); } //Score is displaying on game over else if (displayingScore) { delay = 4; float score = completedRecipes * (totalIngredientsChopped - wrongIngredientsChopped * 2) * 1000 - ((hand.transform.childCount - hand.GetFingerCount()) * completedRecipes * totalIngredientsChopped); if (score < 0) { score = 0; } if (totalIngredientsChopped == 0) { totalIngredientsChopped = 1; } inspection.GetComponent <Text>().text = "Completed Recipes: " + completedRecipes + "\nFingers Remaining: " + hand.GetFingerCount() + "\nTotal Ingredients Chopped: " + totalIngredientsChopped + "\nIngredient accuracy: " + (int)((1 - wrongIngredientsChopped / totalIngredientsChopped) * 100) + "%" + "\nScore: " + (int)score + "\n\nPress any key to try again!"; if (Input.anyKeyDown) { audioManager.GetComponent <AudioManager>().PlayMenuAdvance(); Start(); } } //Review Over/Game Over else if (delay >= 3.0f && delay < 15.0f) { delay = 4.0f; if (Input.anyKeyDown && lives > 0) { audioManager.GetComponent <AudioManager>().PlayMenuAdvance(); review.transform.localScale = new Vector3(0f, 1.5f, 20.7f); hand.GoToGrabPos(); delay = 15.0f; } else if (Input.anyKeyDown && lives <= 0) { displayingScore = true; audioManager.GetComponent <AudioManager>().PlayMenuAdvance(); } } //everytime player completes a recipe, a new one generates with new timer constraints; else if (total <= 0 && delay >= 15.0f && lives > 0) { if (hasFingers) { completedRecipes++; } initializeRecipe(); } if (cutSuccessfully) { totalIngredientsChopped++; total = 0; choppedIngredients.Add(vegetableCut); for (int i = 0; i < ingredients.Length; i++) { if (vegetableCut == ingredients[i].tag) { if (numIngredient[i] > 0) { numIngredient[i]--; } } total += numIngredient[i]; } cutSuccessfully = false; } if (timer > totalTime && lives > 0 && delay >= 15.0f) { total = 0; sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 1f); meter.GetComponent <SpriteRenderer>().sprite = full; bar.transform.localScale = new Vector3(0f, .7f, 1f); if (flagFire) { smoke.GetComponent <ParticleSystem>().Clear(); smoke.GetComponent <ParticleSystem>().Pause(); bubbles.GetComponent <ParticleSystem>().Clear(); bubbles.GetComponent <ParticleSystem>().Pause(); fire.GetComponent <ParticleSystem>().Clear(); fire.GetComponent <ParticleSystem>().Play(); flagFire = false; } } else if (timer / totalTime <= .5f && lives > 0 && delay >= 15.0f) { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 0f); bar.transform.localScale = new Vector3(timer * barVar / totalTime, .7f, 1f); bar.GetComponent <SpriteRenderer>().color = new Vector4(1f - (timer * 2 / totalTime), 1f, 0f, 1f); if (flagSmoke) { smoke.GetComponent <ParticleSystem>().Clear(); smoke.GetComponent <ParticleSystem>().Play(); bubbles.GetComponent <ParticleSystem>().Clear(); bubbles.GetComponent <ParticleSystem>().Pause(); fire.GetComponent <ParticleSystem>().Clear(); fire.GetComponent <ParticleSystem>().Pause(); flagSmoke = false; } } else if (timer / totalTime >= .95f && lives > 0 && delay >= 15.0f) { if (timer % .25 < .125) { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 1f); } else { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 0f); } bar.transform.localScale = new Vector3(timer * barVar / totalTime, .7f, 1f); bar.GetComponent <SpriteRenderer>().color = new Vector4(-1f + (timer * 2 / totalTime), 2f - (timer * 2 / totalTime), 0f, 1f); if (flagBubbles) { smoke.GetComponent <ParticleSystem>().Clear(); smoke.GetComponent <ParticleSystem>().Pause(); bubbles.GetComponent <ParticleSystem>().Clear(); bubbles.GetComponent <ParticleSystem>().Play(); fire.GetComponent <ParticleSystem>().Clear(); fire.GetComponent <ParticleSystem>().Pause(); flagBubbles = false; } } else if (timer / totalTime >= .85f && lives > 0 && delay >= 15.0f) { if (timer % .5 < .25) { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 1f); } else { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 0f); } bar.transform.localScale = new Vector3(timer * barVar / totalTime, .7f, 1f); bar.GetComponent <SpriteRenderer>().color = new Vector4(-1f + (timer * 2 / totalTime), 2f - (timer * 2 / totalTime), 0f, 1f); if (flagBubbles) { smoke.GetComponent <ParticleSystem>().Clear(); smoke.GetComponent <ParticleSystem>().Pause(); bubbles.GetComponent <ParticleSystem>().Clear(); bubbles.GetComponent <ParticleSystem>().Play(); fire.GetComponent <ParticleSystem>().Clear(); fire.GetComponent <ParticleSystem>().Pause(); flagBubbles = false; } } else if (timer / totalTime >= .75f && lives > 0 && delay >= 15.0f) { if (timer % 1 < .5) { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 1f); } else { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 0f); } bar.transform.localScale = new Vector3(timer * barVar / totalTime, .7f, 1f); bar.GetComponent <SpriteRenderer>().color = new Vector4(-1f + (timer * 2 / totalTime), 2f - (timer * 2 / totalTime), 0f, 1f); if (flagBubbles) { smoke.GetComponent <ParticleSystem>().Clear(); smoke.GetComponent <ParticleSystem>().Pause(); bubbles.GetComponent <ParticleSystem>().Clear(); bubbles.GetComponent <ParticleSystem>().Play(); fire.GetComponent <ParticleSystem>().Clear(); fire.GetComponent <ParticleSystem>().Pause(); flagBubbles = false; } } else if (lives > 0 && delay >= 15.0f) { sign.GetComponent <SpriteRenderer>().color = new Vector4(1f, 1f, 1f, 0f); bar.transform.localScale = new Vector3(timer * barVar / totalTime, .7f, 1f); bar.GetComponent <SpriteRenderer>().color = new Vector4(-1f + (timer * 2 / totalTime), 2f - (timer * 2 / totalTime), 0f, 1f); if (flagBubbles) { smoke.GetComponent <ParticleSystem>().Clear(); smoke.GetComponent <ParticleSystem>().Pause(); bubbles.GetComponent <ParticleSystem>().Clear(); bubbles.GetComponent <ParticleSystem>().Play(); fire.GetComponent <ParticleSystem>().Clear(); fire.GetComponent <ParticleSystem>().Pause(); flagBubbles = false; } } }