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.
This commit is contained in:
parent
581e5b4a60
commit
e1c667d816
12 changed files with 40 additions and 36 deletions
BIN
assets/build_failed.png
Normal file
BIN
assets/build_failed.png
Normal file
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 |
BIN
assets/building.png
Normal file
BIN
assets/building.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
assets/you_died.png
Normal file
BIN
assets/you_died.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
|
@ -80,7 +80,7 @@ void Builder::BUILDING(BuildEvent ev) {
|
|||
|
||||
if(rc == 0) {
|
||||
game.event(GameEvent::BUILD_SUCCESS);
|
||||
gui.build_works();
|
||||
gui.build_success();
|
||||
} else {
|
||||
game.event(GameEvent::BUILD_FAILED);
|
||||
gui.build_failed(!game.is_dead(), build_cmd);
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
GUI gui;
|
||||
GameEngine game{100};
|
||||
auto backend = SFMLBackend(game);
|
||||
GUI gui(backend);
|
||||
auto builder = Builder(gui, game);
|
||||
|
||||
backend.startup();
|
||||
|
||||
while(backend.is_open()) {
|
||||
builder.event(BuildEvent::GO);
|
||||
gui.main_loop(backend);
|
||||
gui.main_loop();
|
||||
}
|
||||
|
||||
builder.event(BuildEvent::QUIT);
|
||||
|
|
2
fsm.hpp
2
fsm.hpp
|
@ -11,7 +11,7 @@
|
|||
template<typename S, typename E>
|
||||
class DeadSimpleFSM {
|
||||
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;
|
||||
|
||||
public:
|
||||
|
|
14
gui.cpp
14
gui.cpp
|
@ -17,13 +17,13 @@ using namespace fmt;
|
|||
using namespace nlohmann;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
GUI::GUI() {
|
||||
GUI::GUI(SFMLBackend &backend) : gui(backend) {
|
||||
std::ifstream infile(".tarpit.json");
|
||||
json data = json::parse(infile);
|
||||
|
||||
// json load the config file
|
||||
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");
|
||||
building_sound.load(data, "building", true);
|
||||
}
|
||||
|
@ -33,19 +33,21 @@ void GUI::output(const string msg) {
|
|||
std::cout << msg << std::endl;
|
||||
}
|
||||
|
||||
void GUI::main_loop(SFMLBackend &gui) {
|
||||
void GUI::main_loop() {
|
||||
gui.handle_events();
|
||||
gui.update_entities();
|
||||
gui.update_log(_lines);
|
||||
}
|
||||
|
||||
void GUI::build_works() {
|
||||
void GUI::build_success() {
|
||||
gui.change_face("build_success");
|
||||
building_sound.stop();
|
||||
build_works_sound.play();
|
||||
build_success_sound.play();
|
||||
output("BUILD FINISHED!");
|
||||
}
|
||||
|
||||
void GUI::build_failed(bool play_sound, const string &command) {
|
||||
gui.change_face("build_failed");
|
||||
building_sound.stop();
|
||||
|
||||
if(play_sound) {
|
||||
|
@ -56,6 +58,7 @@ void GUI::build_failed(bool play_sound, const string &command) {
|
|||
}
|
||||
|
||||
void GUI::you_died() {
|
||||
gui.change_face("you_died");
|
||||
building_sound.stop();
|
||||
you_died_sound.play();
|
||||
output("!!!! YOU DIED! !!!! Learn to code luser.");
|
||||
|
@ -63,6 +66,7 @@ void GUI::you_died() {
|
|||
}
|
||||
|
||||
void GUI::building() {
|
||||
gui.change_face("building");
|
||||
output("############# START ############");
|
||||
output(">>>> Will it Build?");
|
||||
building_sound.play();
|
||||
|
|
9
gui.hpp
9
gui.hpp
|
@ -12,22 +12,23 @@ class GUI {
|
|||
std::vector<string> _lines;
|
||||
|
||||
SoundQuip you_died_sound;
|
||||
SoundQuip build_works_sound;
|
||||
SoundQuip build_success_sound;
|
||||
SoundQuip build_failed_sound;
|
||||
SoundQuip building_sound;
|
||||
SFMLBackend &gui;
|
||||
|
||||
public:
|
||||
|
||||
GUI();
|
||||
GUI(SFMLBackend &backend);
|
||||
|
||||
// prevent copy
|
||||
GUI(GUI &g) = delete;
|
||||
|
||||
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 you_died();
|
||||
void building();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
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
|
||||
|
|
|
@ -45,12 +45,8 @@ public:
|
|||
class SFMLBackend {
|
||||
sf::ContextSettings settings;
|
||||
sf::RenderWindow window;
|
||||
sf::Clock clock;
|
||||
sf::Clock deltaClock;
|
||||
sf::Sprite face_sprite;
|
||||
sf::Texture face_texture;
|
||||
bool window_active_out = false;
|
||||
bool show_build_log = false;
|
||||
int hit_points = 50;
|
||||
sf::Font font;
|
||||
GameEngine &game;
|
||||
|
@ -67,6 +63,7 @@ public:
|
|||
bool is_open();
|
||||
void shutdown();
|
||||
|
||||
void change_face(const string name);
|
||||
void handle_events();
|
||||
void update_entities();
|
||||
void update_log(std::vector<string> &lines);
|
||||
|
|
|
@ -6,10 +6,10 @@ BUGS:
|
|||
|
||||
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.
|
||||
|
||||
* Convert buttons to sprites.
|
||||
* Mouse events to the GUI.
|
||||
* chrono::time_point is probably what we need but need to know where to put it for the timeout events and soo on.
|
||||
* Make some button graphics and use sprites, or see if you can do a drawn sprite.
|
||||
* 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:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue