|
|
@ -1,8 +1,7 @@ |
|
|
|
#include "imgui.h" |
|
|
|
|
|
|
|
#include "imgui-SFML.h" |
|
|
|
|
|
|
|
#define _USE_MATH_DEFINES |
|
|
|
#define _USE_MATH_DEFINES |
|
|
|
#include <math.h> |
|
|
|
#include <math.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
|
|
|
|
#include <fmt/chrono.h> |
|
|
|
#include <SFML/Graphics/Texture.hpp> |
|
|
|
#include <SFML/Graphics/Texture.hpp> |
|
|
|
#include <SFML/Graphics/RectangleShape.hpp> |
|
|
|
#include <SFML/Graphics/RectangleShape.hpp> |
|
|
|
#include <SFML/Graphics/CircleShape.hpp> |
|
|
|
#include <SFML/Graphics/CircleShape.hpp> |
|
|
@ -14,7 +13,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
|
using namespace nlohmann; |
|
|
|
using namespace nlohmann; |
|
|
|
using namespace ImGui; |
|
|
|
|
|
|
|
using std::string; |
|
|
|
using std::string; |
|
|
|
|
|
|
|
|
|
|
|
void SoundQuip::load(json &data, const char *file_key, bool loop) { |
|
|
|
void SoundQuip::load(json &data, const char *file_key, bool loop) { |
|
|
@ -37,34 +35,7 @@ void SoundQuip::stop() { |
|
|
|
sound.stop(); |
|
|
|
sound.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::ImGui_setup() { |
|
|
|
|
|
|
|
bool res = SFML::Init(window); |
|
|
|
|
|
|
|
fmt::println("IMGUI returned {}", res); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::ImGui_update() { |
|
|
|
|
|
|
|
sf::Vector2u size = window.getSize(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SFML::Update(window, deltaClock.restart()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetNextWindowPos(ImVec2(0, 0)); |
|
|
|
|
|
|
|
SetNextWindowSize(ImVec2(size.x, size.y)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Begin("Build Status", &window_active_out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextColored(ImVec4(1,1,0,1), "Build Log"); |
|
|
|
|
|
|
|
BeginChild("Scrolling"); |
|
|
|
|
|
|
|
for(string &line : log) { |
|
|
|
|
|
|
|
TextWrapped(line.c_str()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
EndChild(); |
|
|
|
|
|
|
|
End(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::Window_update() { |
|
|
|
void SFMLBackend::Window_update() { |
|
|
|
if(show_build_log) { |
|
|
|
|
|
|
|
SFML::Render(window); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
window.display(); |
|
|
|
window.display(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -73,10 +44,6 @@ void SFMLBackend::handle_events() { |
|
|
|
|
|
|
|
|
|
|
|
// is this a main event loop
|
|
|
|
// is this a main event loop
|
|
|
|
while (window.pollEvent(event)) { |
|
|
|
while (window.pollEvent(event)) { |
|
|
|
if(show_build_log) { |
|
|
|
|
|
|
|
SFML::ProcessEvent(window, event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(event.type) { |
|
|
|
switch(event.type) { |
|
|
|
case sf::Event::Closed: |
|
|
|
case sf::Event::Closed: |
|
|
|
fmt::print("Exiting...\n"); |
|
|
|
fmt::print("Exiting...\n"); |
|
|
@ -110,12 +77,12 @@ sf::Vector2f translate(int x, int y) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::write_text(int x, int y, string content) { |
|
|
|
void SFMLBackend::write_text(int x, int y, string content, float size_mult) { |
|
|
|
sf::Vector2f position = translate(x,y); |
|
|
|
sf::Vector2f position = translate(x,y); |
|
|
|
sf::Text text; |
|
|
|
sf::Text text; |
|
|
|
text.setFont(font); |
|
|
|
text.setFont(font); |
|
|
|
text.setString(content); |
|
|
|
text.setString(content); |
|
|
|
text.setCharacterSize(TEXT_SIZE); |
|
|
|
text.setCharacterSize(TEXT_SIZE * size_mult); |
|
|
|
text.setFillColor(sf::Color(100, 250, 50)); |
|
|
|
text.setFillColor(sf::Color(100, 250, 50)); |
|
|
|
text.setPosition(position); |
|
|
|
text.setPosition(position); |
|
|
|
window.draw(text); |
|
|
|
window.draw(text); |
|
|
@ -125,14 +92,20 @@ void SFMLBackend::update_entities() { |
|
|
|
window.clear(); |
|
|
|
window.clear(); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2)); |
|
|
|
sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2)); |
|
|
|
face_box.setPosition(translate(X_ROWS/3+2,2)); |
|
|
|
face_box.setPosition(translate(2,2)); |
|
|
|
face_box.setOutlineColor(sf::Color(50, 200, 25)); |
|
|
|
face_box.setOutlineColor(sf::Color(50, 200, 25)); |
|
|
|
face_box.setOutlineThickness(10); |
|
|
|
face_box.setOutlineThickness(10); |
|
|
|
face_box.setFillColor(sf::Color(200, 250, 200)); |
|
|
|
face_box.setFillColor(sf::Color(200, 250, 200)); |
|
|
|
window.draw(face_box); |
|
|
|
window.draw(face_box); |
|
|
|
|
|
|
|
|
|
|
|
constexpr int hp_box_len = 44; |
|
|
|
sf::RectangleShape stats_box(translate(X_ROWS - X_ROWS/4 - 5, Y_LINES/2)); |
|
|
|
|
|
|
|
stats_box.setPosition(translate(X_ROWS/4 + 4, 2)); |
|
|
|
|
|
|
|
stats_box.setOutlineColor(sf::Color(50, 200, 25)); |
|
|
|
|
|
|
|
stats_box.setOutlineThickness(10); |
|
|
|
|
|
|
|
stats_box.setFillColor(sf::Color(0, 0, 0)); |
|
|
|
|
|
|
|
window.draw(stats_box); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constexpr int hp_box_len = 45; |
|
|
|
int current_hp = (float(game.hit_points) / float(game.starting_hp)) * float(hp_box_len); |
|
|
|
int current_hp = (float(game.hit_points) / float(game.starting_hp)) * float(hp_box_len); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape hp_bar(translate(current_hp,2)); |
|
|
|
sf::RectangleShape hp_bar(translate(current_hp,2)); |
|
|
@ -147,12 +120,15 @@ void SFMLBackend::update_entities() { |
|
|
|
hp_box.setFillColor(sf::Color::Transparent); |
|
|
|
hp_box.setFillColor(sf::Color::Transparent); |
|
|
|
window.draw(hp_box); |
|
|
|
window.draw(hp_box); |
|
|
|
|
|
|
|
|
|
|
|
string status = fmt::format("HP {} Rounds {} Streaks {} Deaths XXX", game.hit_points, game.rounds, game.streak); |
|
|
|
string status = fmt::format("HP {}\nRounds {}\nStreaks {}\nDeaths {}", |
|
|
|
write_text(2, 18, status); |
|
|
|
game.hit_points, game.rounds, |
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
write_text(X_ROWS/4+1, 14, time, 2.0f); |
|
|
|
|
|
|
|
|
|
|
|
if(show_build_log) { |
|
|
|
|
|
|
|
ImGui_update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Window_update(); |
|
|
|
Window_update(); |
|
|
|
|
|
|
|
|
|
|
|
show_build_log = window_active_out; |
|
|
|
show_build_log = window_active_out; |
|
|
@ -189,7 +165,6 @@ void SFMLBackend::startup() { |
|
|
|
|
|
|
|
|
|
|
|
window.setFramerateLimit(FPS); |
|
|
|
window.setFramerateLimit(FPS); |
|
|
|
window.setVerticalSyncEnabled(true); |
|
|
|
window.setVerticalSyncEnabled(true); |
|
|
|
ImGui_setup(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SFMLBackend::is_open() { |
|
|
|
bool SFMLBackend::is_open() { |
|
|
@ -197,5 +172,4 @@ bool SFMLBackend::is_open() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::shutdown() { |
|
|
|
void SFMLBackend::shutdown() { |
|
|
|
SFML::Shutdown(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|