パニックモード

守矢諏訪子 <suwako@076.moe>、2026-07-16 01:30
コミット 3671925c9589567fecafd93b19fb8964079f5fda ・親 a754b97 ・ファイルを見る

4個のファイル、+51 -2

@@ -55,6 +55,8 @@
5555 void clearLines();
5656 void handleInput();
5757 bool isValidPos(i8 piece, i8 rot, i8 x, i8 y);
58+ i32 stackHeight() const;
59+ f32 targetDangerPitch() const;
5860
5961 private:
6062 void createLandingEffect();
@@ -159,6 +161,8 @@
159161
160162 PauseOption m_PauseSelect = PauseOption::Resume;
161163 f32 m_PauseAlpha = 0.f;
164+
165+ f32 m_DangerPitch = 1.f;
162166
163167 private:
164168 void countdown();
@@ -57,7 +57,9 @@
5757
5858 void PauseBgm();
5959 void ResumeBgm();
60+ void SetBgmPitch(f32 pitch);
6061
62+ public:
6163 void SetSfxVolume(f32 volume) { m_SfxVolume = volume; }
6264 void SetBgmVolume(f32 volume) { m_BgmVolume = volume; }
6365
@@ -219,6 +219,11 @@
219219
220220 m_FallTimer = 0.f;
221221 }
222+
223+ f32 target = targetDangerPitch();
224+ m_DangerPitch = std::lerp(m_DangerPitch, target, GetFrameTime() * 3.5f);
225+
226+ sys::SndMan::Get().SetBgmPitch(m_DangerPitch);
222227 }
223228
224229 void GameMain::DrawUpdate() {
@@ -239,6 +244,7 @@
239244 if (m_ShakeTime > 0.f) {
240245 DrawText(TextFormat("SHAKE: %.2f", m_ShakeTime), 20, 20, 20, RED);
241246 }
247+ DrawText(TextFormat("Height: %d Pitch: %.2f", stackHeight(), m_DangerPitch), 10, 10, 20, WHITE);
242248 #endif
243249
244250 Vector2 drawPos = boardPos;
@@ -562,8 +568,8 @@
562568 i8 oldLevel = m_Level;
563569 m_Level = 1 + (m_Lines / levelUpThreshold);
564570
565- if (m_Level > oldLevel && m_Level - 1 < (i8)m_Bg.size()) {
566- m_CurBg = m_Level - 1;
571+ if (m_Level > oldLevel) {
572+ m_CurBg = (m_Level - 1) % (i8)m_Bg.size();
567573 sys::SndMan::Get().PlaySfx("sfx_level_up");
568574 sys::ImgMan::Get().SetBackground(m_Bg[m_CurBg]);
569575 }
@@ -632,6 +638,34 @@
632638 if (py >= 0 && board[py][px] != 0) return false;
633639 }
634640 return true;
641+ }
642+
643+ i32 GameMain::stackHeight() const {
644+ i32 highestRow = m_VSize;
645+
646+ for (i32 y = 0; y < m_VSize; ++y) {
647+ for (i32 x = 0; x < m_HSize; ++x) {
648+ if (board[y][x] != 0) {
649+ highestRow = y;
650+ goto found;
651+ }
652+ }
653+ }
654+
655+found:
656+
657+ return m_VSize - highestRow;
658+ }
659+
660+ f32 GameMain::targetDangerPitch() const {
661+ constexpr i32 beginDanger = 6;
662+ constexpr i32 maxDanger = 20;
663+
664+ i32 h = stackHeight();
665+ f32 t = std::clamp((h - beginDanger) / f32(maxDanger - beginDanger), 0.0f, 1.0f);
666+ t = t * t * (3.0f - 2.0f * t);
667+
668+ return std::lerp(1.0f, 1.20f, t);
635669 }
636670
637671 ///////////
@@ -33,6 +33,7 @@
3333 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434 */
3535 #include <tetris/sys/sndman.hh>
36+#include <algorithm>
3637
3738 namespace tetris::sys {
3839 SndMan &SndMan::Get() {
@@ -158,5 +159,13 @@
158159 ResumeMusicStream(m_Current->intro);
159160 ResumeMusicStream(m_Current->loop);
160161 }
162+ }
163+
164+ void SndMan::SetBgmPitch(f32 pitch) {
165+ pitch = std::clamp(pitch, .5f, 2.f);
166+ if (!m_Current) return;
167+
168+ if (!m_Current->introDone) SetMusicPitch(m_Current->intro, pitch);
169+ else SetMusicPitch(m_Current->loop, pitch);
161170 }
162171 } // namespace tetris::sys