/** Copyright (c) テクニカル諏訪子 Permission is hereby granted to any person obtaining a copy of the software Tetris (the "Software") to use, modify, merge, copy, publish, distribute, sublicense, and/or sell copies of the Software, subject to the following conditions: 1. **Origin Attribution**: - You must not misrepresent the origin of the Software; you must not claim you created the original Software. - If the Software is used in a product, you must either: a. Provide clear attribution in the product's documentation, user interface, or other visible areas, **OR** b. Pay the original developers a fee they specify in writing. 2. **Usage Restriction**: - The Software, or any derivative works, dependencies, or libraries incorporating it, must not be used for censorship or to suppress freedom of speech, expression, or creativity. Prohibited uses include, but are not limited to: - Censorship of so-called "hate speech", visuals, non-mainstream opinions, ideas, or objective reality. - Tools or systems designed to restrict access to information or artistic works. 3. **Notice Preservation**: - This license and the above copyright notice must remain intact in all copies of the source code. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include namespace tetris::scene { Texture2D titleBackground; Texture2D htpBackground; void Title::Init(Game *game) { m_Game = game; titleBackground = sys::ImgMan::Get().LoadTexture("tx_titlebg", ass_TitleGamen_png, ass_TitleGamen_png_len); htpBackground = sys::ImgMan::Get().LoadTexture("tx_htpbg", ass_TitleGamen_htp_png, ass_TitleGamen_htp_png_len); sys::ImgMan::Get().SetBackground(m_Bg[0]); // tx_titlebg auto &snd = sys::SndMan::Get(); if (!snd.LoadBgm("bgm_title", ass_title_intro_ogg, ass_title_intro_ogg_len, ass_title_loop_ogg, ass_title_loop_ogg_len)) { TraceLog(LOG_WARNING, "Failed to load BGM!"); } else { snd.PlayBgm("bgm_title"); } snd.LoadSfx("sfx_confirm", __ass_confirm_ogg, __ass_confirm_ogg_len); snd.LoadSfx("sfx_quit", __ass_quit_ogg, __ass_quit_ogg_len); snd.LoadSfx("sfx_select", __ass_select_ogg, __ass_select_ogg_len); } void Title::FuncUpdate() { handleInput(); sys::SndMan::Get().Update(GetFrameTime()); } void Title::DrawUpdate() { sys::ImgMan::Get().DrawBackground(); if (m_CurMenu == Menu::TitleScreen) { Font font = GetFontDefault(); Vector2 menuPos = { GetScreenWidth() / 2.f - 120.f, GetScreenHeight() / 2.f + 20.f, }; constexpr f32 spacing = 40.f; auto DrawButton = [](Font font, cstr text, Vector2 pos, bool selected) { f32 scale = selected ? 1.05f + 0.03f * sinf(GetTime() * 8.f) : 1.f; Color color = selected ? WHITE : Fade(WHITE, 0.5f); f32 sizePx = 20.f * scale; Vector2 textSize = MeasureTextEx(font, text, sizePx, 0); DrawTextPro(font, text, pos, { textSize.x / 2.f, textSize.y / 2.f }, 0.f, sizePx, 2.f, color); if (selected) DrawTextPro(font, ">", { pos.x - textSize.x / 2.f - 30.f, pos.y }, { 0.f, textSize.y / 2.f }, 0.f, sizePx, 4.f, color); }; DrawButton(font, "GAME START", { menuPos.x, menuPos.y + spacing * 0 }, m_MenuSelect == Menu::TitleScreen); DrawButton(font, "HOW TO PLAY", { menuPos.x, menuPos.y + spacing * 1 }, m_MenuSelect == Menu::HowToPlay); DrawButton(font, "CREDITS", { menuPos.x, menuPos.y + spacing * 2 }, m_MenuSelect == Menu::Credits); DrawButton(font, "QUIT", { menuPos.x, menuPos.y + spacing * 3 }, m_MenuSelect == Menu::Quit); } else if (m_CurMenu == Menu::Credits) { auto DrawText = [](Font font, cstr text, Vector2 pos) { f32 scale = 1.f; Color color = WHITE; f32 sizePx = 20.f * scale; Vector2 textSize = MeasureTextEx(font, text, sizePx, 0); DrawTextPro(font, text, pos, { textSize.x / 2.f, textSize.y / 2.f }, 0.f, sizePx, 2.f, color); }; Font font = GetFontDefault(); constexpr f32 spacing = 30.f; const i32 lastLine = 15; const f32 blockHeight = lastLine * spacing; const f32 startY = GetScreenHeight() / 2.f - blockHeight / 2.f; Vector2 pos = { GetScreenWidth() / 2.f, startY }; DrawText(font, "CODE/DESIGN/ART:", { pos.x, pos.y + spacing * 0 }); DrawText(font, "TechnicalSuwako", { pos.x, pos.y + spacing * 1 }); DrawText(font, "MUSIC:", { pos.x, pos.y + spacing * 3 }); DrawText(font, "hiiragi_magne (x.com/hiiragi_magne)", { pos.x, pos.y + spacing * 4 }); DrawText(font, "Jutenks (youtube.com/@JutenksViak)", { pos.x, pos.y + spacing * 5 }); DrawText(font, "Summoning Beatz (youtube.com/@summoningbeatz)", { pos.x, pos.y + spacing * 6 }); DrawText(font, "HAIKEI:", { pos.x, pos.y + spacing * 8 }); DrawText(font, "brzozkamarcin", { pos.x, pos.y + spacing * 9 }); DrawText(font, "(pixabay.com/users/brzozkamarcin-10835605)", { pos.x, pos.y + spacing * 10 }); DrawText(font, "SFX:", { pos.x, pos.y + spacing * 12 }); DrawText(font, "PhatPhrogStudio", { pos.x, pos.y + spacing * 13 }); DrawText(font, "(pixabay.com/users/phatphrogstudio-54178146)", { pos.x, pos.y + spacing * 14 }); DrawText(font, "PRESS ESC FOR RETURN TO THE TITLE SCREEN", { pos.x, pos.y + spacing * 16 }); } else if (m_CurMenu == Menu::HowToPlay) { auto DrawText = [](Font font, cstr text, Vector2 pos) { f32 scale = 1.f; Color color = WHITE; f32 sizePx = 20.f * scale; Vector2 textSize = MeasureTextEx(font, text, sizePx, 0); DrawTextPro(font, text, pos, { 0.f, textSize.y / 2.f }, 0.f, sizePx, 2.f, color); }; Font font = GetFontDefault(); constexpr f32 spacing = 30.f; const i32 lastLine = 12; const f32 blockHeight = lastLine * spacing; const f32 startY = GetScreenHeight() / 2.f - blockHeight / 2.f; Vector2 pos = { 120.f, startY }; DrawText(font, "MOVING: LEFT/RIGHT/UP/DOWN OR WASD", { pos.x, pos.y + spacing * 0 }); DrawText(font, "CONFIRM: ENTER", { pos.x, pos.y + spacing * 1 }); DrawText(font, "PAUSE: ESC", { pos.x, pos.y + spacing * 2 }); DrawText(font, "ROTATE: SPACE", { pos.x, pos.y + spacing * 3 }); DrawText(font, "HOLD: CTRL", { pos.x, pos.y + spacing * 4 }); DrawText(font, "PRESS ESC FOR RETURN TO THE TITLE SCREEN", { pos.x, pos.y + spacing * 10 }); } } void Title::Close() { sys::SndMan::Get().StopBgm(); } /////////////// void Title::handleInput() { if (IsKeyPressed(KEY_HOME) && m_MenuSelect != Menu::TitleScreen) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::TitleScreen; } if (IsKeyPressed(KEY_END) && m_MenuSelect != Menu::Quit) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::Quit; } switch (m_MenuSelect) { case Menu::TitleScreen: { if (m_CurMenu == Menu::TitleScreen) { if (IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_S)) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::HowToPlay; } if (IsKeyPressed(KEY_ENTER)) { sys::SndMan::Get().PlaySfx("sfx_confirm"); assert(m_Game != nullptr); m_Game->SetNextScene(Scene::GameMain); } } break; } case Menu::HowToPlay: { if (m_CurMenu == Menu::TitleScreen) { if (IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_S)) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::Credits; } if (IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_W)) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::TitleScreen; } if (m_CurMenu == Menu::TitleScreen && IsKeyPressed(KEY_ENTER)) { sys::SndMan::Get().PlaySfx("sfx_confirm"); sys::ImgMan::Get().SetBackground(m_Bg[1]); // tx_htpbg m_CurMenu = Menu::HowToPlay; } } else { if (m_CurMenu == Menu::HowToPlay && IsKeyPressed(KEY_ESCAPE)) { sys::SndMan::Get().PlaySfx("sfx_quit"); sys::ImgMan::Get().SetBackground(m_Bg[0]); // tx_titlebg m_CurMenu = Menu::TitleScreen; } } break; } case Menu::Credits: { if (m_CurMenu == Menu::TitleScreen) { if (IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_S)) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::Quit; } if (IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_W)) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::HowToPlay; } if (m_CurMenu == Menu::TitleScreen && IsKeyPressed(KEY_ENTER)) { sys::SndMan::Get().PlaySfx("sfx_confirm"); sys::ImgMan::Get().SetBackground(m_Bg[1]); // tx_htpbg m_CurMenu = Menu::Credits; } } else { if (m_CurMenu == Menu::Credits && IsKeyPressed(KEY_ESCAPE)) { sys::SndMan::Get().PlaySfx("sfx_quit"); sys::ImgMan::Get().SetBackground(m_Bg[0]); // tx_titlebg m_CurMenu = Menu::TitleScreen; } } break; } case Menu::Quit: { if (m_CurMenu == Menu::TitleScreen) { if (IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_W)) { sys::SndMan::Get().PlaySfx("sfx_select"); m_MenuSelect = Menu::Credits; } if (m_CurMenu == Menu::TitleScreen && IsKeyPressed(KEY_ENTER)) { sys::SndMan::Get().PlaySfx("sfx_quit"); m_Game->isRunning = false; } } break; } default: break; } } } // namespace tetris::scene