| 1 | /* |
| 2 | =========================================================================== |
| 3 | blockattack - Block Attack - Rise of the Blocks |
| 4 | Copyright (C) 2005-2016 Poul Sander |
| 5 | |
| 6 | This program is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see http://www.gnu.org/licenses/ |
| 18 | |
| 19 | Source information and contacts persons can be found at |
| 20 | https://blockattack.net |
| 21 | =========================================================================== |
| 22 | */ |
| 23 | |
| 24 | #pragma once |
| 25 | |
| 26 | #include "BlockGame.hpp" |
| 27 | #include "global.hpp" |
| 28 | #include "sago/SagoTextField.hpp" |
| 29 | #include "BallManager.hpp" |
| 30 | #include "ExplosionManager.hpp" |
| 31 | #include "puzzlehandler.hpp" |
| 32 | |
| 33 | extern BallManager theBallManager; |
| 34 | |
| 35 | extern ExplosionManager theExplosionManager; |
| 36 | |
| 37 | |
| 38 | static void setScoreboardFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) { |
| 39 | field.SetHolder(holder); |
| 40 | field.SetFont("penguinattack"); |
| 41 | field.SetColor({255,255,255,255}); |
| 42 | field.SetFontSize(20); |
| 43 | field.SetText(text); |
| 44 | } |
| 45 | |
| 46 | static void setButtonFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) { |
| 47 | field.SetHolder(holder); |
| 48 | field.SetFont("freeserif"); |
| 49 | field.SetColor({255,255,255,255}); |
| 50 | field.SetFontSize(24); |
| 51 | field.SetOutline(1, {64,64,64,255}); |
| 52 | field.SetText(text); |
| 53 | } |
| 54 | |
| 55 | template <class T> void sagoTextSetHelpFont(T& field) { |
| 56 | field.SetHolder(&globalData.spriteHolder->GetDataHolder()); |
| 57 | field.SetFont("freeserif"); |
| 58 | field.SetFontSize(30); |
| 59 | field.SetOutline(1, {128,128,128,255}); |
| 60 | } |
| 61 | |
| 62 | class BlockGameSdl : public BlockGame { |
| 63 | public: |
| 64 | BlockGameSdl(int tx, int ty, const sago::SagoDataHolder* holder) { |
| 65 | topx = tx; |
| 66 | topy = ty; |
| 67 | setScoreboardFont(holder, scoreLabel, _("Score:")); |
| 68 | setScoreboardFont(holder, timeLabel, _("Time:")); |
| 69 | setScoreboardFont(holder, chainLabel, _("Chain:")); |
| 70 | setScoreboardFont(holder, speedLabel, _("Speed:")); |
| 71 | setButtonFont(holder, buttonNext, _("Next")); |
| 72 | setButtonFont(holder, buttonRetry, _("Retry")); |
| 73 | setButtonFont(holder, buttonSkip, _("Skip")); |
| 74 | setButtonFont(holder, stopIntField, ""); |
| 75 | |
| 76 | sagoTextSetBlueFont(player_name); |
| 77 | sagoTextSetBlueFont(player_time); |
| 78 | sagoTextSetBlueFont(player_score); |
| 79 | sagoTextSetBlueFont(player_chain); |
| 80 | sagoTextSetBlueFont(player_speed); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void DrawImgBoard(const sago::SagoSprite& img, int x, int y) const { |
| 85 | DrawIMG(img, globalData.screen, x+topx, y+topy); |
| 86 | } |
| 87 | |
| 88 | void DrawImgBoardBounded(const sago::SagoSprite& img, int x, int y) const { |
| 89 | DrawIMG_Bounded(img, globalData.screen, x+topx, y+topy, topx, topy, topx + BOARD_WIDTH, topy + BOARD_HEIGHT); |
| 90 | } |
| 91 | |
| 92 | void PrintTextCenteredBoard(int x, int y, sago::SagoTextField& field) { |
| 93 | field.Draw(globalData.screen, x+topx+60, y+topy+20, |
| 94 | sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::center, &globalData.logicalResize); |
| 95 | } |
| 96 | |
| 97 | void SetTopXY(int tx, int ty) { |
| 98 | topx = tx; |
| 99 | topy = ty; |
| 100 | } |
| 101 | |
| 102 | int GetTopX() const { |
| 103 | return topx; |
| 104 | } |
| 105 | int GetTopY() const { |
| 106 | return topy; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Retrives the coordinate to a given brick based on mouse input. |
| 111 | * @param match true if the coordinate are within borders |
| 112 | * @param mousex mouse coordinate input |
| 113 | * @param mousey mouse coordiante input |
| 114 | * @param x brick x. Unchanged if outside border |
| 115 | * @param y brick y. Unchanged if outside border |
| 116 | */ |
| 117 | void GetBrickCoordinateFromMouse(bool& match, int mousex, int mousey, int& x, int& y) const { |
| 118 | if (!IsInTheBoard(mousex, mousey)) { |
| 119 | match = false; |
| 120 | return; |
| 121 | } |
| 122 | match = true; |
| 123 | x = (mousex-topx) / bsize; |
| 124 | y = (bsize*12+topy-mousey-pixels) / bsize; |
| 125 | } |
| 126 | |
| 127 | bool IsInTheBoard(int mousex, int mousey) const { |
| 128 | if (mousex < topx || mousex > topx+bsize*6 || mousey < topy || mousey > topy+bsize*12) { |
| 129 | return false; |
| 130 | } |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | bool IsUnderTheBoard(int mousex, int mousey) const { |
| 135 | if (mousex < topx || mousex > topx+bsize*6 || mousey < topy+bsize*12) { |
| 136 | return false; |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | void AddText(int x, int y, unsigned int text, int time) const override { |
| 142 | globalData.theTextManager.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time); |
| 143 | } |
| 144 | |
| 145 | void AddBall(int x, int y, bool right, int color) const override { |
| 146 | theBallManager.addBall(topx+40+x*bsize, topy+bsize*12-y*bsize, right, color); |
| 147 | } |
| 148 | |
| 149 | void AddExplosion(int x, int y) const override { |
| 150 | theExplosionManager.addExplosion(topx-10+x*bsize, topy+bsize*12-10-y*bsize); |
| 151 | } |
| 152 | |
| 153 | void PlayerWonEvent() const override { |
| 154 | if (!globalData.SoundEnabled) { |
| 155 | return; |
| 156 | } |
| 157 | Mix_PlayChannel(1, globalData.applause.get(), 0); |
| 158 | } |
| 159 | |
| 160 | void DrawEvent() const override { |
| 161 | Mix_HaltChannel(1); |
| 162 | } |
| 163 | |
| 164 | void BlockPopEvent() const override { |
| 165 | if (!globalData.SoundEnabled) { |
| 166 | return; |
| 167 | } |
| 168 | Mix_PlayChannel(0, globalData.boing.get(), 0); |
| 169 | } |
| 170 | |
| 171 | void LongChainDoneEvent() const override { |
| 172 | if (!globalData.SoundEnabled) { |
| 173 | return; |
| 174 | } |
| 175 | Mix_PlayChannel(1, globalData.applause.get(), 0); |
| 176 | } |
| 177 | |
| 178 | void TimeTrialEndEvent() const override { |
| 179 | if (!globalData.NoSound && globalData.SoundEnabled) { |
| 180 | Mix_PlayChannel(1,globalData.counterFinalChunk.get(),0); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void EndlessHighscoreEvent() const override { |
| 185 | if (!globalData.SoundEnabled) { |
| 186 | return; |
| 187 | } |
| 188 | Mix_PlayChannel(1, globalData.applause.get(), 0); |
| 189 | } |
| 190 | private: |
| 191 | |
| 192 | /** |
| 193 | This crops "dstrect" and "srcrect" to fit inside "bounds" |
| 194 | dstrect and srcrect are modified in place. |
| 195 | */ |
| 196 | void CropTexture(SDL_Rect& dstrect, SDL_Rect& srcrect, const SDL_Rect& bounds) const { |
| 197 | if (dstrect.x > bounds.x+bounds.w) { |
| 198 | dstrect = {0,0,0,0}; |
| 199 | return; |
| 200 | } |
| 201 | if (dstrect.y > bounds.y+bounds.h) { |
| 202 | dstrect = {0,0,0,0}; |
| 203 | return; |
| 204 | } |
| 205 | if (dstrect.x+dstrect.w < bounds.x) { |
| 206 | dstrect = {0,0,0,0}; |
| 207 | return; |
| 208 | } |
| 209 | if (dstrect.y+dstrect.h < bounds.y) { |
| 210 | dstrect = {0,0,0,0}; |
| 211 | return; |
| 212 | } |
| 213 | if (dstrect.x < bounds.x) { |
| 214 | Sint16 absDiff = bounds.x-dstrect.x; |
| 215 | dstrect.x+=absDiff; |
| 216 | srcrect.x+=absDiff; |
| 217 | dstrect.w-=absDiff; |
| 218 | srcrect.w-=absDiff; |
| 219 | } |
| 220 | if (dstrect.y < bounds.y) { |
| 221 | Sint16 absDiff = bounds.y-dstrect.y; |
| 222 | dstrect.y+=absDiff; |
| 223 | srcrect.y+=absDiff; |
| 224 | dstrect.h-=absDiff; |
| 225 | srcrect.h-=absDiff; |
| 226 | } |
| 227 | if (dstrect.x+dstrect.w > bounds.x+bounds.w) { |
| 228 | Sint16 absDiff = dstrect.x+dstrect.w-(bounds.x+bounds.w); |
| 229 | dstrect.w -= absDiff; |
| 230 | srcrect.w -= absDiff; |
| 231 | } |
| 232 | if (dstrect.y+dstrect.h > bounds.y+bounds.h) { |
| 233 | Sint16 absDiff = dstrect.y+dstrect.h-(bounds.y+bounds.h); |
| 234 | dstrect.h -= absDiff; |
| 235 | srcrect.h -= absDiff; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | //Draws all the bricks to the board (including garbage) |
| 240 | void PaintBricks() const { |
| 241 | for (int i=0; i<13; ++i) { |
| 242 | for (int j=0; j<6; ++j) { |
| 243 | int basicBrick = board[j][i]%10; //The basic brick, stored on the least significant digit |
| 244 | if ((basicBrick > -1) && (basicBrick < 7) && ((board[j][i]/1000000)%10==0)) { |
| 245 | DrawImgBoardBounded(globalData.bricks[basicBrick], j*bsize, bsize*12-i*bsize-pixels); |
| 246 | if ((board[j][i]/BLOCKWAIT)%10==1) { |
| 247 | DrawImgBoard(globalData.bomb, j*bsize, bsize*12-i*bsize-pixels); |
| 248 | } |
| 249 | if ((board[j][i]/BLOCKHANG)%10==1) { |
| 250 | DrawImgBoardBounded(globalData.ready, j*bsize, bsize*12-i*bsize-pixels); |
| 251 | } |
| 252 | |
| 253 | } |
| 254 | if ((board[j][i]/1000000)%10==1) { |
| 255 | int left, right, over, under; |
| 256 | int number = board[j][i]; |
| 257 | if (j<1) { |
| 258 | left = -1; |
| 259 | } |
| 260 | else { |
| 261 | left = board[j-1][i]; |
| 262 | } |
| 263 | if (j>=5) { |
| 264 | right = -1; |
| 265 | } |
| 266 | else { |
| 267 | right = board[j+1][i]; |
| 268 | } |
| 269 | if (i>28) { |
| 270 | over = -1; |
| 271 | } |
| 272 | else { |
| 273 | over = board[j][i+1]; |
| 274 | } |
| 275 | if (i<1) { |
| 276 | under = -1; |
| 277 | } |
| 278 | else { |
| 279 | under = board[j][i-1]; |
| 280 | } |
| 281 | if ((left == number)&&(right == number)&&(over == number)&&(under == number)) { |
| 282 | DrawImgBoardBounded(globalData.garbageFill, j*bsize, bsize*12-i*bsize-pixels); |
| 283 | } |
| 284 | if ((left != number)&&(right == number)&&(over == number)&&(under == number)) { |
| 285 | DrawImgBoardBounded(globalData.garbageL, j*bsize, bsize*12-i*bsize-pixels); |
| 286 | } |
| 287 | if ((left == number)&&(right != number)&&(over == number)&&(under == number)) { |
| 288 | DrawImgBoardBounded(globalData.garbageR, j*bsize, bsize*12-i*bsize-pixels); |
| 289 | } |
| 290 | if ((left == number)&&(right == number)&&(over != number)&&(under == number)) { |
| 291 | DrawImgBoardBounded(globalData.garbageT, j*bsize, bsize*12-i*bsize-pixels); |
| 292 | } |
| 293 | if ((left == number)&&(right == number)&&(over == number)&&(under != number)) { |
| 294 | DrawImgBoardBounded(globalData.garbageB, j*bsize, bsize*12-i*bsize-pixels); |
| 295 | } |
| 296 | if ((left != number)&&(right == number)&&(over != number)&&(under == number)) { |
| 297 | DrawImgBoardBounded(globalData.garbageTL, j*bsize, bsize*12-i*bsize-pixels); |
| 298 | } |
| 299 | if ((left != number)&&(right == number)&&(over == number)&&(under != number)) { |
| 300 | DrawImgBoardBounded(globalData.garbageBL, j*bsize, bsize*12-i*bsize-pixels); |
| 301 | } |
| 302 | if ((left == number)&&(right != number)&&(over != number)&&(under == number)) { |
| 303 | DrawImgBoardBounded(globalData.garbageTR, j*bsize, bsize*12-i*bsize-pixels); |
| 304 | } |
| 305 | if ((left == number)&&(right != number)&&(over == number)&&(under != number)) { |
| 306 | DrawImgBoardBounded(globalData.garbageBR, j*bsize, bsize*12-i*bsize-pixels); |
| 307 | } |
| 308 | if ((left == number)&&(right != number)&&(over != number)&&(under != number)) { |
| 309 | DrawImgBoardBounded(globalData.garbageMR, j*bsize, bsize*12-i*bsize-pixels); |
| 310 | } |
| 311 | if ((left == number)&&(right == number)&&(over != number)&&(under != number)) { |
| 312 | DrawImgBoardBounded(globalData.garbageM, j*bsize, bsize*12-i*bsize-pixels); |
| 313 | } |
| 314 | if ((left != number)&&(right == number)&&(over != number)&&(under != number)) { |
| 315 | DrawImgBoardBounded(globalData.garbageML, j*bsize, bsize*12-i*bsize-pixels); |
| 316 | } |
| 317 | } |
| 318 | if ((board[j][i]/1000000)%10==2) { |
| 319 | if (j==0) { |
| 320 | DrawImgBoardBounded(globalData.garbageGML, j*bsize, bsize*12-i*bsize-pixels); |
| 321 | } |
| 322 | else if (j==5) { |
| 323 | DrawImgBoardBounded(globalData.garbageGMR, j*bsize, bsize*12-i*bsize-pixels); |
| 324 | } |
| 325 | else { |
| 326 | DrawImgBoardBounded(globalData.garbageGM, j*bsize, bsize*12-i*bsize-pixels); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | const int j = 0; |
| 332 | |
| 333 | int garbageSize=0; |
| 334 | for (int i=0; i<20; i++) { |
| 335 | if ((board[j][i]/1000000)%10==1) { |
| 336 | int left, right, over, under; |
| 337 | int number = board[j][i]; |
| 338 | left = -1; |
| 339 | right = board[j+1][i]; |
| 340 | if (i>28) { |
| 341 | over = -1; |
| 342 | } |
| 343 | else { |
| 344 | over = board[j][i+1]; |
| 345 | } |
| 346 | if (i<1) { |
| 347 | under = -1; |
| 348 | } |
| 349 | else { |
| 350 | under = board[j][i-1]; |
| 351 | } |
| 352 | if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) { |
| 353 | if (globalData.theme.decoration.decoration_sprites.size()) { |
| 354 | const sago::SagoSprite& sprite = globalData.spriteHolder->GetSprite(globalData.theme.decoration.decoration_sprites[board[j][i]%globalData.theme.decoration.decoration_sprites.size()]); |
| 355 | DrawImgBoardBounded(sprite, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize); |
| 356 | } |
| 357 | } |
| 358 | if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) { //not in garbage |
| 359 | garbageSize=0; |
| 360 | } |
| 361 | else { |
| 362 | garbageSize++; |
| 363 | } |
| 364 | |
| 365 | } |
| 366 | } |
| 367 | for (int i=0; i<6; i++) { |
| 368 | if (board[i][0]!=-1) { |
| 369 | DrawImgBoardBounded(globalData.transCover, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | } |
| 374 | public: |
| 375 | //Draws everything |
| 376 | void DoPaintJob() { |
| 377 | const ThemeBorderData& border = globalData.theme.border; |
| 378 | sago::SagoSprite backback = globalData.spriteHolder->GetSprite(border.border_sprite); |
| 379 | DrawIMG(backback, globalData.screen, this->GetTopX()+border.border_sprite_offset.first, this->GetTopY()+border.border_sprite_offset.second); |
| 380 | |
| 381 | this->scoreLabel.Draw(globalData.screen, this->GetTopX()+border.score_label_offset.first,this->GetTopY()+border.score_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 382 | this->timeLabel.Draw(globalData.screen, this->GetTopX()+border.time_label_offset.first,this->GetTopY()+border.time_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 383 | this->chainLabel.Draw(globalData.screen, this->GetTopX()+border.chain_label_offset.first,this->GetTopY()+border.chain_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 384 | this->speedLabel.Draw(globalData.screen, this->GetTopX()+border.speed_label_offset.first,this->GetTopY()+border.speed_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 385 | globalData.spriteHolder->GetSprite(globalData.theme.back_board).DrawScaled(globalData.screen, SDL_GetTicks(), this->GetTopX(),this->GetTopY(), BOARD_WIDTH, BOARD_HEIGHT, &globalData.logicalResize); |
| 386 | |
| 387 | PaintBricks(); |
| 388 | if (stageClear) { |
| 389 | DrawImgBoard(globalData.blackLine, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1); |
| 390 | } |
| 391 | if (puzzleMode&&(!bGameOver)) { |
| 392 | //We need to write nr. of moves left! |
| 393 | strHolder = _("Moves left: ") + std::to_string(MovesLeft); |
| 394 | static sago::SagoTextField movesPuzzleLabel; |
| 395 | sagoTextSetHelpFont(movesPuzzleLabel); |
| 396 | movesPuzzleLabel.SetText(strHolder); |
| 397 | movesPuzzleLabel.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 398 | |
| 399 | } |
| 400 | if (puzzleMode && stageButtonStatus == SBpuzzleMode) { |
| 401 | DrawImgBoard(globalData.bRetry, globalData.cordRetryButton.x, globalData.cordRetryButton.y); |
| 402 | PrintTextCenteredBoard(globalData.cordRetryButton.x, globalData.cordRetryButton.y, buttonRetry); |
| 403 | if (getLevel()<PuzzleGetNumberOfPuzzles()-1) { |
| 404 | if (hasWonTheGame) { |
| 405 | DrawImgBoard(globalData.bNext, globalData.cordNextButton.x, globalData.cordNextButton.y); |
| 406 | PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonNext); |
| 407 | } |
| 408 | else { |
| 409 | DrawImgBoard(globalData.bSkip, globalData.cordNextButton.x, globalData.cordNextButton.y); |
| 410 | PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonSkip); |
| 411 | } |
| 412 | } |
| 413 | else { |
| 414 | static sago::SagoTextField lastPuzzleLabel; |
| 415 | sagoTextSetHelpFont(lastPuzzleLabel); |
| 416 | lastPuzzleLabel.SetText(_("Last puzzle")); |
| 417 | lastPuzzleLabel.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 418 | } |
| 419 | } |
| 420 | if (stageClear && stageButtonStatus == SBstageClear) { |
| 421 | DrawImgBoard(globalData.bRetry, globalData.cordRetryButton.x, globalData.cordRetryButton.y); |
| 422 | PrintTextCenteredBoard(globalData.cordRetryButton.x, globalData.cordRetryButton.y, buttonRetry); |
| 423 | if (getLevel()<50-1) { |
| 424 | if (hasWonTheGame) { |
| 425 | DrawImgBoard(globalData.bNext, globalData.cordNextButton.x, globalData.cordNextButton.y); |
| 426 | PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonNext); |
| 427 | } |
| 428 | else { |
| 429 | DrawImgBoard(globalData.bSkip, globalData.cordNextButton.x, globalData.cordNextButton.y); |
| 430 | PrintTextCenteredBoard(globalData.cordNextButton.x, globalData.cordNextButton.y, buttonSkip); |
| 431 | } |
| 432 | } |
| 433 | else { |
| 434 | static sago::SagoTextField lastStageLabel; |
| 435 | sagoTextSetHelpFont(lastStageLabel); |
| 436 | lastStageLabel.SetText(_("Last stage")); |
| 437 | lastStageLabel.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 438 | } |
| 439 | } |
| 440 | if (!bGameOver && stop > 20) { |
| 441 | stopIntField.SetText(std::to_string(stop/10)); |
| 442 | stopIntField.Draw(globalData.screen, 240+topx, -40+topy, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 443 | } |
| 444 | |
| 445 | #if DEBUG |
| 446 | if (AI_Enabled&&(!bGameOver)) { |
| 447 | sagoTextSetBlueFont(aiStatusField); |
| 448 | strHolder = "AI_status: " + std::to_string(AIstatus)+ ", "+ std::to_string(AIlineToClear); |
| 449 | aiStatusField.SetText(strHolder); |
| 450 | aiStatusField.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 451 | } |
| 452 | #endif |
| 453 | if (!bGameOver) { |
| 454 | bool touched = false; |
| 455 | int mx = 0; |
| 456 | int my = 0; |
| 457 | this->GetMouseCursor(touched, mx, my); |
| 458 | if (touched) { |
| 459 | DrawImgBoard(globalData.spriteHolder->GetSprite("touchcursor"),mx*bsize, 11*bsize-my*bsize-pixels); |
| 460 | } |
| 461 | else { |
| 462 | DrawImgBoard(globalData.cursor,cursorx*bsize,11*bsize-cursory*bsize-pixels); |
| 463 | } |
| 464 | } |
| 465 | if (ticks<gameStartedAt) { |
| 466 | int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000; |
| 467 | if ( (currentCounter!=lastCounter) && (globalData.SoundEnabled)&&(!globalData.NoSound)) { |
| 468 | Mix_PlayChannel(1, globalData.counterChunk.get(), 0); |
| 469 | } |
| 470 | lastCounter = currentCounter; |
| 471 | switch (currentCounter) { |
| 472 | case 2: |
| 473 | DrawImgBoard(globalData.counter[2], 2*bsize, 5*bsize); |
| 474 | break; |
| 475 | case 1: |
| 476 | DrawImgBoard(globalData.counter[1], 2*bsize, 5*bsize); |
| 477 | break; |
| 478 | case 0: |
| 479 | DrawImgBoard(globalData.counter[0], 2*bsize, 5*bsize); |
| 480 | break; |
| 481 | default: |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | else { |
| 486 | if (globalData.SoundEnabled&&(!globalData.NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver)) { |
| 487 | int currentCounter = (ticks-(int)gameStartedAt)/1000; |
| 488 | if (currentCounter!=lastCounter) { |
| 489 | if (currentCounter>115 && currentCounter<120) { |
| 490 | Mix_PlayChannel(1, globalData.counterChunk.get(), 0); |
| 491 | } |
| 492 | } |
| 493 | lastCounter = currentCounter; |
| 494 | } |
| 495 | else { |
| 496 | if ( (0==lastCounter) && (globalData.SoundEnabled)&&(!globalData.NoSound)) { |
| 497 | Mix_PlayChannel(1, globalData.counterFinalChunk.get(), 0); |
| 498 | } |
| 499 | lastCounter = -1; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | if (bGameOver) { |
| 504 | if (hasWonTheGame) { |
| 505 | globalData.tbWinner.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center, &globalData.logicalResize); |
| 506 | } |
| 507 | else { |
| 508 | if (bDraw) { |
| 509 | globalData.tbDraw.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center, &globalData.logicalResize); |
| 510 | } |
| 511 | else { |
| 512 | if (this->infostring.empty()) { |
| 513 | globalData.tbGameOver.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center, &globalData.logicalResize); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | std::string strHolder; |
| 520 | strHolder = std::to_string(this->GetScore()+this->GetHandicap()); |
| 521 | player_score.SetText(strHolder); |
| 522 | player_score.Draw(globalData.screen, this->GetTopX()+border.score_label_offset.first,this->GetTopY()+border.score_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 523 | if (this->GetAIenabled()) { |
| 524 | player_name.SetText(_("AI")); |
| 525 | } |
| 526 | else { |
| 527 | player_name.SetText(name); |
| 528 | } |
| 529 | player_name.Draw(globalData.screen, this->GetTopX()+10,this->GetTopY()-34, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 530 | if (this->isTimeTrial()) { |
| 531 | int tid = (int)SDL_GetTicks()-this->GetGameStartedAt(); |
| 532 | int minutes; |
| 533 | int seconds; |
| 534 | if (tid>=0) { |
| 535 | minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))/60/1000; |
| 536 | seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))%(60*1000))/1000; |
| 537 | } |
| 538 | else { |
| 539 | minutes = ((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))/60/1000; |
| 540 | seconds = (((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))%(60*1000))/1000; |
| 541 | } |
| 542 | if (this->isGameOver()) { |
| 543 | minutes=0; |
| 544 | } |
| 545 | if (this->isGameOver()) { |
| 546 | seconds=0; |
| 547 | } |
| 548 | if (seconds>9) { |
| 549 | strHolder = std::to_string(minutes)+":"+std::to_string(seconds); |
| 550 | } |
| 551 | else { |
| 552 | strHolder = std::to_string(minutes)+":0"+std::to_string(seconds); |
| 553 | } |
| 554 | player_time.SetText(strHolder); |
| 555 | } |
| 556 | else { |
| 557 | int minutes = ((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))/60/1000; |
| 558 | int seconds = (((abs((int)SDL_GetTicks()-(int)this->GetGameStartedAt())))%(60*1000))/1000; |
| 559 | if (this->isGameOver()) { |
| 560 | minutes=(this->GetGameEndedAt()/1000/60)%100; |
| 561 | } |
| 562 | if (this->isGameOver()) { |
| 563 | seconds=(this->GetGameEndedAt()/1000)%60; |
| 564 | } |
| 565 | if (seconds>9) { |
| 566 | strHolder = std::to_string(minutes)+":"+std::to_string(seconds); |
| 567 | } |
| 568 | else { |
| 569 | strHolder = std::to_string(minutes)+":0"+std::to_string(seconds); |
| 570 | } |
| 571 | player_time.SetText(strHolder); |
| 572 | } |
| 573 | player_time.Draw(globalData.screen, this->GetTopX()+border.time_label_offset.first,this->GetTopY()+border.time_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 574 | strHolder = std::to_string(this->GetChains()); |
| 575 | player_chain.SetText(strHolder); |
| 576 | player_chain.Draw(globalData.screen, this->GetTopX()+border.chain_label_offset.first,this->GetTopY()+border.chain_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 577 | //drawspeedLevel: |
| 578 | strHolder = std::to_string(this->GetSpeedLevel()); |
| 579 | player_speed.SetText(strHolder); |
| 580 | player_speed.Draw(globalData.screen, this->GetTopX()+border.speed_label_offset.first,this->GetTopY()+border.speed_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 581 | if ((this->isStageClear()) &&(this->GetTopY()+700+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1<600+this->GetTopY())) { |
| 582 | oldBubleX = this->GetTopX()+280; |
| 583 | oldBubleY = this->GetTopY()+650+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1; |
| 584 | DrawIMG(globalData.stageBobble,globalData.screen,this->GetTopX()+280,this->GetTopY()+650+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1); |
| 585 | } |
| 586 | |
| 587 | if (infostring.length() > 0) { |
| 588 | static sago::SagoTextBox infoBox; |
| 589 | static sago::SagoTextField objectiveField; |
| 590 | static sago::SagoTextField gametypeNameField; |
| 591 | sagoTextSetHelpFont(infoBox); |
| 592 | infoBox.SetMaxWidth(290); |
| 593 | infoBox.SetText(infostring); |
| 594 | sagoTextSetHelpFont(objectiveField); |
| 595 | objectiveField.SetText(_("Objective:")); |
| 596 | sagoTextSetHelpFont(gametypeNameField); |
| 597 | gametypeNameField.SetText(infostringName); |
| 598 | gametypeNameField.Draw(globalData.screen, this->GetTopX()+7,this->GetTopY()+10, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 599 | objectiveField.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 600 | infoBox.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160+32, sago::SagoTextField::Alignment::left, &globalData.logicalResize); |
| 601 | |
| 602 | int y = this->GetTopY()+400; |
| 603 | static sago::SagoTextBox controldBox; |
| 604 | controldBox.SetHolder(&globalData.spriteHolder->GetDataHolder()); |
| 605 | sagoTextSetHelpFont(controldBox); |
| 606 | controldBox.SetMaxWidth(290); |
| 607 | controldBox.SetText(controldBoxText); |
| 608 | controldBox.Draw(globalData.screen, this->GetTopX()+7,y, sago::SagoTextField::Alignment::left, &globalData.logicalResize); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | sago::SagoTextField player_name; |
| 613 | sago::SagoTextField player_time; |
| 614 | sago::SagoTextField player_score; |
| 615 | sago::SagoTextField player_chain; |
| 616 | sago::SagoTextField player_speed; |
| 617 | |
| 618 | //Old Stage Clear Buble |
| 619 | int oldBubleX = 0; |
| 620 | int oldBubleY = 0; |
| 621 | |
| 622 | std::string infostring; |
| 623 | std::string infostringName; |
| 624 | std::string controldBoxText; |
| 625 | |
| 626 | |
| 627 | private: |
| 628 | int topx = 0; |
| 629 | int topy = 0; |
| 630 | sago::SagoTextField scoreLabel; |
| 631 | sago::SagoTextField timeLabel; |
| 632 | sago::SagoTextField chainLabel; |
| 633 | sago::SagoTextField speedLabel; |
| 634 | sago::SagoTextField buttonSkip; |
| 635 | sago::SagoTextField buttonRetry; |
| 636 | sago::SagoTextField buttonNext; |
| 637 | sago::SagoTextField stopIntField; |
| 638 | #if DEBUG |
| 639 | sago::SagoTextField aiStatusField; |
| 640 | #endif |
| 641 | }; |
| 642 | |
| 643 |