レベルアップで背景の変更

守矢諏訪子 <suwako@076.moe>、2026-07-11 20:37
コミット 1fcaf1f2e78600391ba00da3390391bc27c76a30 ・親 2874023 ・ファイルを見る

4個のファイル、+25 -8

@@ -43,5 +43,8 @@
4343
4444 bool m_GameOver = false;
4545 bool m_CanHold = true;
46+
47+ vector<string> m_Bg = { "bg_beach", "bg_city", "bg_mount", "bg_road", "bg_sunset", "bg_waterfall" };
48+ i8 m_CurBg = 0;
4649 }; // struct GameMain
4750 } // namespace tetris::scene
@@ -11,11 +11,17 @@
1111
1212 Texture2D LoadTexture(const string &name, const u8 *data, i32 dataSize);
1313 Texture2D GetTexture(const string &name);
14- void DrawBackground(const string &name, Color tint = WHITE);
14+ void DrawBackground(Color tint = WHITE);
1515 void UnloadAll();
16+ void SetBackground(const string &name);
1617
18+ public:
19+ string GetCurrentBackground() const { return m_CurBg; }
20+
1721 private:
1822 ImgMan() = default;
1923 std::unordered_map<string, Texture2D> m_Textures;
24+
25+ string m_CurBg = "bg_beach";
2026 }; // struct ImgMan
2127 } // namespace tetris::sys
@@ -95,7 +95,7 @@
9595 }
9696
9797 void GameMain::DrawUpdate() {
98- sys::ImgMan::Get().DrawBackground("bg_beach");
98+ sys::ImgMan::Get().DrawBackground();
9999 Rectangle gameArea = {
100100 boardPos.x - 160,
101101 boardPos.y - 30,
@@ -338,7 +338,14 @@
338338 m_Lines += clearLine;
339339 m_Score += clearLine * clearLine * 100;
340340
341+ i8 oldLevel = m_Level;
341342 m_Level = 1 + (m_Lines / 10);
343+
344+ if (m_Level > oldLevel && m_Level - 1 < (i8)m_Bg.size()) {
345+ m_CurBg = m_Level - 1;
346+ sys::ImgMan::Get().SetBackground(m_Bg[m_CurBg]);
347+ }
348+
342349 m_FallSpeed = std::max(.15f, .8f - (m_Level - 1) * .07f);
343350 }
344351 }
@@ -39,12 +39,9 @@
3939 return Texture2D{};
4040 }
4141
42- void ImgMan::DrawBackground(const string &name, Color tint) {
43- Texture2D tx = GetTexture(name);
44- if (tx.id == 0) {
45- DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
46- return;
47- }
42+ void ImgMan::DrawBackground(Color tint) {
43+ Texture2D tx = GetTexture(m_CurBg);
44+ if (tx.id == 0) return;
4845
4946 DrawTexturePro(tx,
5047 { 0, 0, (f32)tx.width, (f32)tx.height },
@@ -55,5 +52,9 @@
5552 void ImgMan::UnloadAll() {
5653 for (auto &[name, tx] : m_Textures) UnloadTexture(tx);
5754 m_Textures.clear();
55+ }
56+
57+ void ImgMan::SetBackground(const string &name) {
58+ if (m_Textures.contains(name)) m_CurBg = name;
5859 }
5960 } // namespace tetris::sys