From b20a58b7d334bcfca279f2b2ca8938bdce559abb Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Mon, 7 Mar 2022 20:18:08 -0800 Subject: [PATCH] Add thousands comma, prevent tiles and blocks counters from counting on reset --- res/numerals.png | Bin 291 -> 308 bytes src/Main.cpp | 26 ++++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/res/numerals.png b/res/numerals.png index f3b9a9dfab44278e501868d443d11c280eed00a4..cbb190cdf2837d73e8aeaba5dfab0bfc5013ff5e 100644 GIT binary patch literal 308 zcmV-40n7f0P)Px#?ny*JRA_P27)65Rh7AiSdYA;)$LXhbF=Y`9_Oe!4LA@;u}BTl%Jm}6 zXzjUCT@~Jy=+#x_7ab?7POFjOKp=(aKvj5G237ww^Rtc<)k`|fVWPSy)%jWbQ$BDY zkfOT-akQ1lzq#Js#II{Et+tTPSEA=})>_7!pEVvh5J(|9P_NyNwMN)#w^jYVQRA+v zmH0Tpfk28j%fGPd+M*Z#5~me75J<84E)2{8IVl_nr1$_sY>l&(=lzuc0000VB; literal 291 zcmV+;0o?wHP)Px#-AP12RA_ijrq zy&li+0s!N%cK~2aCVIHN9!-MzbXmP~oz))gcWXSO$2pn~jsZj_twCF9UU=pbR=-hQ z7TWk(x~%y{zmuhdV*nA=F|zPx@_l*MQc9uI(pHCv>NTC^2vJ>>?D-LJ3?S0oF*w%B z;rA-u>U!^*#@f5d5joNOq}Ce4J3lxE5K$eYSM}ez2Y>7Ikv-n1aeL!}V*ru*FaJui p_wHW&N}O;EAcDjIB1jA%@&Ro}f3dg>vwr{p002ovPDHLkV1nTce60Wg diff --git a/src/Main.cpp b/src/Main.cpp index 06e9c0d..73dd4d2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -30,13 +30,16 @@ class NumberRenderer { public: - sf::IntRect numeral_rects[10]; sf::Texture texture; + sf::IntRect comma_rect; + sf::IntRect numeral_rects[10]; NumberRenderer( sf::Texture _texture, + sf::IntRect _comma_rect, std::initializer_list _numeral_rects ) { texture = _texture; + comma_rect = _comma_rect; sprite = sf::Sprite(texture); int i = 0; for (auto numeral_rect = _numeral_rects.begin(); numeral_rect != _numeral_rects.end(); ++numeral_rect) { @@ -50,15 +53,26 @@ class NumberRenderer { numeral_string.push_back(number_string.back()); auto numeral_rect = numeral_rects[std::stoi(numeral_string)]; int x_offset = -numeral_rect.width; - for (int i = number_string.length() - 1; i >= 0; i--) { - char numeral_string[] = {number_string[i]}; // stoi requires string (char[]) not char + uint digits = number_string.length(); + for (int i = digits - 1; i >= 0; i--) { + char numeral_string[] = {number_string[i]}; auto numeral_rect = numeral_rects[std::stoi(numeral_string)]; + if ((digits - i) % 3 == 1 && i != digits - 1) { + sprite.setTextureRect(comma_rect); + sprite.setPosition(x + x_offset, y); + window->draw(sprite); + x_offset -= numeral_rect.width; + } sprite.setTextureRect(numeral_rect); sprite.setPosition(x + x_offset, y); window->draw(sprite); if (i == 0) { break; } + if ((digits - i) % 3 == 0) { + x_offset -= comma_rect.width; + continue; + } numeral_string[0] = number_string[i - 1]; numeral_rect = numeral_rects[std::stoi(numeral_string)]; x_offset -= numeral_rect.width; @@ -239,7 +253,7 @@ int main() sf::Texture numeral_texture; numeral_texture.loadFromFile("../res/numerals.png"); - NumberRenderer number_renderer(numeral_texture, { + NumberRenderer number_renderer(numeral_texture, sf::IntRect(134, 0, 10, 16), { sf::IntRect(0, 0, 14, 16), sf::IntRect(14, 0, 8, 16), sf::IntRect(22, 0, 14, 16), @@ -403,6 +417,8 @@ int main() } } } else { + tiles += block.get_tiles().size(); + blocks++; for (auto tile : block.get_tiles()) { grid[tile.y][tile.x] = block.type->tile_type; } @@ -428,8 +444,6 @@ int main() } } block = Block(); - tiles += block.get_tiles().size(); - blocks++; } else if(is_update_frame) { block.position.y++; }