|
|
@ -14,6 +14,7 @@ |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "dbc.hpp" |
|
|
|
|
|
|
|
#include "constants.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using namespace nlohmann; |
|
|
|
using namespace nlohmann; |
|
|
|
using std::string, std::make_shared; |
|
|
|
using std::string, std::make_shared; |
|
|
@ -31,26 +32,10 @@ std::array<sf::Color, 10> VALUES{ |
|
|
|
sf::Color::Transparent, // white
|
|
|
|
sf::Color::Transparent, // white
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void SoundQuip::load(json &data, const char *file_key, bool loop) { |
|
|
|
SFMLBackend::SFMLBackend(GameEngine &g) |
|
|
|
buffer = make_shared<sf::SoundBuffer>(); |
|
|
|
: window(sf::VideoMode({X_DIM, Y_DIM}), "Turing's Tarpit"), |
|
|
|
|
|
|
|
game(g), current_face(textures::get("building")) |
|
|
|
auto audio = data["audio"]; |
|
|
|
{ |
|
|
|
json::string_t file_name = audio[file_key].template get<string>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!buffer->loadFromFile(file_name)) { |
|
|
|
|
|
|
|
fmt::println("Failed to load sound: {} with file {}", file_key, file_name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sound = make_shared<sf::Sound>(*buffer); |
|
|
|
|
|
|
|
sound->setLooping(loop); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SoundQuip::play() { |
|
|
|
|
|
|
|
sound->play(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SoundQuip::stop() { |
|
|
|
|
|
|
|
sound->stop(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::Window_update() { |
|
|
|
void SFMLBackend::Window_update() { |
|
|
@ -107,8 +92,8 @@ void SFMLBackend::update_entities() { |
|
|
|
window.clear(); |
|
|
|
window.clear(); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2, Value::DARK_DARK); |
|
|
|
sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2, Value::DARK_DARK); |
|
|
|
face_sprite->setPosition(translate(2,2)); |
|
|
|
current_face.sprite->setPosition(translate(2,2)); |
|
|
|
window.draw(*face_sprite); |
|
|
|
window.draw(*current_face.sprite); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape stats_box = box(X_ROWS/4 + 4, 2, |
|
|
|
sf::RectangleShape stats_box = box(X_ROWS/4 + 4, 2, |
|
|
|
X_ROWS - X_ROWS/4 - 5, Y_LINES/2, Value::DARK_DARK); |
|
|
|
X_ROWS - X_ROWS/4 - 5, Y_LINES/2, Value::DARK_DARK); |
|
|
@ -139,28 +124,8 @@ void SFMLBackend::update_entities() { |
|
|
|
Window_update(); |
|
|
|
Window_update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::change_face(const string name) { |
|
|
|
void SFMLBackend::change_face(const string& name) { |
|
|
|
std::ifstream infile(".tarpit.json"); |
|
|
|
current_face = textures::get(name); |
|
|
|
json data = json::parse(infile); |
|
|
|
|
|
|
|
auto images = data["images"]; |
|
|
|
|
|
|
|
json::string_t file_name = images[name].template get<string>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool good = face_texture->loadFromFile(file_name); |
|
|
|
|
|
|
|
dbc::check(good, fmt::format("failed to load texture {}", file_name)); |
|
|
|
|
|
|
|
face_sprite->setTexture(*face_texture); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SFMLBackend::SFMLBackend(GameEngine &g) |
|
|
|
|
|
|
|
: window(sf::VideoMode({X_DIM, Y_DIM}), "Turing's Tarpit"), |
|
|
|
|
|
|
|
game(g) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::ifstream infile(".tarpit.json"); |
|
|
|
|
|
|
|
json data = json::parse(infile); |
|
|
|
|
|
|
|
auto images = data["images"]; |
|
|
|
|
|
|
|
std::string build_name = images["building"]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face_texture = make_shared<sf::Texture>(build_name); |
|
|
|
|
|
|
|
face_sprite = make_shared<sf::Sprite>(*face_texture); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -179,11 +144,7 @@ void SFMLBackend::update_log(std::vector<string> &lines) { |
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::startup() { |
|
|
|
void SFMLBackend::startup() { |
|
|
|
fmt::print("Setting up a window for you...\n"); |
|
|
|
fmt::print("Setting up a window for you...\n"); |
|
|
|
std::ifstream infile(".tarpit.json"); |
|
|
|
if(!font.openFromFile(FONT_FILE_NAME)) { |
|
|
|
json data = json::parse(infile); |
|
|
|
|
|
|
|
std::string font_file = data["font"]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!font.openFromFile(font_file)) { |
|
|
|
|
|
|
|
fmt::println("Cannot load font."); |
|
|
|
fmt::println("Cannot load font."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|