diff --git a/README.md b/README.md index d337b02..629b66f 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ A Tetris clone made in C++ and [SFML](https://www.sfml-dev.org/). -For build instructions, see the [build folder](build). +For build instructions, see the [build folder](build). \ No newline at end of file diff --git a/assets/AnonymousPro-Regular.ttf b/assets/AnonymousPro-Regular.ttf new file mode 100644 index 0000000..a98da85 Binary files /dev/null and b/assets/AnonymousPro-Regular.ttf differ diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000..80a2b22 --- /dev/null +++ b/assets/README.md @@ -0,0 +1,3 @@ +### Font + +[Anonymous Pro](https://fonts.google.com/specimen/Anonymous+Pro) by Mark Simonson is used for the score font. To optimize font size, [fonttools](https://github.com/fonttools/fonttools) is used to strip out all characters from the font besides the numerals 0-9. \ No newline at end of file diff --git a/assets/chars.txt b/assets/chars.txt new file mode 100644 index 0000000..4cae957 --- /dev/null +++ b/assets/chars.txt @@ -0,0 +1,10 @@ +U+0030 +U+0031 +U+0032 +U+0033 +U+0034 +U+0035 +U+0036 +U+0037 +U+0038 +U+0039 diff --git a/assets/strip.sh b/assets/strip.sh new file mode 100755 index 0000000..671ee3b --- /dev/null +++ b/assets/strip.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# https://stackoverflow.com/a/14779443 +pyftsubset AnonymousPro-Regular.ttf --output-file=../res/font.ttf --unicodes-file=chars.txt \ No newline at end of file diff --git a/res/font.ttf b/res/font.ttf new file mode 100644 index 0000000..4549f39 Binary files /dev/null and b/res/font.ttf differ diff --git a/src/Main.cpp b/src/Main.cpp index f3883a2..dca39f2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,11 +1,13 @@ #include #include +#include #include #include #include #include #include +#include #define WINDOW_WIDTH 400 #define WINDOW_HEIGHT 800 @@ -158,6 +160,18 @@ int main() sf::Clock update_clock; sf::Clock move_clock; + int score = 0; + + sf::Font font; + font.loadFromFile("../res/stripped.ttf"); + + sf::Text text; + text.setFont(font); + text.setString("0"); + text.setCharacterSize(24); + text.setFillColor(sf::Color::White); + text.setPosition(8, 0); + while (window.isOpen()) { sf::Event event; @@ -309,6 +323,8 @@ int main() grid[z + 1][x] = grid[z][x]; } } + score++; + text.setString(std::to_string(score)); } block = Block(); } else if(is_update_frame) { @@ -332,6 +348,7 @@ int main() window.draw(shape); } } + window.draw(text); window.display();