Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef COMMON
#define COMMON
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>

Expand Down Expand Up @@ -68,7 +69,8 @@ namespace Arcade {
float x;
float y;
char character;
int color;
std::uint8_t color;
std::uint8_t textColor;
};

struct Drawable {
Expand Down
2 changes: 1 addition & 1 deletion include/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Core {
void runMenu();
void runGame();

std::vector<Cell> stringToCells(const std::string& str, float startX, float startY);
std::vector<Cell> 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");
Expand Down
1 change: 0 additions & 1 deletion include/MenuSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string>
#include <vector>
#include <functional>
#include <iostream>

namespace Arcade {

Expand Down
19 changes: 0 additions & 19 deletions include/PluginApi.hpp

This file was deleted.

16 changes: 7 additions & 9 deletions src/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
** core
*/

#include <cstdint>
#include <memory>
#include <algorithm>
#include "Core.hpp"
Expand Down Expand Up @@ -88,10 +89,10 @@ void Core::handleGlobalInput(InputAction action) {
}
}

std::vector<Cell> Core::stringToCells(const std::string& str, float startX, float startY) {
std::vector<Cell> Core::stringToCells(const std::string& str, float startX, float startY, std::uint8_t color, std::uint8_t textColor) {
std::vector<Cell> cells;
for (size_t i = 0; i < str.length(); ++i) {
cells.push_back({startX + static_cast<float>(i), startY, str[i], 0});
cells.push_back({startX + static_cast<float>(i), startY, str[i], color, textColor});
}
return cells;
}
Expand All @@ -113,18 +114,18 @@ void Core::runMenu() {

std::vector<Cell> 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());
}

Expand All @@ -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();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/MenuSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>

namespace Arcade {

Expand Down
8 changes: 4 additions & 4 deletions src/graphicals/Ncurses/NcursesModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
56 changes: 47 additions & 9 deletions src/graphicals/Sdl2/Sdl2Module.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "IGraphic.hpp"
#include <SDL2/SDL_video.h>
#include <cstdint>
#include <vector>

#ifdef __APPLE__
#include <SDL.h>
Expand All @@ -13,6 +16,45 @@
#include <map>
#include <iostream>

#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<Uint8> to_rgb(std::uint8_t color) {
std::vector<Uint8> 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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<Uint8> color = to_rgb(cell.color);
std::vector<Uint8> 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) {
Expand Down
Loading