|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
#define _USE_MATH_DEFINES |
|
|
|
|
#include <math.h> |
|
|
|
|
#include <fmt/core.h> |
|
|
|
|
#include <chrono> |
|
|
|
|
#include <fmt/chrono.h> |
|
|
|
|
#include <SFML/Graphics/Texture.hpp> |
|
|
|
|
#include <SFML/Graphics/RectangleShape.hpp> |
|
|
|
@ -70,13 +71,9 @@ void SFMLBackend::handle_events() { |
|
|
|
|
break; |
|
|
|
|
case sf::Event::KeyPressed: |
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { |
|
|
|
|
if(show_build_log) { |
|
|
|
|
window_active_out = false; |
|
|
|
|
} else { |
|
|
|
|
window.close(); |
|
|
|
|
} |
|
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { |
|
|
|
|
window_active_out = !window_active_out; |
|
|
|
|
fmt::println("STOP THE CLOCK"); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case sf::Event::MouseButtonPressed: { |
|
|
|
@ -128,7 +125,7 @@ sf::RectangleShape SFMLBackend::box(int x, int y, int width, int height, |
|
|
|
|
void SFMLBackend::update_entities() { |
|
|
|
|
window.clear(); |
|
|
|
|
|
|
|
|
|
sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2); |
|
|
|
|
sf::RectangleShape face_box = box(2, 2, X_ROWS/4, Y_LINES/2, Value::DARK_DARK); |
|
|
|
|
face_sprite.setPosition(translate(2,2)); |
|
|
|
|
window.draw(face_sprite); |
|
|
|
|
|
|
|
|
@ -148,8 +145,8 @@ void SFMLBackend::update_entities() { |
|
|
|
|
game.streak, game.deaths); |
|
|
|
|
write_text(X_ROWS/4 + 5, 2, status); |
|
|
|
|
|
|
|
|
|
std::time_t t = std::time(nullptr); |
|
|
|
|
string time = fmt::format("{:%r}", fmt::localtime(t)); |
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); |
|
|
|
|
string time = fmt::format("{:%r}", now); |
|
|
|
|
write_text(2, 14, time, 2.0f); |
|
|
|
|
|
|
|
|
|
sf::RectangleShape start_btn = box(27, 16, 8, 3, Value::DARK_MID); |
|
|
|
@ -159,23 +156,28 @@ void SFMLBackend::update_entities() { |
|
|
|
|
write_text(39, 16, "DONE", 1.0f); |
|
|
|
|
|
|
|
|
|
Window_update(); |
|
|
|
|
|
|
|
|
|
show_build_log = window_active_out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) |
|
|
|
|
{ |
|
|
|
|
void SFMLBackend::change_face(const string name) { |
|
|
|
|
std::ifstream infile(".tarpit.json"); |
|
|
|
|
json data = json::parse(infile); |
|
|
|
|
auto audio = data["images"]; |
|
|
|
|
json::string_t file_name = audio["build_works"].template get<string>(); |
|
|
|
|
auto images = data["images"]; |
|
|
|
|
json::string_t file_name = images[name].template get<string>(); |
|
|
|
|
|
|
|
|
|
face_texture.loadFromFile(file_name); |
|
|
|
|
face_sprite.setTexture(face_texture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) |
|
|
|
|
{ |
|
|
|
|
change_face("building"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This makes my sould hurt. Make it stop. |
|
|
|
|
* This makes my soul hurt. Make it stop. |
|
|
|
|
* |
|
|
|
|
* TODO: Make this more efficient, and don't display |
|
|
|
|
* more than 10 or so errors since more than that is |
|
|
|
|