diff --git a/include/Common.hpp b/include/Common.hpp index 035acc6..3bd2221 100644 --- a/include/Common.hpp +++ b/include/Common.hpp @@ -8,6 +8,7 @@ #ifndef COMMON #define COMMON #include +#include #include #include @@ -68,7 +69,8 @@ namespace Arcade { float x; float y; char character; - int color; + std::uint8_t color; + std::uint8_t textColor; }; struct Drawable { diff --git a/include/Core.hpp b/include/Core.hpp index b143e55..f500d23 100644 --- a/include/Core.hpp +++ b/include/Core.hpp @@ -47,7 +47,7 @@ class Core { void runMenu(); void runGame(); - std::vector stringToCells(const std::string& str, float startX, float startY); + std::vector stringToCells(const std::string& str, float startX, float startY, std::uint8_t color, std::uint8_t textColor); public: explicit Core(const std::string &initalGraphicLib, const std::string& playerName = "Player 1"); diff --git a/include/MenuSelector.hpp b/include/MenuSelector.hpp index df63b78..dd73479 100644 --- a/include/MenuSelector.hpp +++ b/include/MenuSelector.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace Arcade { diff --git a/include/PluginApi.hpp b/include/PluginApi.hpp deleted file mode 100644 index cde2f54..0000000 --- a/include/PluginApi.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* -** EPITECH PROJECT, 2026 -** PluginApi -** File description: -** PluginApi -*/ - -#ifndef PLUGINAPI - #define PLUGINAPI - #include "Common.hpp" - -namespace Arcade { - using CreateFn = void* (*)(); - using DestroyFn = void (*)(void*); - using GetTypeFn = PluginType (*)(); - using GetNameFn = const char* (*)(); -} - -#endif diff --git a/src/Core.cpp b/src/Core.cpp index 43e3dbe..774e329 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -5,6 +5,7 @@ ** core */ +#include #include #include #include "Core.hpp" @@ -88,10 +89,10 @@ void Core::handleGlobalInput(InputAction action) { } } -std::vector Core::stringToCells(const std::string& str, float startX, float startY) { +std::vector Core::stringToCells(const std::string& str, float startX, float startY, std::uint8_t color, std::uint8_t textColor) { std::vector cells; for (size_t i = 0; i < str.length(); ++i) { - cells.push_back({startX + static_cast(i), startY, str[i], 0}); + cells.push_back({startX + static_cast(i), startY, str[i], color, textColor}); } return cells; } @@ -113,18 +114,18 @@ void Core::runMenu() { std::vector menuRender; - auto title = stringToCells("--- Arcade Menu ---", 10.0f, 2.0f); + auto title = stringToCells("--- Arcade Menu ---", 10.0f, 2.0f, 0, 7); menuRender.insert(menuRender.end(), title.begin(), title.end()); - auto nameInfo = stringToCells("Player: " + _playerName, 10.0f, 4.0f); + auto nameInfo = stringToCells("Player: " + _playerName, 10.0f, 4.0f, 0, 1); menuRender.insert(menuRender.end(), nameInfo.begin(), nameInfo.end()); - auto gamesTitle = stringToCells("Available Games:", 10.0f, 6.0f); + auto gamesTitle = stringToCells("Available Games:", 10.0f, 6.0f, 0, 1); menuRender.insert(menuRender.end(), gamesTitle.begin(), gamesTitle.end()); for (size_t i = 0; i < _gameLibs.size(); ++i) { std::string prefix = (i == _menuSelectionIdx) ? "> " : " "; - auto gameName = stringToCells(prefix + _gameLibs[i], 12.0f, 8.0f + i); + auto gameName = stringToCells(prefix + _gameLibs[i], 12.0f, 8.0f + i, (i == _menuSelectionIdx) ? 1 : 0, (i == _menuSelectionIdx) ? 0 : 1); menuRender.insert(menuRender.end(), gameName.begin(), gameName.end()); } @@ -143,9 +144,6 @@ void Core::runGame() { _graph->clear(); _graph->draw(_game->getDisplay()); - auto scoreDisplay = stringToCells("Score: " + std::to_string(_game->getScore()), 0.0f, 0.0f); - _graph->draw(scoreDisplay); - _graph->display(); } } diff --git a/src/MenuSelector.cpp b/src/MenuSelector.cpp index 5cf284a..617f8b2 100644 --- a/src/MenuSelector.cpp +++ b/src/MenuSelector.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace Arcade { diff --git a/src/graphicals/Ncurses/NcursesModule.cpp b/src/graphicals/Ncurses/NcursesModule.cpp index 1ab1a92..7238a08 100644 --- a/src/graphicals/Ncurses/NcursesModule.cpp +++ b/src/graphicals/Ncurses/NcursesModule.cpp @@ -78,14 +78,14 @@ class NcursesModule : public Arcade::IGraphics { if (x < 0 || y < 0) continue; - if (cell.color > 0 && cell.color <= 7) { - attron(COLOR_PAIR(cell.color)); + if (cell.textColor > 0 && cell.textColor <= 7) { + attron(COLOR_PAIR(cell.textColor)); } mvaddch(y, x, cell.character); - if (cell.color > 0 && cell.color <= 7) { - attroff(COLOR_PAIR(cell.color)); + if (cell.textColor > 0 && cell.textColor <= 7) { + attroff(COLOR_PAIR(cell.textColor)); } } } diff --git a/src/graphicals/Sdl2/Sdl2Module.cpp b/src/graphicals/Sdl2/Sdl2Module.cpp index 55ccf4d..e1de96a 100644 --- a/src/graphicals/Sdl2/Sdl2Module.cpp +++ b/src/graphicals/Sdl2/Sdl2Module.cpp @@ -1,4 +1,7 @@ #include "IGraphic.hpp" +#include +#include +#include #ifdef __APPLE__ #include @@ -13,6 +16,45 @@ #include #include +#define COLOR_WHITE {200, 200, 200} +#define COLOR_RED {200, 0, 0} +#define COLOR_GREEN {0, 200, 0} +#define COLOR_YELLOW {200, 200, 0} +#define COLOR_BLUE {0, 0, 200} +#define COLOR_MAGENTA {200, 0, 200} +#define COLOR_CYAN {35, 200, 200} + +static std::vector to_rgb(std::uint8_t color) { + std::vector rgb; + + switch (color) { + case 1: + rgb = COLOR_WHITE; + break; + case 2: + rgb = COLOR_RED; + break; + case 3: + rgb = COLOR_GREEN; + break; + case 4: + rgb = COLOR_YELLOW; + break; + case 5: + rgb = COLOR_BLUE; + break; + case 6: + rgb = COLOR_MAGENTA; + break; + case 7: + rgb = COLOR_CYAN; + break; + default: + rgb = {20, 20, 20}; + } + return rgb; +} + class SDL2Module : public Arcade::IGraphics { private: SDL_Window* _window; @@ -72,7 +114,7 @@ class SDL2Module : public Arcade::IGraphics { SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, - SDL_WINDOW_MAXIMIZED + SDL_WINDOW_RESIZABLE ); if (!_window) { @@ -122,19 +164,15 @@ class SDL2Module : public Arcade::IGraphics { SDL_Rect rect = {x, y, _cellSize, _cellSize}; - Uint8 r = 0, g = 0, b = 0; - if (cell.character == '-' || cell.character == '>') { r = 0; g = 0; b = 100; } - else { r = 20; g = 20; b = 20; } + std::vector color = to_rgb(cell.color); + std::vector textVecColor = to_rgb(cell.textColor); - SDL_SetRenderDrawColor(_renderer, r, g, b, 255); + SDL_SetRenderDrawColor(_renderer, color[0], color[1], color[2], 255); SDL_RenderFillRect(_renderer, &rect); - SDL_SetRenderDrawColor(_renderer, 100, 100, 100, 255); - SDL_RenderDrawRect(_renderer, &rect); - if (_font && cell.character != ' ') { char text[2] = {cell.character, '\0'}; - SDL_Color textColor = {255, 255, 255, 255}; + SDL_Color textColor = {textVecColor[0], textVecColor[1], textVecColor[2], 255}; SDL_Surface* surface = TTF_RenderText_Blended(_font, text, textColor); if (surface) {