レベルアップで背景の変更
守矢諏訪子 <suwako@076.moe>、2026-07-11 20:37
コミット 1fcaf1f2e78600391ba00da3390391bc27c76a30
・親 2874023
・ファイルを見る
4個のファイル、+25 -8
| @@ -43,5 +43,8 @@ | ||
| 43 | 43 | |
| 44 | 44 | bool m_GameOver = false; |
| 45 | 45 | 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; | |
| 46 | 49 | }; // struct GameMain |
| 47 | 50 | } // namespace tetris::scene |
| @@ -11,11 +11,17 @@ | ||
| 11 | 11 | |
| 12 | 12 | Texture2D LoadTexture(const string &name, const u8 *data, i32 dataSize); |
| 13 | 13 | Texture2D GetTexture(const string &name); |
| 14 | - void DrawBackground(const string &name, Color tint = WHITE); | |
| 14 | + void DrawBackground(Color tint = WHITE); | |
| 15 | 15 | void UnloadAll(); |
| 16 | + void SetBackground(const string &name); | |
| 16 | 17 | |
| 18 | + public: | |
| 19 | + string GetCurrentBackground() const { return m_CurBg; } | |
| 20 | + | |
| 17 | 21 | private: |
| 18 | 22 | ImgMan() = default; |
| 19 | 23 | std::unordered_map<string, Texture2D> m_Textures; |
| 24 | + | |
| 25 | + string m_CurBg = "bg_beach"; | |
| 20 | 26 | }; // struct ImgMan |
| 21 | 27 | } // namespace tetris::sys |
| @@ -95,7 +95,7 @@ | ||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | void GameMain::DrawUpdate() { |
| 98 | - sys::ImgMan::Get().DrawBackground("bg_beach"); | |
| 98 | + sys::ImgMan::Get().DrawBackground(); | |
| 99 | 99 | Rectangle gameArea = { |
| 100 | 100 | boardPos.x - 160, |
| 101 | 101 | boardPos.y - 30, |
| @@ -338,7 +338,14 @@ | ||
| 338 | 338 | m_Lines += clearLine; |
| 339 | 339 | m_Score += clearLine * clearLine * 100; |
| 340 | 340 | |
| 341 | + i8 oldLevel = m_Level; | |
| 341 | 342 | 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 | + | |
| 342 | 349 | m_FallSpeed = std::max(.15f, .8f - (m_Level - 1) * .07f); |
| 343 | 350 | } |
| 344 | 351 | } |
| @@ -39,12 +39,9 @@ | ||
| 39 | 39 | return Texture2D{}; |
| 40 | 40 | } |
| 41 | 41 | |
| 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; | |
| 48 | 45 | |
| 49 | 46 | DrawTexturePro(tx, |
| 50 | 47 | { 0, 0, (f32)tx.width, (f32)tx.height }, |
| @@ -55,5 +52,9 @@ | ||
| 55 | 52 | void ImgMan::UnloadAll() { |
| 56 | 53 | for (auto &[name, tx] : m_Textures) UnloadTexture(tx); |
| 57 | 54 | m_Textures.clear(); |
| 55 | + } | |
| 56 | + | |
| 57 | + void ImgMan::SetBackground(const string &name) { | |
| 58 | + if (m_Textures.contains(name)) m_CurBg = name; | |
| 58 | 59 | } |
| 59 | 60 | } // namespace tetris::sys |