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 zcmeAS@N?(olHy`uVBq!ia0y~yV3@$bz#zcE#=yYv^V_!s1_lPk;vjb?hIQv;UNSH+ zyz_K%49RGGJJXx*kO7Yi=PTC)PN6&hB@_-$l4A{vOE~$-T-D`s*xE^%xvDd*GIz`P zy_aR^`TZ+rTHWt^jSV{^Up)F&HG}2)#lU z(%Fo+I|E}y?@fJiHT0>ttomxd)e|2&D73zC2(1Wb3;l2Md2^reRd1`aiHmk=T>TmO zJJ_y3VZx%_%!ON~p4h+h-rXbXv-Q?)n{Y0C(euJ?MwPUZGZ`03`$i2mLugbkG&$d~7+;SFQAES%fTF2;B10o0Ay?uNrRpkoKvz@>-DB!poP!+B;sE&V9-e7(3<7Pr(8ng-dr0 zEv}t<_+9JXtE%_2j@{aQQqc0^?un7dpE)M^Ce;0fG>n{^+@2x1Te%zGI zF!7iEf3Hp7-^Km$np41|&~$`B$%9AX6JxG>{l* _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++; }