diff --git a/Color.h b/Color.h new file mode 100644 index 0000000..b62cf72 --- /dev/null +++ b/Color.h @@ -0,0 +1,37 @@ +// +// Created by trotfunky on 26/01/24. +// + +#ifndef RAYCASTING_COLOR_H +#define RAYCASTING_COLOR_H + +#include +#ifdef IMGUI +#include +#endif + + +class Color { +public: + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t alpha; + + constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255) : + r(r), g(g), b(b), alpha(alpha) {}; + + operator sf::Color() const { return {r, g, b, alpha}; } +#ifdef IMGUI + operator ImColor() const { return {r, g, b, alpha}; } +#endif +}; + +namespace Colors { + static constexpr Color Ground{67, 137, 39}; + static constexpr Color Ceiling{39, 69, 137}; + static constexpr Color Wall{84, 56, 34}; + static constexpr Color Door{186, 152, 107}; + static constexpr Color Window{104, 123, 165}; +} +#endif //RAYCASTING_COLOR_H diff --git a/World.cpp b/World.cpp index 3e7ecc9..d359063 100644 --- a/World.cpp +++ b/World.cpp @@ -287,13 +287,13 @@ void World::step(const float& stepTime) { ImVec4 hoverColor; switch ((BlockType)blockToPlace) { case BlockType::WALL: - hoverColor = (ImVec4)ImColor(84, 56, 34); + hoverColor = (ImVec4)Colors::Wall; break; case BlockType::DOOR: - hoverColor = (ImVec4)ImColor(186, 152, 107); + hoverColor = (ImVec4)Colors::Door; break; case BlockType::WINDOW: - hoverColor = (ImVec4)ImColor(104, 123, 165); + hoverColor = (ImVec4)Colors::Window; break; default: /* Default header color, it seems ? */ @@ -305,13 +305,13 @@ void World::step(const float& stepTime) { ImVec4 blockColor; switch (currentBlock) { case BlockType::WALL: - blockColor = (ImVec4)ImColor(84, 56, 34); + blockColor = (ImVec4)Colors::Wall; break; case BlockType::DOOR: - blockColor = (ImVec4)ImColor(186, 152, 107); + blockColor = (ImVec4)Colors::Door; break; case BlockType::WINDOW: - blockColor = (ImVec4)ImColor(104, 123, 165); + blockColor = (ImVec4)Colors::Window; break; default: blockColor = (ImVec4)ImColor(188, 120, 32); diff --git a/World.h b/World.h index 59a14b0..19c503a 100644 --- a/World.h +++ b/World.h @@ -10,6 +10,7 @@ #include #include +#include "Color.h" #include "Player.h" enum class BlockType { @@ -24,8 +25,8 @@ public: Player player; World(int w, int h, - sf::Color groundColor = sf::Color{67, 137, 39}, - sf::Color ceilingColor = sf::Color{39, 69, 137}, + sf::Color groundColor = Colors::Ground, + sf::Color ceilingColor = Colors::Ceiling, std::vector worldMap = {}); int getW() const; int getH() const; @@ -52,7 +53,7 @@ private: sf::Color ceilingColor; void fillColumn(sf::RenderWindow&, unsigned int column, float scale, - sf::Color fillColor = sf::Color(84,56,34)) const; + sf::Color fillColor = Colors::Wall) const; /** * Cast a ray from a given position and return its distance to the origin. * @param originX Ray X origin, strictly positive