Commit e58e68d9 authored by saad's avatar saad

increase tick sound speed over time

bug: the tick sound doesn't work in mcq game
parent 70812d7e
...@@ -707,7 +707,7 @@ MonoBehaviour: ...@@ -707,7 +707,7 @@ MonoBehaviour:
classCode: classCode:
runSpeed: 8 runSpeed: 8
lives: 5 lives: 5
startTime: 60 startTime: 100
correctAnswerBonusTime: 10 correctAnswerBonusTime: 10
wrongAnswerPenaltyTime: 10 wrongAnswerPenaltyTime: 10
useOfflineTestData: 0 useOfflineTestData: 0
......
...@@ -7,6 +7,7 @@ using UnityEngine.Events; ...@@ -7,6 +7,7 @@ using UnityEngine.Events;
namespace com.al_arcade.cs namespace com.al_arcade.cs
{ {
using com.al_arcade.mcq;
using shared; using shared;
using Unity.Cinemachine; using Unity.Cinemachine;
...@@ -56,7 +57,7 @@ namespace com.al_arcade.cs ...@@ -56,7 +57,7 @@ namespace com.al_arcade.cs
private int _deltaChangeInSize; private int _deltaChangeInSize;
private bool _showHint = true; private bool _showHint = true;
private Camera _cam; private Camera _cam;
private float _quarterTime;
CinemachineTargetGroup _targetGroup; CinemachineTargetGroup _targetGroup;
CinemachineGroupFraming _groupFraming; CinemachineGroupFraming _groupFraming;
...@@ -122,17 +123,24 @@ namespace com.al_arcade.cs ...@@ -122,17 +123,24 @@ namespace com.al_arcade.cs
protected override void OnTimerTick(float timeLeft) protected override void OnTimerTick(float timeLeft)
{ {
// Ticking sound when under 4 seconds float quarter = CsPrefabBuilder.Instance.startTime / 4f;
if (timeLeft < 4f && !_isTicking)
if (timeLeft < quarter && !_isTicking)
{ {
_isTicking = true; _isTicking = true;
SSAudioManager.Instance?.Tick(true); SSAudioManager.Instance?.Tick(true);
} }
else if (timeLeft >= 4f && _isTicking) else if (timeLeft >= quarter && _isTicking)
{ {
_isTicking = false; _isTicking = false;
SSAudioManager.Instance?.Tick(false); SSAudioManager.Instance?.Tick(false);
} }
if (_isTicking)
{
float t = 1f - (timeLeft / quarter);
float pitch = Mathf.Lerp(1f, 2.5f, t);
SSAudioManager.Instance?.SetTickPitch(pitch);
}
uiManager?.SetTimer(timeLeft); uiManager?.SetTimer(timeLeft);
} }
...@@ -176,6 +184,7 @@ namespace com.al_arcade.cs ...@@ -176,6 +184,7 @@ namespace com.al_arcade.cs
onGameStart?.Invoke(); onGameStart?.Invoke();
StartCoroutine(QuestionLoop()); StartCoroutine(QuestionLoop());
_quarterTime = CsPrefabBuilder.Instance.startTime / 4;
} }
// ─── Update: CS also needs the state guard from original ───────────── // ─── Update: CS also needs the state guard from original ─────────────
...@@ -240,13 +249,12 @@ namespace com.al_arcade.cs ...@@ -240,13 +249,12 @@ namespace com.al_arcade.cs
// ─── Timer helpers ──────────────────────────────────────────────────── // ─── Timer helpers ────────────────────────────────────────────────────
private void AdjustTimer(float delta) private void AdjustTimer(float delta)
{ {
UpdateTimerBy(delta); _timeLeft = Mathf.Clamp(_timeLeft + delta, 0f, CsPrefabBuilder.Instance.startTime);
_timeLeft = Mathf.Clamp(_timeLeft, 0, CsPrefabBuilder.Instance.startTime);
// Re-check tick state after adjustment // Re-check tick state after adjustment
if (_timeLeft < 4f && !_isTicking) if (_timeLeft < _quarterTime && !_isTicking)
{ _isTicking = true; SSAudioManager.Instance?.Tick(true); } { _isTicking = true; SSAudioManager.Instance?.Tick(true); }
else if (_timeLeft >= 4f && _isTicking) else if (_timeLeft >= _quarterTime && _isTicking)
{ _isTicking = false; SSAudioManager.Instance?.Tick(false); } { _isTicking = false; SSAudioManager.Instance?.Tick(false); }
uiManager?.UpdateTimer(_timeLeft, delta > 0); uiManager?.UpdateTimer(_timeLeft, delta > 0);
......
...@@ -505,9 +505,9 @@ namespace com.al_arcade.cs ...@@ -505,9 +505,9 @@ namespace com.al_arcade.cs
public void SetTimer(float time) public void SetTimer(float time)
{ {
if (isTweening) return; if (isTweening) return;
float quarter = CsPrefabBuilder.Instance.startTime / 4f;
_timerSlider.value = time / 30f; _timerSlider.value = time / CsPrefabBuilder.Instance.startTime;
_timerFill.color = time > 4f ? _timerDefaultColor : SSColorPalette.Danger; _timerFill.color = time > quarter ? _timerDefaultColor : SSColorPalette.Danger;
} }
public void EnableScore(bool value) public void EnableScore(bool value)
{ {
...@@ -525,27 +525,22 @@ namespace com.al_arcade.cs ...@@ -525,27 +525,22 @@ namespace com.al_arcade.cs
public void UpdateTimer(float time, bool pos) public void UpdateTimer(float time, bool pos)
{ {
isTweening = true; isTweening = true;
float quarter = CsPrefabBuilder.Instance.startTime / 4f;
var color = pos ? SSColorPalette.CorrectWord : SSColorPalette.Danger; // ✅ after the flash, return to red if still in danger zone, normal if above quarter
_timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f); Color restingColor = time > quarter ? _timerDefaultColor : SSColorPalette.Danger;
_timerFill.DOColor(color, 0.2f).SetEase(Ease.OutQuad).OnComplete(() =>
{
_timerFill.DOColor(_timerDefaultColor, 0.2f).SetEase(Ease.OutQuad);
});
var targetTime = time;
// Account for tween time var flashColor = pos ? SSColorPalette.CorrectWord : SSColorPalette.Danger;
if (!pos) _timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f);
{ _timerFill.DOColor(flashColor, 0.2f).SetEase(Ease.OutQuad).OnComplete(() =>
targetTime -= 0.3f;
}
_timerSlider.DOValue(targetTime / 30f, 0.3f).SetEase(Ease.OutQuad).OnComplete(() =>
{ {
isTweening = false; _timerFill.DOColor(restingColor, 0.2f).SetEase(Ease.OutQuad); // ✅ smart resting color
}); });
var targetTime = pos ? time : time - 0.3f;
_timerSlider.DOValue(targetTime / CsPrefabBuilder.Instance.startTime, 0.3f)
.SetEase(Ease.OutQuad)
.OnComplete(() => isTweening = false);
} }
public void ResetUI() public void ResetUI()
......
...@@ -190,13 +190,11 @@ namespace com.al_arcade.mcq ...@@ -190,13 +190,11 @@ namespace com.al_arcade.mcq
public void SetTimer(float time) public void SetTimer(float time)
{ {
if (_isTweening) return; if (_isTweening) return;
float quarter = McqPrefabBuilder.Instance.startTime / 4f;
if (_timerSlider != null) if (_timerSlider != null)
_timerSlider.value = time / McqPrefabBuilder.Instance.startTime; _timerSlider.value = time / McqPrefabBuilder.Instance.startTime;
if (_timerFill != null) if (_timerFill != null)
_timerFill.color = time > 4f ? _timerDefaultColor : SSColorPalette.Danger; _timerFill.color = time > quarter ? _timerDefaultColor : SSColorPalette.Danger; // ✅ red below quarter
if (_timerText != null) if (_timerText != null)
_timerText.Text = Mathf.CeilToInt(time).ToString(); _timerText.Text = Mathf.CeilToInt(time).ToString();
} }
...@@ -205,21 +203,22 @@ namespace com.al_arcade.mcq ...@@ -205,21 +203,22 @@ namespace com.al_arcade.mcq
public void UpdateTimer(float time, bool positive) public void UpdateTimer(float time, bool positive)
{ {
_isTweening = true; _isTweening = true;
float quarter = McqPrefabBuilder.Instance.startTime / 4f;
var flashColor = positive ? SSColorPalette.CorrectWord : SSColorPalette.Danger; // ✅ after flash, go red if still in danger zone, normal if bonus pushed us above quarter
Color restingColor = time > quarter ? _timerDefaultColor : SSColorPalette.Danger;
var flashColor = positive ? SSColorPalette.CorrectWord : SSColorPalette.Danger;
if (_timerSlider != null) if (_timerSlider != null)
_timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f); _timerSlider.transform.DOPunchScale(Vector3.one * 0.1f, 0.3f, 8, 0.3f);
if (_timerFill != null) if (_timerFill != null)
{ {
_timerFill.DOColor(flashColor, 0.2f).SetEase(Ease.OutQuad) _timerFill.DOColor(flashColor, 0.2f).SetEase(Ease.OutQuad)
.OnComplete(() => .OnComplete(() =>
_timerFill.DOColor(_timerDefaultColor, 0.2f).SetEase(Ease.OutQuad)); _timerFill.DOColor(restingColor, 0.2f).SetEase(Ease.OutQuad)); // ✅ smart resting color
} }
float targetTime = positive ? time : time - 0.3f; float targetTime = positive ? time : time - 0.3f;
if (_timerSlider != null) if (_timerSlider != null)
{ {
_timerSlider.DOValue(targetTime / McqPrefabBuilder.Instance.startTime, 0.3f) _timerSlider.DOValue(targetTime / McqPrefabBuilder.Instance.startTime, 0.3f)
......

using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -87,18 +87,26 @@ namespace com.al_arcade.shared ...@@ -87,18 +87,26 @@ namespace com.al_arcade.shared
{ {
if (start) if (start)
{ {
if (_tickingSource.isPlaying) if (_tickingSource.isPlaying) return; // ✅ prevent restart
{
_tickingSource.Stop();
}
_tickingSource.clip = tickingLoop; _tickingSource.clip = tickingLoop;
_tickingSource.loop = true; // ✅ IMPORTANT
_tickingSource.pitch = 1f; // reset
_tickingSource.Play(); _tickingSource.Play();
} }
else else
{ {
_tickingSource.Stop(); if (_tickingSource.isPlaying)
_tickingSource.Stop();
} }
} }
// ADD this new method below the existing Tick() method
public void SetTickPitch(float pitch)
{
if (_tickingSource != null && _tickingSource.isPlaying)
_tickingSource.pitch = Mathf.Clamp(pitch, 1f, 3f);
}
public void StopMusic() public void StopMusic()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment