void GameOver() { SetGameState(GameState.GAMEOVER); score = 0; onScoreUpdate.Invoke(score, highscore); onGameOver.Invoke(); }
public void StartGame(GameView gameView) { _score = 0; UpdateScoreEvent?.Invoke(0); SpawnMap(); BakeMesh(); StartWaves(); }
// Update the scores by mipping the splat texture down to a 4x4 texture and sampling the pixels. // Space the whole operation out over a few frames to keep everything running smoothly. // Only update the scores once every second. IEnumerator UpdateScores() { while (true) { yield return(new WaitForEndOfFrame()); splatBlitMaterial.SetTexture("_WorldPosTex", worldPosTex); // Shader pass 4 fills in RTWorldUnmappedRed with the splatTex + world pos tex if it is zero Graphics.Blit(splatTex, RTWorldUnmappedRed, splatBlitMaterial, 4); Graphics.Blit(RTWorldUnmappedRed, RT256, splatBlitMaterial, 3); Graphics.Blit(RT256, RT4); RenderTexture.active = RT4; Tex4.ReadPixels(new Rect(0, 0, 4, 4), 0, 0); Tex4.Apply(); yield return(new WaitForSeconds(0.01f)); Color scoresColor = new Color(0, 0, 0, 0); scoresColor += Tex4.GetPixel(0, 0); scoresColor += Tex4.GetPixel(0, 1); scoresColor += Tex4.GetPixel(0, 2); scoresColor += Tex4.GetPixel(0, 3); yield return(new WaitForSeconds(0.01f)); scoresColor += Tex4.GetPixel(1, 0); scoresColor += Tex4.GetPixel(1, 1); scoresColor += Tex4.GetPixel(1, 2); scoresColor += Tex4.GetPixel(1, 3); yield return(new WaitForSeconds(0.01f)); scoresColor += Tex4.GetPixel(2, 0); scoresColor += Tex4.GetPixel(2, 1); scoresColor += Tex4.GetPixel(2, 2); scoresColor += Tex4.GetPixel(2, 3); yield return(new WaitForSeconds(0.01f)); scoresColor += Tex4.GetPixel(3, 0); scoresColor += Tex4.GetPixel(3, 1); scoresColor += Tex4.GetPixel(3, 2); scoresColor += Tex4.GetPixel(3, 3); // Max value for each score is 16, since there are 16 pixels each with a value of 0-1 scores.x = scoresColor.r / 16.0f; scores.y = scoresColor.g / 16.0f; scores.z = scoresColor.b / 16.0f; scores.w = scoresColor.a / 16.0f; updateScore.Invoke(scores.x); yield return(new WaitForSeconds(1.0f)); } }
/// <summary> /// invokes updatescoreevent /// </summary> /// <param name="score"></param> public static void OnUpdateScoreEvent(int score) { UpdateScoreEvent?.Invoke(score); }
public void CallUpdateScoreEvent() { UpdateScoreEvent?.Invoke(); }
public void AddScore(int value) { _score += value; UpdateScoreEvent?.Invoke(_score); }