Better UI layout and actually tracking deaths.

master
Zed A. Shaw 2 months ago
parent 662e4bf918
commit 56663b9052
  1. 2
      fsm.hpp
  2. 1
      game_engine.cpp
  3. 1
      game_engine.hpp
  4. 64
      sfmlbackend.cpp
  5. 4
      sfmlbackend.hpp
  6. 2
      status.txt

@ -18,7 +18,7 @@ public:
template<typename... Types> template<typename... Types>
void event(E event, Types... args); void event(E event, Types... args);
void state(S next_state) { void state(S next_state)
_state = next_state; _state = next_state;
} }

@ -95,6 +95,7 @@ void GameEngine::IN_ROUND(GameEvent ev, string &hit_type) {
void GameEngine::DEAD(GameEvent ev) { void GameEngine::DEAD(GameEvent ev) {
if(ev == GameEvent::BUILD_DONE) { if(ev == GameEvent::BUILD_DONE) {
deaths++;
reset(); reset();
state(GameState::FAILURE); state(GameState::FAILURE);
FAILURE(ev); FAILURE(ev);

@ -35,6 +35,7 @@ class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
int hit_points = 0; int hit_points = 0;
int hits_taken = 0; int hits_taken = 0;
int rounds = 0; int rounds = 0;
int deaths = 0;
int streak = 0; int streak = 0;
float hp_bonus = 1.0f; float hp_bonus = 1.0f;
bool free_death = false; bool free_death = false;

@ -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();
} }

@ -59,9 +59,7 @@ public:
void update_entities(); void update_entities();
void update_log(std::vector<string> &lines); void update_log(std::vector<string> &lines);
void write_text(int x, int y, string content); void write_text(int x, int y, string content, float size_mult=1.0f);
void ImGui_setup();
void ImGui_update();
void Window_update(); void Window_update();
}; };

@ -1,8 +1,6 @@
* Using that to redesign the starter UI. * Using that to redesign the starter UI.
BUGS: BUGS:
* BUG: lots of errors crash it
* BUG: doesn't play you_died sound.
TODO: TODO:
* Add a timer to the game engine so you can set a kind of pomodoro timer and if you don't meet the goal it costs you. * Add a timer to the game engine so you can set a kind of pomodoro timer and if you don't meet the goal it costs you.

Loading…
Cancel
Save