/** 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. */ #pragma once #include #include #include namespace tetris::scene { struct GameMain { public: void Init(Game *game); void FuncUpdate(); void DrawUpdate(); void Close(); public: u32 GetScore() const { return m_Score; } u16 GetLevel() const { return m_Level; } u16 GetLines() const { return m_Lines; } private: void spawn(); void lock(); void updateBoardLayout(); void drawNextPiece(); void drawHoldPiece(); void drawGhostPiece(Vector2 offset); void clearLines(); void handleInput(); bool isValidPos(i8 piece, i8 rot, i8 x, i8 y); i32 stackHeight() const; f32 targetDangerPitch() const; private: void createLandingEffect(); void updateLandingEffects(); void drawLandingEffects(); void createClearEffect(i8 row); void updateClearEffects(); void drawClearEffects(Vector2 offset); void updateHoldAnimation(); void startHoldAnimation(); void drawHoldAnimation(); private: Game *m_Game = nullptr; u32 m_Score = 0; u16 m_Level = 1; u16 m_Lines = 0; u8 m_Gravity = 30; u8 m_HSize = 10; u8 m_VSize = 20; u8 m_SquareSize = 20; i8 m_Hold = -1; i8 m_CurPiece = 0; i8 m_CurRot = 0; i8 m_CurX = 0; i8 m_CurY = 0; f32 m_FallTimer = 0.f; f32 m_FallSpeed = .8f; bool m_GameOver = false; bool m_CanHold = true; vector m_Bg = { "bg_beach", "bg_city", "bg_mount", "bg_road", "bg_sunset", "bg_waterfall" }; i8 m_CurBg = 0; private: enum class ParticleType { Sparkle, Smoke, }; // enum class ParticleType struct Particle { Vector2 pos; Vector2 vel; Color color; f32 life; f32 size; i8 txIdx; ParticleType type; }; vector m_Particles; struct ClearEffect { i8 row; f32 timer; }; vector m_ClearEffects; f32 m_ShakeTime = 0.f; Vector2 m_ShakeOffset = { 0, 0 }; // 画像 vector m_Sparkles; vector m_Smokes; private: enum class GameState { Countdown, Playing, Paused, GameOver, }; enum class PauseOption { Resume, Quit, }; enum class HoldAnimState { None, FadeOut, Beam, FadeIn, }; HoldAnimState m_HoldAnim = HoldAnimState::None; f32 m_HoldAnimTimer = 0.f; Vector2 m_BeamStart{}; Vector2 m_BeamEnd{}; GameState m_State = GameState::Countdown; f32 m_Countdown = 4.f; i8 m_CountValue = 3; f32 m_TextScale = 1.f; f32 m_TextAlpha = 1.f; PauseOption m_PauseSelect = PauseOption::Resume; f32 m_PauseAlpha = 0.f; f32 m_DangerPitch = 1.f; private: void countdown(); void pause(); }; // struct GameMain } // namespace tetris::scene