game: better scoring/run completion
This commit is contained in:
parent
d2c08ac57d
commit
49a5930c3c
2731
RunningLateGame/Assets/Scenes/Playgrounds/SharedAIPlayground.unity
Normal file
2731
RunningLateGame/Assets/Scenes/Playgrounds/SharedAIPlayground.unity
Normal file
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 92017b6393d1f4144b0d915b9463f66c
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -45,6 +45,11 @@ public enum DisplayState
|
|||
/// </summary>
|
||||
[SerializeField] private GameObject guiHudObject;
|
||||
|
||||
/// <summary>
|
||||
/// game object for the completion menu
|
||||
/// </summary>
|
||||
[SerializeField] private GameObject guiCompletedMenuObject;
|
||||
|
||||
/// <summary>
|
||||
/// float to keep track of the elapsed play/run/speeder time
|
||||
/// </summary>
|
||||
|
@ -70,11 +75,6 @@ public enum DisplayState
|
|||
/// </summary>
|
||||
private Label _uiLabelInteractionPrompt;
|
||||
|
||||
/// <summary>
|
||||
/// hud ui label for the player's score out of a thousand
|
||||
/// </summary>
|
||||
private Label _uiLabelScore;
|
||||
|
||||
/// <summary>
|
||||
/// hud ui label for the speed-run stopwatch
|
||||
/// </summary>
|
||||
|
@ -170,7 +170,7 @@ private void InitialiseInterfaceElements()
|
|||
|
||||
_ui = guiHudObject.GetComponent<UIDocument>()?.rootVisualElement;
|
||||
_uiLabelStopwatch = _ui.Q<Label>("CurrentStopwatchLabel");
|
||||
_uiLabelScore = _ui.Q<Label>("CurrentScoreLabel");
|
||||
// _uiLabelScore = _ui.Q<Label>("CurrentScoreLabel");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -455,4 +455,44 @@ public void ClearInteractionPrompt()
|
|||
{
|
||||
_uiLabelInteractionPrompt.visible = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// function to end the run, calculate a score and grade, and show the appropriate menu
|
||||
/// </summary>
|
||||
public void ProperlyEndRun()
|
||||
{
|
||||
SetDisplayState(DisplayState.OverlayCompleteUnderTimeMenu);
|
||||
|
||||
var ui = guiCompletedMenuObject.GetComponent<UIDocument>()?.rootVisualElement;
|
||||
var timeLabel = ui.Q<Label>("FinalTimeLabel");
|
||||
var timeScore = ui.Q<Label>("FinalScoreLabel");
|
||||
var timeGrade = ui.Q<Label>("FinalGradeLabel");
|
||||
|
||||
// calculate a score between 0-1000 and grade (S, A, B, C, D)
|
||||
// if you finish the run in 2.5 minutes, you get a 1000
|
||||
// from 2.5 to 5 minutes, the score goes down to 0
|
||||
|
||||
// scoring parameters
|
||||
const float maxScore = 1000f;
|
||||
const float maxTimeForMaxScore = 150f; // 2.5 minutes
|
||||
const float maxTimeForMinScore = 300f; // 5 minutes
|
||||
|
||||
var score = _elapsedRunTime switch
|
||||
{
|
||||
<= maxTimeForMaxScore => maxScore,
|
||||
>= maxTimeForMinScore => 0,
|
||||
_ => maxScore * (1 - (_elapsedRunTime - maxTimeForMaxScore) / (maxTimeForMinScore - maxTimeForMaxScore))
|
||||
};
|
||||
|
||||
timeLabel.text = $"Completed in {_uiLabelStopwatch.text}";
|
||||
timeGrade.text = score switch
|
||||
{
|
||||
>= 900 => "S",
|
||||
>= 800 => "A",
|
||||
>= 700 => "B",
|
||||
>= 600 => "C",
|
||||
_ => "D"
|
||||
};
|
||||
timeScore.text = $"Score: {score}";
|
||||
}
|
||||
}
|
|
@ -13,6 +13,6 @@ public class RunCompletionTrigger : MonoBehaviour
|
|||
{
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
GameManager.Instance.SetDisplayState(GameManager.DisplayState.OverlayCompleteUnderTimeMenu);
|
||||
GameManager.Instance.ProperlyEndRun();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#Root {
|
||||
-unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Medium.otf?fileID=12800000&guid=9439a6fdc5392c6479cda7dd72a8f3f7&type=3#Fervojo-Medium");
|
||||
-unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Medium%20SDF.asset?fileID=11400000&guid=45943718062c86e448361bd7f6506932&type=2#Fervojo-Medium SDF");
|
||||
background-color: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
Button {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<Style src="project://database/Assets/UI%20Toolkit/Interfaces/Common.uss?fileID=7433441132597879392&guid=7e22eeee55627cf478c5e125a8197039&type=3#Common" />
|
||||
<ui:VisualElement name="Root" style="flex-grow: 1; justify-content: space-around; align-items: center;">
|
||||
<ui:VisualElement name="Root" style="flex-grow: 1; justify-content: space-around; align-items: center; background-color: rgba(0, 0, 0, 0);">
|
||||
<ui:VisualElement name="VertHolder" style="flex-grow: 1; justify-content: flex-start; align-items: center; align-self: auto; margin-top: 2%;">
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="00:53.47" name="CurrentStopwatchLabel" enable-rich-text="false" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 64px; margin-bottom: 0; padding-bottom: 0;" />
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="1,000" name="CurrentScoreLabel" enable-rich-text="false" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 32px; margin-top: 0; padding-top: 0;" />
|
||||
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" text="1,000" name="CurrentScoreLabel" enable-rich-text="false" style="color: rgb(255, 255, 255); -unity-text-align: upper-center; white-space: normal; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF"); font-size: 32px; margin-top: 0; padding-top: 0; display: none;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
<ui:VisualElement name="HoriHolder" style="flex-grow: 1; flex-direction: column; max-height: 60%; margin-left: 10%; margin-right: 10%;">
|
||||
<ui:VisualElement name="Logospace" style="flex-grow: 1; width: auto; flex-direction: row; height: 50%; min-height: 50%;">
|
||||
<ui:VisualElement name="Header" style="background-image: none; -unity-background-scale-mode: scale-to-fit; flex-grow: 1; flex-shrink: 0; align-items: center; justify-content: center; align-self: stretch;">
|
||||
<ui:Label tabindex="-1" text="A" parse-escape-sequences="true" display-tooltip-when-elided="true" name="FinalGradeLabel" style="-unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/GODarkslide/GODarkslide-distressed.ttf?fileID=12800000&guid=1f2f7dc4dddb45a4e91b4b96053f09f6&type=3#GODarkslide-distressed"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/GODarkslide/GODarkslide-distressed%20SDF.asset?fileID=11400000&guid=e706151e7fb3790409b13d29b812a8ff&type=2#GODarkslide-distressed SDF"); font-size: 100px; color: rgb(193, 39, 45); -unity-text-align: upper-center; white-space: normal; text-overflow: clip; rotate: -12.347deg; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
|
||||
<ui:Label tabindex="-1" text="Completed in 01:59.23" parse-escape-sequences="true" display-tooltip-when-elided="true" name="FinalTimeLabel" style="color: rgb(255, 255, 255); font-size: 26px; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF");" />
|
||||
<ui:Label tabindex="-1" text="1,000" parse-escape-sequences="true" display-tooltip-when-elided="true" name="FinalScoreLabel" style="color: rgb(255, 255, 255); font-size: 20px; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0;" />
|
||||
<ui:Label tabindex="-1" text="A" parse-escape-sequences="true" display-tooltip-when-elided="true" name="FinalGradeLabel" style="-unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/GODarkslide/GODarkslide-distressed.ttf?fileID=12800000&guid=1f2f7dc4dddb45a4e91b4b96053f09f6&type=3#GODarkslide-distressed"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/GODarkslide/GODarkslide-distressed%20SDF.asset?fileID=11400000&guid=e706151e7fb3790409b13d29b812a8ff&type=2#GODarkslide-distressed SDF"); font-size: 150px; color: rgb(193, 39, 45); -unity-text-align: upper-center; white-space: normal; text-overflow: clip; rotate: -12.347deg; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;" />
|
||||
<ui:Label tabindex="-1" text="Completed in 01:59.23" parse-escape-sequences="true" display-tooltip-when-elided="true" name="FinalTimeLabel" style="color: rgb(255, 255, 255); font-size: 38px; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; -unity-font: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold.otf?fileID=12800000&guid=505dfbc18d2d4604db47ff55755f9dc8&type=3#Fervojo-Bold"); -unity-font-definition: url("project://database/Assets/UI%20Toolkit/RLFonts/Fervojo/Fervojo-Bold%20SDF.asset?fileID=11400000&guid=1abb65c0bf74b1649863fc75b2b83ac1&type=2#Fervojo-Bold SDF");" />
|
||||
<ui:Label tabindex="-1" text="1,000" parse-escape-sequences="true" display-tooltip-when-elided="true" name="FinalScoreLabel" style="color: rgb(255, 255, 255); font-size: 28px; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="Buttonspace" style="flex-grow: 1; width: 50%; min-width: 50%; height: 50%; min-height: 50%; align-items: center; justify-content: flex-end; align-self: center; flex-direction: column;">
|
||||
|
|
Reference in a new issue