master
ブランチ master
Tetris / include / tetris / scene / gamemain.hh
4.8 KB、179行 生 Blame 履歴
1/**
2Copyright (c) テクニカル諏訪子
3
4Permission is hereby granted to any person obtaining a copy of the software
5Tetris (the "Software") to use, modify, merge, copy, publish, distribute,
6sublicense, and/or sell copies of the Software, subject to the following conditions:
7
8 1. **Origin Attribution**:
9 - You must not misrepresent the origin of the Software; you must not claim
10 you created the original Software.
11 - If the Software is used in a product, you must either:
12 a. Provide clear attribution in the product's documentation, user interface,
13 or other visible areas, **OR**
14 b. Pay the original developers a fee they specify in writing.
15 2. **Usage Restriction**:
16 - The Software, or any derivative works, dependencies, or libraries
17 incorporating it, must not be used for censorship or to suppress freedom of
18 speech, expression, or creativity. Prohibited uses include, but are not
19 limited to:
20 - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
21 ideas, or objective reality.
22 - Tools or systems designed to restrict access to information or
23 artistic works.
24 3. **Notice Preservation**:
25 - This license and the above copyright notice must remain intact in all copies
26 of the source code.
27
28THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
30PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
33OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34*/
35#pragma once
36
37#include <util/types.hh>
38#include <raylib.h>
39#include <tetris/tetris.hh>
40
41namespace tetris::scene {
42 struct GameMain {
43 public:
44 void Init(Game *game);
45 void FuncUpdate();
46 void DrawUpdate();
47 void Close();
48
49 public:
50 u32 GetScore() const { return m_Score; }
51 u16 GetLevel() const { return m_Level; }
52 u16 GetLines() const { return m_Lines; }
53
54 private:
55 void spawn();
56 void lock();
57 void updateBoardLayout();
58 void drawNextPiece();
59 void drawHoldPiece();
60 void drawGhostPiece(Vector2 offset);
61 void clearLines();
62 void handleInput();
63 bool isValidPos(i8 piece, i8 rot, i8 x, i8 y);
64 i32 stackHeight() const;
65 f32 targetDangerPitch() const;
66
67 private:
68 void createLandingEffect();
69 void updateLandingEffects();
70 void drawLandingEffects();
71 void createClearEffect(i8 row);
72 void updateClearEffects();
73 void drawClearEffects(Vector2 offset);
74 void updateHoldAnimation();
75 void startHoldAnimation();
76 void drawHoldAnimation();
77
78 private:
79 Game *m_Game = nullptr;
80
81 u32 m_Score = 0;
82 u16 m_Level = 1;
83 u16 m_Lines = 0;
84 u8 m_Gravity = 30;
85
86 u8 m_HSize = 10;
87 u8 m_VSize = 20;
88 u8 m_SquareSize = 20;
89
90 i8 m_Hold = -1;
91
92 i8 m_CurPiece = 0;
93 i8 m_CurRot = 0;
94 i8 m_CurX = 0;
95 i8 m_CurY = 0;
96
97 f32 m_FallTimer = 0.f;
98 f32 m_FallSpeed = .8f;
99
100 bool m_GameOver = false;
101 bool m_CanHold = true;
102
103 vector<string> m_Bg = { "bg_beach", "bg_city", "bg_mount", "bg_road", "bg_sunset", "bg_waterfall" };
104 i8 m_CurBg = 0;
105
106 private:
107 enum class ParticleType {
108 Sparkle,
109 Smoke,
110 }; // enum class ParticleType
111
112 struct Particle {
113 Vector2 pos;
114 Vector2 vel;
115 Color color;
116 f32 life;
117 f32 size;
118 i8 txIdx;
119 ParticleType type;
120 };
121
122 vector<Particle> m_Particles;
123
124 struct ClearEffect {
125 i8 row;
126 f32 timer;
127 };
128
129 vector<ClearEffect> m_ClearEffects;
130
131 f32 m_ShakeTime = 0.f;
132 Vector2 m_ShakeOffset = { 0, 0 };
133
134 // 画像
135 vector<Texture2D> m_Sparkles;
136 vector<Texture2D> m_Smokes;
137
138 private:
139 enum class GameState {
140 Countdown,
141 Playing,
142 Paused,
143 GameOver,
144 };
145
146 enum class PauseOption {
147 Resume,
148 Quit,
149 };
150
151 enum class HoldAnimState {
152 None,
153 FadeOut,
154 Beam,
155 FadeIn,
156 };
157
158 HoldAnimState m_HoldAnim = HoldAnimState::None;
159 f32 m_HoldAnimTimer = 0.f;
160 Vector2 m_BeamStart{};
161 Vector2 m_BeamEnd{};
162
163 GameState m_State = GameState::Countdown;
164
165 f32 m_Countdown = 4.f;
166 i8 m_CountValue = 3;
167 f32 m_TextScale = 1.f;
168 f32 m_TextAlpha = 1.f;
169
170 PauseOption m_PauseSelect = PauseOption::Resume;
171 f32 m_PauseAlpha = 0.f;
172
173 f32 m_DangerPitch = 1.f;
174
175 private:
176 void countdown();
177 void pause();
178 }; // struct GameMain
179} // namespace tetris::scene