open font
This commit is contained in:
parent
cf7a9a1f1a
commit
91328c4aca
19
src/Game.cpp
19
src/Game.cpp
@ -1,11 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <sstream>
|
||||||
#include "Game.hpp"
|
#include "Game.hpp"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_ttf.h"
|
#include "SDL_ttf.h"
|
||||||
#include "words.hpp"
|
#include "words.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include "default_font.hpp"
|
||||||
|
|
||||||
const int CHAR_SIZE = 30;
|
const int CHAR_SIZE = 30;
|
||||||
const int STEP_SIZE = CHAR_SIZE + CHAR_SIZE / 2;
|
const int STEP_SIZE = CHAR_SIZE + CHAR_SIZE / 2;
|
||||||
@ -65,6 +67,23 @@ void Game::Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Game::Game() {
|
Game::Game() {
|
||||||
|
const char *defaultFontPath = getDefaultFontPath();
|
||||||
|
if (defaultFontPath == nullptr) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Font path is not set for this platform (null)";
|
||||||
|
auto s = ss.str();
|
||||||
|
std::cerr << s << std::endl;
|
||||||
|
throw std::runtime_error(s);
|
||||||
|
}
|
||||||
|
font = TTF_OpenFont(defaultFontPath, CHAR_SIZE);
|
||||||
|
if (font == nullptr) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Failed to load font: " << TTF_GetError();
|
||||||
|
auto s = ss.str();
|
||||||
|
std::cerr << s << std::endl;
|
||||||
|
throw std::runtime_error(s);
|
||||||
|
}
|
||||||
|
|
||||||
std::random_device random_device{};
|
std::random_device random_device{};
|
||||||
std::mt19937 rng(random_device());
|
std::mt19937 rng(random_device());
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL_rect.h>
|
|
||||||
#include <SDL_events.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <SDL_render.h>
|
#include "SDL_rect.h"
|
||||||
|
#include "SDL_events.h"
|
||||||
|
#include "SDL_render.h"
|
||||||
|
#include "SDL_ttf.h"
|
||||||
#include "GuessCorrector.hpp"
|
#include "GuessCorrector.hpp"
|
||||||
|
|
||||||
const SDL_Point SCREEN_SIZE{800, 800};
|
const SDL_Point SCREEN_SIZE{800, 800};
|
||||||
@ -14,6 +15,7 @@ private:
|
|||||||
std::vector<const char *> all_words;
|
std::vector<const char *> all_words;
|
||||||
std::unique_ptr<GuessCorrector> guess_corrector;
|
std::unique_ptr<GuessCorrector> guess_corrector;
|
||||||
const char *word;
|
const char *word;
|
||||||
|
const _TTF_Font *font;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Run();
|
static void Run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user