int CalculateRank(int score, string s) { Dictionary <int, List <string> > temp = gameSettings.getScores(); var ordered = temp.OrderByDescending(x => x.Value[2]).ToDictionary(x => x.Key, x => x.Value); int i = 1; int rank = 1; bool add = false; if (ordered.Count > 0) { foreach (var pair in ordered) { if (int.Parse(pair.Value[2]) < score && !add) { CalculateRankHelper(i, gameSettings.ReturnPlayerName(), s, score.ToString(), true); add = true; rank = i; i++; } CalculateRankHelper(i, pair.Value[0], pair.Value[1], pair.Value[2]); i++; } } if (!add) { CalculateRankHelper(i, gameSettings.ReturnPlayerName(), s, score.ToString(), true); rank = i; i++; } if (i < maxLeaderBoard) { for (int j = i; j < maxLeaderBoard; j++) { content.GetChild(j).gameObject.SetActive(false); } } gameSettings.AddScore(score.ToString(), s); return(rank); }
void SaveScore() { newHighScoreMessage.SetActive(newHighScore); gameSettings.AddScore(highScore); }
private void Update() { if (!End) { absorbTime = Mathf.Max(absorbTime - Time.deltaTime, 0.0f); bool hasShieldActif = false; for (int j = 0; j < shields.Count; j++) { if (shields[j].HasShield) { hasShieldActif = true; break; } } Shield.SetActive(hasShieldActif); Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, (scale + 1.0f * absorbTime), layer.value); for (int i = 0; i < colliders.Length; i++) { int dmg = 1; if (colliders[i].gameObject == this.gameObject) { continue; } Planete pl = colliders[i].gameObject.GetComponent <Planete>(); if (pl) { bool isPinky = colliders[i].gameObject.GetComponent <Pinky>() != null; if (isPinky) { GameManager.Instance.SpawnPlanete(); } pl.Dead(true); } Asteroid at = colliders[i].gameObject.GetComponent <Asteroid>(); if (at) { GameManager.Instance.AddScore(-at.maxLife); if (at.Big) { dmg++; } } Destroy(colliders[i].gameObject); if (hasShieldActif) { for (int j = 0; j < shields.Count; j++) { if (shields[j].HasShield) { shields[j].UseShield(); dmg--; if (dmg <= 0) { break; } } } } if (dmg > 0) { absorbTime += dmg; scale += dmg; if (scale >= 20) { WarningUI.SetActive(true); if (AudioCritique.isPlaying == false) { AudioCritique.Play(); } float pct = (scale - 20.0f) / 10.0f; AudioCritique.pitch = 1 + pct * 0.5f; } End = scale >= 30.0f; if (End) { timer = Time.time; AudioCritique.Stop(); } } } transform.localScale = Vector3.one * (scale + 1.0f * absorbTime); UpdateAnimation(); } else { float pct = Time.time - timer; scale = endCurve.Evaluate(pct > 1.5f ? 1.5f : pct) * 1.5f; transform.localScale = Vector3.one * scale; Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, scale, layer.value); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject == this.gameObject) { continue; } Destroy(colliders[i].gameObject); } if (pct >= 0.5f && AudioEnd.isPlaying == false && PanelEnd.Instance.IsVisible == false) { AudioEnd.Play(); } float pc = (pct - 1.5f) / 0.5f; pc = Mathf.Clamp01(pc); GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f - pc); if (pct > 2.0f) { if (PanelEnd.Instance.IsVisible == false) { GameSettings.AddScore(); PanelEnd.Instance.Show(); } } } }