Stefan Schuermans commited on 2019-07-14 18:04:07
Showing 3 changed files, with 25 additions and 4 deletions.
... | ... |
@@ -0,0 +1 @@ |
1 |
+50 |
... | ... |
@@ -39,13 +39,16 @@ Tetris::Tetris(const std::string &name, Mgrs &mgrs, const Directory &dirBase): |
39 | 39 |
m_fileStoneColor(dirBase.getFile("stoneColor")), |
40 | 40 |
m_fileDelay(dirBase.getFile("delay")), |
41 | 41 |
m_fileDropDelay(dirBase.getFile("dropDelay")), |
42 |
+ m_fileBlinkDelay(dirBase.getFile("blinkDelay")), |
|
42 | 43 |
m_fileStartSound(dirBase.getFile("startSound")), |
43 | 44 |
m_stoneColor(), |
44 | 45 |
m_delay(c_delayDescr.default_), |
45 | 46 |
m_dropDelay(c_dropDelayDescr.default_), |
47 |
+ m_blinkDelay(c_blinkDelayDescr.default_), |
|
46 | 48 |
m_pConn(NULL), |
47 |
- m_stone(-1), m_rot(-1), m_posX(-1), m_posY(-1), m_dropping(false), |
|
48 |
- m_field() |
|
49 |
+ m_stone(-1), m_rot(-1), m_posX(-1), m_posY(-1), |
|
50 |
+ m_dropping(false), m_blinking(0), |
|
51 |
+ m_field(), m_rowsBlink() |
|
49 | 52 |
{ |
50 | 53 |
// open operator connection interfaces for player |
51 | 54 |
m_mgrs.m_opMgr.open(m_name, this); |
... | ... |
@@ -73,7 +76,8 @@ bool Tetris::updateConfigGame() |
73 | 76 |
// cfg value file was updated -> read new cfg value, return true for update |
74 | 77 |
if (colorUpdate(m_fileStoneColor, m_stoneColor) || |
75 | 78 |
valueUpdate(m_fileDelay, c_delayDescr, m_delay) || |
76 |
- valueUpdate(m_fileDropDelay, c_dropDelayDescr, m_dropDelay)) { |
|
79 |
+ valueUpdate(m_fileDropDelay, c_dropDelayDescr, m_dropDelay) || |
|
80 |
+ valueUpdate(m_fileBlinkDelay, c_blinkDelayDescr, m_blinkDelay)) { |
|
77 | 81 |
ret = true; |
78 | 82 |
} |
79 | 83 |
|
... | ... |
@@ -331,7 +335,12 @@ void Tetris::planTimeStep() |
331 | 335 |
} |
332 | 336 |
|
333 | 337 |
// compute interval based on game state |
334 |
- int interval_ms = m_dropping ? m_dropDelay : m_delay; |
|
338 |
+ int interval_ms = m_delay; |
|
339 |
+ if (m_dropping) { |
|
340 |
+ interval_ms = m_dropDelay; |
|
341 |
+ } else if (m_blinking > 0) { |
|
342 |
+ interval_ms = m_blinkDelay; |
|
343 |
+ } |
|
335 | 344 |
float interval = 1e-3f * interval_ms; |
336 | 345 |
|
337 | 346 |
// request next time call |
... | ... |
@@ -496,5 +505,8 @@ Tetris::ValueDescr const Tetris::c_delayDescr = { 400, 200, 1000 }; |
496 | 505 |
/// descriptor for delay value during dropping a stone |
497 | 506 |
Tetris::ValueDescr const Tetris::c_dropDelayDescr = { 100, 50, 250 }; |
498 | 507 |
|
508 |
+/// descriptor for delay value during blinking of disappearing rows |
|
509 |
+Tetris::ValueDescr const Tetris::c_blinkDelayDescr = { 50, 50, 250 }; |
|
510 |
+ |
|
499 | 511 |
} // namespace Blinker |
500 | 512 |
|
... | ... |
@@ -159,15 +159,20 @@ protected: |
159 | 159 |
/// descriptor for delay value during dropping a stone |
160 | 160 |
static ValueDescr const c_dropDelayDescr; |
161 | 161 |
|
162 |
+ /// descriptor for delay value during blinking of disappearing rows |
|
163 |
+ static ValueDescr const c_blinkDelayDescr; |
|
164 |
+ |
|
162 | 165 |
ColorFile m_fileStoneColor; ///< color file for stone color |
163 | 166 |
UIntFile m_fileDelay; ///< file for initial delay in ms per frame |
164 | 167 |
UIntFile m_fileDropDelay; ///< file for delay while dropping (ms / frame) |
168 |
+ UIntFile m_fileBlinkDelay; ///< file for delay while blinking (ms / frame) |
|
165 | 169 |
|
166 | 170 |
NameFile m_fileStartSound; ///< "start game" sound name file |
167 | 171 |
|
168 | 172 |
ColorData m_stoneColor; ///< stone color |
169 | 173 |
unsigned int m_delay; ///< initial delay in ms per frame |
170 | 174 |
unsigned int m_dropDelay; ///< delay while dropping in ms per frame |
175 |
+ unsigned int m_blinkDelay; ///< delay while rwos blinking in ms per frame |
|
171 | 176 |
|
172 | 177 |
OpConn *m_pConn; ///< operator connection of player (or NULL) |
173 | 178 |
|
... | ... |
@@ -176,9 +181,12 @@ protected: |
176 | 181 |
int m_posX; ///< x position of current stone |
177 | 182 |
int m_posY; ///< y position of current stone |
178 | 183 |
bool m_dropping; ///< whether currently dropping a stone |
184 |
+ int m_blinking; ///< step of blinking: 0 not blinking |
|
179 | 185 |
|
180 | 186 |
/// tetris field (y * m_width + x), -1 for free, >= 0 for pixel from stone |
181 | 187 |
std::vector<int> m_field; |
188 |
+ /// sorted y indices of rows that are currently blinking |
|
189 |
+ std::vector<int> m_rowsBlink; |
|
182 | 190 |
}; // class Tetris |
183 | 191 |
|
184 | 192 |
} // namespace Blinker |
185 | 193 |