Код: Выделить всё
#include
#include
#include
#include
#include
#include
using namespace sf;
using namespace std;
float blockWidth = 400.f; // Width of the block
float blockHeight = 200.f; // Height of the block
float indentSize = 30.f; // Indent size for both depth and length
//Function to map string keys to SFML keyboard keys
Keyboard::Key getKeyFromString(string& keyName) {
if (keyName.length() == 1) {
char c = keyName[0];
if (isalpha(c)) return static_cast(toupper(c) - 'A'); // A-Z
if (isdigit(c)) return static_cast(Keyboard::Num0 + (c - '0')); // 0-9
}
if (keyName[0] == 'F' && keyName.length() >= 2) {
int fn = stoi(keyName.substr(1));
if (fn >= 1 && fn second : Keyboard::Unknown;
}
// Function to create a convex shape similar to Scratch blocks
ConvexShape createScratchBlock(Color blockColor) {
ConvexShape block;
block.setPointCount(12);
// Top left corner
block.setPoint(0, Vector2f(0, 0));
// Top indent inwards
block.setPoint(1, Vector2f(blockWidth / 4 - indentSize, 0));
block.setPoint(2, Vector2f(blockWidth / 4, indentSize));
block.setPoint(3, Vector2f(blockWidth / 2 - indentSize, indentSize));
block.setPoint(4, Vector2f(blockWidth / 2, 0));
block.setPoint(5, Vector2f(blockWidth, 0));
// Bottom right corner
block.setPoint(6, Vector2f(blockWidth, blockHeight));
// Bottom indent inwards
block.setPoint(7, Vector2f(blockWidth / 2, blockHeight));
block.setPoint(8, Vector2f(blockWidth / 2 - indentSize, blockHeight - indentSize));
block.setPoint(9, Vector2f(blockWidth / 4, blockHeight - indentSize));
block.setPoint(10, Vector2f(blockWidth / 4 - indentSize, blockHeight));
block.setPoint(11, Vector2f(0, blockHeight));
block.setFillColor(blockColor);
return block;
}
int main() {
RenderWindow window(VideoMode(800, 600), "SFML Text Example"); // Create SFML window
Font font;
// Font loading error handling
if (!font.loadFromFile("OldLondon.ttf")) {
cerr
Подробнее здесь: [url]https://stackoverflow.com/questions/78992155/why-does-my-sfml-code-keep-crashing-even-after-ive-made-sure-ive-installed-it[/url]