Browse Source

clearer game over screen

A
Josh 2 years ago
parent
commit
c68f687017
  1. 23
      namedropper/Assets/GameOverScreen.cs
  2. 5
      namedropper/Assets/ScoreStack.cs
  3. 36
      namedropper/Assets/Scripts/Category.cs
  4. 12
      namedropper/Assets/Scripts/Game.cs
  5. 8
      namedropper/Assets/Scripts/Player.cs

23
namedropper/Assets/GameOverScreen.cs

@ -16,11 +16,30 @@ public class GameOverScreen : MonoBehaviour
{
GameManager.Instance.HighScore = score;
}
_gameOverMessage.text = "GAME OVER\n\nYour score: " + score + "\nToday's hi-score: " + GameManager.Instance.HighScore.ToString() + "\n\nPress 'R' to Replay";
_gameOverMessage.text = "GAME OVER\n\nYour score: " + score + "\nToday's hi-score: " + GameManager.Instance.HighScore.ToString() + "\n\nPress 'R' to replay";
}
else
{
_gameOverMessage.text = "GAME OVER\n\nScores: " + GameManager.Instance.Score1 + "\n" + GameManager.Instance.Score2 + "\n" + GameManager.Instance.Score3 + "\n" + GameManager.Instance.Score4;
ScoreStack blueScoreStack = GameObject.Find("/ScoreStackBlue").GetComponent<ScoreStack>();
ScoreStack redScoreStack = GameObject.Find("/ScoreStackRed").GetComponent<ScoreStack>();
if (blueScoreStack.Score > redScoreStack.Score)
{
_gameOverMessage.color = Color.blue;
_gameOverMessage.text = "BLUE TEAM WINS!\n" + blueScoreStack.Score + " to " + redScoreStack.Score;
}
else if (redScoreStack.Score > blueScoreStack.Score)
{
_gameOverMessage.color = Color.red;
_gameOverMessage.text = "RED TEAM WINS!\n" + redScoreStack.Score + " to " + blueScoreStack.Score;
}
else
{
_gameOverMessage.color = Color.white;
_gameOverMessage.text = "TIE!\n" + redScoreStack.Score + " to " + blueScoreStack.Score;
}
_gameOverMessage.text += "\n\nPress 'R' to replay";
}
}

5
namedropper/Assets/ScoreStack.cs

@ -8,6 +8,11 @@ public class ScoreStack : MonoBehaviour
[SerializeField] Sprite _darkSprite;
int _numCheckers = 0;
// Start is called before the first frame update
public int Score
{
get { return _numCheckers; }
}
void Start()
{
//

36
namedropper/Assets/Scripts/Category.cs

@ -23,22 +23,40 @@ public class Category : MonoBehaviour
HideAllFeedback();
}
public void ShowFeedbackGood(int streak)
public int ShowFeedbackGood(int streak)
{
int streakPayout = GetStreakPayout(streak);
if (streakPayout > 0)
ShowFeedback(_feedbackGood, duration:2f);
else
ShowFeedback(_feedbackGood);
_streak.SetActive(true);
_streak.GetComponent<TMPro.TMP_Text>().text = "10";
_streak.GetComponent<TMPro.TMP_Text>().color = Color.green;
if (streak > 1)
if (streakPayout > 0)
{
_streak.GetComponent<TMPro.TMP_Text>().text += " x " + streak;
_streak.SetActive(true);
_streak.GetComponent<TMPro.TMP_Text>().text = "";
_streak.GetComponent<TMPro.TMP_Text>().color = Color.blue;
_streak.GetComponent<TMPro.TMP_Text>().text = streak + " in a row\n+" + streakPayout + " bonus";
}
return streakPayout;
}
int GetStreakPayout(int streak)
{
if (streak == 3)
return 1;
else if (streak == 5)
return 1;
else if (streak > 5 && streak % 5 == 0) //every other 5
return 3;
else
return 0;
}
public void ShowFeedbackBad(string wrongAnswer)
{
ShowFeedback(_feedbackBad);
ShowFeedback(_feedbackBad, duration: 2f);
if (SHOW_RIGHT_ANSWERS)
{
@ -48,11 +66,11 @@ public class Category : MonoBehaviour
}
}
void ShowFeedback(SpriteRenderer feedback, bool show = true)
void ShowFeedback(SpriteRenderer feedback, bool show = true, float duration = 1f)
{
feedback.enabled = show;
CancelInvoke();
Invoke("HideAllFeedback", 1f);
Invoke("HideAllFeedback", duration);
}
void HideAllFeedback()

12
namedropper/Assets/Scripts/Game.cs

@ -6,6 +6,7 @@ using UnityEngine.SceneManagement;
public class Game : MonoBehaviour
{
const bool HIDE_SCORES = true;
int _seconds = 70;
[SerializeField] Text Score1;
@ -222,6 +223,17 @@ public class Game : MonoBehaviour
public void UpdateScores()
{
if (HIDE_SCORES)
{
Score1.text = "";
Score2.text = "";
Score3.text = "";
Score4.text = "";
return;
}
if (GameManager.Instance.Competitive == false) {
int score = GameManager.Instance.Score1 + GameManager.Instance.Score2 + GameManager.Instance.Score3 + GameManager.Instance.Score4;
Score1.text = score.ToString();

8
namedropper/Assets/Scripts/Player.cs

@ -187,10 +187,10 @@ public class Player : MonoBehaviour
if (category.Elements.Contains(_text.text))
{
_streak++;
int score = 10 * _streak;
int streakBonus = category.ShowFeedbackGood(_streak);
int score = 10 + 10 * streakBonus;
_game.AddScore(score, _playerNumber);
category.ShowFeedbackGood(_streak);
Respawn();
}
else
@ -198,8 +198,8 @@ public class Player : MonoBehaviour
_streak = 0;
category.ShowFeedbackBad(_categoryName);
this.gameObject.SetActive(false);
Respawn();
//Invoke("Respawn", 2f);
//Respawn();
Invoke("Respawn", 2f);
}
}

Loading…
Cancel
Save