Add scorekeeping

cpp
Elnu 3 years ago
parent 13932a45e8
commit b3f7e3789a

Binary file not shown.

@ -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.

@ -0,0 +1,10 @@
U+0030
U+0031
U+0032
U+0033
U+0034
U+0035
U+0036
U+0037
U+0038
U+0039

@ -0,0 +1,3 @@
#!/bin/bash
# https://stackoverflow.com/a/14779443
pyftsubset AnonymousPro-Regular.ttf --output-file=../res/font.ttf --unicodes-file=chars.txt

Binary file not shown.

@ -1,11 +1,13 @@
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/System/Clock.hpp> #include <SFML/System/Clock.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp> #include <SFML/Window/Keyboard.hpp>
#include <iostream> #include <iostream>
#include <string>
#define WINDOW_WIDTH 400 #define WINDOW_WIDTH 400
#define WINDOW_HEIGHT 800 #define WINDOW_HEIGHT 800
@ -158,6 +160,18 @@ int main()
sf::Clock update_clock; sf::Clock update_clock;
sf::Clock move_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()) while (window.isOpen())
{ {
sf::Event event; sf::Event event;
@ -309,6 +323,8 @@ int main()
grid[z + 1][x] = grid[z][x]; grid[z + 1][x] = grid[z][x];
} }
} }
score++;
text.setString(std::to_string(score));
} }
block = Block(); block = Block();
} else if(is_update_frame) { } else if(is_update_frame) {
@ -332,6 +348,7 @@ int main()
window.draw(shape); window.draw(shape);
} }
} }
window.draw(text);
window.display(); window.display();

Loading…
Cancel
Save