The images for my reactions to your bad code are now up. Went with a more 'pixel video' look than a pixel art hand drawn thing.

master
Zed A. Shaw 2 months ago
parent 581e5b4a60
commit e1c667d816
  1. BIN
      assets/build_failed.png
  2. BIN
      assets/build_success.png
  3. BIN
      assets/building.png
  4. BIN
      assets/you_died.png
  5. 2
      builder.cpp
  6. 4
      escape_turings_tarpit.cpp
  7. 2
      fsm.hpp
  8. 14
      gui.cpp
  9. 9
      gui.hpp
  10. 34
      sfmlbackend.cpp
  11. 5
      sfmlbackend.hpp
  12. 6
      status.txt

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

@ -80,7 +80,7 @@ void Builder::BUILDING(BuildEvent ev) {
if(rc == 0) { if(rc == 0) {
game.event(GameEvent::BUILD_SUCCESS); game.event(GameEvent::BUILD_SUCCESS);
gui.build_works(); gui.build_success();
} else { } else {
game.event(GameEvent::BUILD_FAILED); game.event(GameEvent::BUILD_FAILED);
gui.build_failed(!game.is_dead(), build_cmd); gui.build_failed(!game.is_dead(), build_cmd);

@ -4,16 +4,16 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
GUI gui;
GameEngine game{100}; GameEngine game{100};
auto backend = SFMLBackend(game); auto backend = SFMLBackend(game);
GUI gui(backend);
auto builder = Builder(gui, game); auto builder = Builder(gui, game);
backend.startup(); backend.startup();
while(backend.is_open()) { while(backend.is_open()) {
builder.event(BuildEvent::GO); builder.event(BuildEvent::GO);
gui.main_loop(backend); gui.main_loop();
} }
builder.event(BuildEvent::QUIT); builder.event(BuildEvent::QUIT);

@ -11,7 +11,7 @@
template<typename S, typename E> template<typename S, typename E>
class DeadSimpleFSM { class DeadSimpleFSM {
protected: protected:
// BUG: don't put this in your class because state() won't work // BUG: don't put this in your class because state() won't wor
S _state = S::START; S _state = S::START;
public: public:

@ -17,13 +17,13 @@ using namespace fmt;
using namespace nlohmann; using namespace nlohmann;
namespace fs = std::filesystem; namespace fs = std::filesystem;
GUI::GUI() { GUI::GUI(SFMLBackend &backend) : gui(backend) {
std::ifstream infile(".tarpit.json"); std::ifstream infile(".tarpit.json");
json data = json::parse(infile); json data = json::parse(infile);
// json load the config file // json load the config file
you_died_sound.load(data, "you_died"); you_died_sound.load(data, "you_died");
build_works_sound.load(data, "build_works"); build_success_sound.load(data, "build_success");
build_failed_sound.load(data, "build_failed"); build_failed_sound.load(data, "build_failed");
building_sound.load(data, "building", true); building_sound.load(data, "building", true);
} }
@ -33,19 +33,21 @@ void GUI::output(const string msg) {
std::cout << msg << std::endl; std::cout << msg << std::endl;
} }
void GUI::main_loop(SFMLBackend &gui) { void GUI::main_loop() {
gui.handle_events(); gui.handle_events();
gui.update_entities(); gui.update_entities();
gui.update_log(_lines); gui.update_log(_lines);
} }
void GUI::build_works() { void GUI::build_success() {
gui.change_face("build_success");
building_sound.stop(); building_sound.stop();
build_works_sound.play(); build_success_sound.play();
output("BUILD FINISHED!"); output("BUILD FINISHED!");
} }
void GUI::build_failed(bool play_sound, const string &command) { void GUI::build_failed(bool play_sound, const string &command) {
gui.change_face("build_failed");
building_sound.stop(); building_sound.stop();
if(play_sound) { if(play_sound) {
@ -56,6 +58,7 @@ void GUI::build_failed(bool play_sound, const string &command) {
} }
void GUI::you_died() { void GUI::you_died() {
gui.change_face("you_died");
building_sound.stop(); building_sound.stop();
you_died_sound.play(); you_died_sound.play();
output("!!!! YOU DIED! !!!! Learn to code luser."); output("!!!! YOU DIED! !!!! Learn to code luser.");
@ -63,6 +66,7 @@ void GUI::you_died() {
} }
void GUI::building() { void GUI::building() {
gui.change_face("building");
output("############# START ############"); output("############# START ############");
output(">>>> Will it Build?"); output(">>>> Will it Build?");
building_sound.play(); building_sound.play();

@ -12,22 +12,23 @@ class GUI {
std::vector<string> _lines; std::vector<string> _lines;
SoundQuip you_died_sound; SoundQuip you_died_sound;
SoundQuip build_works_sound; SoundQuip build_success_sound;
SoundQuip build_failed_sound; SoundQuip build_failed_sound;
SoundQuip building_sound; SoundQuip building_sound;
SFMLBackend &gui;
public: public:
GUI(); GUI(SFMLBackend &backend);
// prevent copy // prevent copy
GUI(GUI &g) = delete; GUI(GUI &g) = delete;
void output(const string msg); void output(const string msg);
void main_loop(SFMLBackend &backend); void main_loop();
void build_works(); void build_success();
void build_failed(bool play_sound, const string &command); void build_failed(bool play_sound, const string &command);
void you_died(); void you_died();
void building(); void building();

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

@ -45,12 +45,8 @@ public:
class SFMLBackend { class SFMLBackend {
sf::ContextSettings settings; sf::ContextSettings settings;
sf::RenderWindow window; sf::RenderWindow window;
sf::Clock clock;
sf::Clock deltaClock;
sf::Sprite face_sprite; sf::Sprite face_sprite;
sf::Texture face_texture; sf::Texture face_texture;
bool window_active_out = false;
bool show_build_log = false;
int hit_points = 50; int hit_points = 50;
sf::Font font; sf::Font font;
GameEngine &game; GameEngine &game;
@ -67,6 +63,7 @@ public:
bool is_open(); bool is_open();
void shutdown(); void shutdown();
void change_face(const string name);
void handle_events(); void handle_events();
void update_entities(); void update_entities();
void update_log(std::vector<string> &lines); void update_log(std::vector<string> &lines);

@ -6,10 +6,10 @@ BUGS:
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.
* chrono::time_point is probably what we need but need to know where to put it for the timeout events and soo on.
* Convert buttons to sprites. * Make some button graphics and use sprites, or see if you can do a drawn sprite.
* Mouse events to the GUI.
* sf::Rect::contains(mouse.x, mouse.y) will say if the mouse is inside the sprite rect. * sf::Rect::contains(mouse.x, mouse.y) will say if the mouse is inside the sprite rect.
* Redo the images of me so they're correctly cropped.
NOTES: NOTES:

Loading…
Cancel
Save