A weird game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
turings-tarpit/sfmlbackend.hpp

91 lines
2.0 KiB

#pragma once
#include <SFML/System.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Audio.hpp>
#include <nlohmann/json.hpp>
#include "game_engine.hpp"
#include <string>
using std::string;
enum class Value {
BLACK=0, DARK_DARK, DARK_MID,
DARK_LIGHT, MID, LIGHT_DARK, LIGHT_MID,
LIGHT_LIGHT, WHITE, TRANSPARENT
};
constexpr int FPS=30;
constexpr int X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2;
constexpr int TEXT_SIZE = 48;
constexpr Value TEXT_COLOR = Value::LIGHT_LIGHT;
constexpr int Y_LINES = 23;
constexpr int X_ROWS = 48;
constexpr Value BOX_OUTLINE = Value::MID;
constexpr int BOX_THICKNESS=10;
constexpr Value BOX_FILL = Value::TRANSPARENT;
enum class Button {
NONE, START, STOP
};
class SoundQuip {
public:
sf::Sound sound;
sf::SoundBuffer buffer;
bool initialized;
SoundQuip() {};
void load(nlohmann::json &data, const char *file_key, bool loop=false);
void play();
void stop();
};
class SFMLBackend {
sf::ContextSettings settings;
sf::RenderWindow window;
sf::Sprite face_sprite;
sf::Texture face_texture;
sf::Sprite stop_button;
sf::Texture stop_texture;
sf::Sprite start_button;
sf::Texture start_texture;
std::chrono::time_point<std::chrono::system_clock> clock_start;
Button buttons = Button::STOP;
int hit_points = 50;
sf::Font font;
GameEngine &game;
std::vector<string> log;
public:
SFMLBackend(GameEngine &g);
// prevent copy
SFMLBackend(SFMLBackend &g) = delete;
void startup();
bool is_open();
void shutdown();
void change_face(const string name);
void handle_events();
void update_entities();
void update_log(std::vector<string> &lines);
sf::Color value(Value level);
sf::RectangleShape box(int x, int y, int width, int height,
Value fill=BOX_FILL,
Value outline=BOX_OUTLINE,
int thickness=BOX_THICKNESS);
void write_text(int x, int y, string content, float size_mult=1.0f, Value color=TEXT_COLOR);
void Window_update();
};