diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-20 23:19:06 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-20 23:19:06 +0100 |
| commit | 43cdfd38bc27fe96105b48d980799f3b2fdd8f0f (patch) | |
| tree | 9c654440614f1dbd626d5d139f3a1f46a7ce5c3a | |
| parent | 64f6f1eaa2ecc188292cfe4a7223606b8bcb3bf2 (diff) | |
| download | 2048-43cdfd38bc27fe96105b48d980799f3b2fdd8f0f.tar.gz 2048-43cdfd38bc27fe96105b48d980799f3b2fdd8f0f.tar.bz2 2048-43cdfd38bc27fe96105b48d980799f3b2fdd8f0f.zip | |
c++98 complient and README update
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | include/graphics.hpp | 4 | ||||
| -rw-r--r-- | screenshot.png | bin | 0 -> 3424 bytes | |||
| -rw-r--r-- | src/graphics.cpp | 50 | ||||
| -rw-r--r-- | src/main.cpp | 2 |
6 files changed, 44 insertions, 18 deletions
@@ -8,7 +8,7 @@ INCDIR = include OBJDIR = build CXX = g++ -CXXFLAGS = -Wall -Wextra -I$(INCDIR) $(shell sdl2-config --cflags) -std=c++11 +CXXFLAGS = -Wall -Wextra -I$(INCDIR) $(shell sdl2-config --cflags) -std=c++98 LDFLAGS = $(shell sdl2-config --libs) -lSDL2_ttf SRC = $(shell find $(SRCDIR) -type f -name "*.cpp") @@ -1,5 +1,9 @@ # 2048 +(shitty) 2048 game. + + + ## Usage ``` diff --git a/include/graphics.hpp b/include/graphics.hpp index 42de214..f98f175 100644 --- a/include/graphics.hpp +++ b/include/graphics.hpp @@ -3,6 +3,7 @@ #include <string> #include <iostream> +#include <sstream> #include <vector> #include <map> #include <utility> @@ -50,6 +51,9 @@ class Graphics SDL_Texture *getNumberTex(int n) const; SDL_Texture *newTextTex(std::string s, SDL_Color c); void error() const; + + static SDL_Color makeColor(int r, int g, int b); + static std::string intToString(int n); }; #endif diff --git a/screenshot.png b/screenshot.png Binary files differnew file mode 100644 index 0000000..e667aa6 --- /dev/null +++ b/screenshot.png diff --git a/src/graphics.cpp b/src/graphics.cpp index 0d9a054..894a629 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -21,19 +21,19 @@ Graphics::Graphics(Game &game, std::string title, int width, int height, AI *ai) error(); if ((m_font = TTF_OpenFont("./font/noto_mono_regular.ttf", 16)) == NULL) error(); - m_scoreText = newTextTex("score", {255, 255, 255, 255}); - m_palette[0] = {10, 10, 10, 255}; - m_palette[2] = {100, 100, 100, 255}; - m_palette[4] = {65, 65, 65, 255}; - m_palette[8] = {40, 40, 40, 255}; - m_palette[16] = {150, 50, 20, 255}; - m_palette[32] = {160, 70, 20, 255}; - m_palette[64] = {190, 80, 30, 255}; - m_palette[128] = {200, 100, 40, 255}; - m_palette[256] = {220, 120, 40, 255}; - m_palette[512] = {230, 180, 30, 255}; - m_palette[1024] = {230, 190, 20, 255}; - m_palette[2048] = {230, 200, 10, 255}; + m_scoreText = newTextTex("score", makeColor(255, 255, 255)); + m_palette[0] = makeColor(10, 10, 10); + m_palette[2] = makeColor(100, 100, 100); + m_palette[4] = makeColor(65, 65, 65); + m_palette[8] = makeColor(40, 40, 40); + m_palette[16] = makeColor(150, 50, 20); + m_palette[32] = makeColor(160, 70, 20); + m_palette[64] = makeColor(190, 80, 30); + m_palette[128] = makeColor(200, 100, 40); + m_palette[256] = makeColor(220, 120, 40); + m_palette[512] = makeColor(230, 180, 30); + m_palette[1024] = makeColor(230, 190, 20); + m_palette[2048] = makeColor(230, 200, 10); } Graphics::~Graphics() @@ -84,7 +84,7 @@ void Graphics::drawCell(int x, int y) if ((tex = getNumberTex(m_game.get(y, x))) == NULL) tex = addNumberTex(m_game.get(y, x)); if (m_palette.find(m_game.get(y, x)) == m_palette.end()) - c = {30, 30, 30, 255}; + c = makeColor(30, 30, 30); else c = m_palette[m_game.get(y, x)]; r.x = 2 + x * (m_gridSize / m_game.getSize()); @@ -122,7 +122,7 @@ void Graphics::drawScore() } SDL_RenderCopy(m_renderer, m_scoreText, NULL, &r); - SDL_Texture *scoreNumTex = newTextTex(std::to_string(m_game.getScore()), {255, 255, 255, 255}); + SDL_Texture *scoreNumTex = newTextTex(intToString(m_game.getScore()), makeColor(255, 255, 255)); SDL_QueryTexture(scoreNumTex, NULL, NULL, &r.w, &r.h); if (m_width > m_height) r.y += 20; @@ -172,7 +172,7 @@ SDL_Texture *Graphics::addNumberTex(int n) { SDL_Texture *tex; SDL_Color c = {255, 255, 255, 255}; - tex = newTextTex(std::to_string(n), c); + tex = newTextTex(intToString(n), c); m_numberTexBuf.push_back(std::make_pair(n, tex)); return tex; } @@ -203,3 +203,21 @@ void Graphics::error() const std::cout << SDL_GetError() << std::endl; exit(1); } + +SDL_Color Graphics::makeColor(int r, int g, int b) +{ + SDL_Color c; + + c.r = r; + c.g = g; + c.b = b; + c.a = 255; + return c; +} + +std::string Graphics::intToString(int n) +{ + std::stringstream tmp; + tmp << n; + return tmp.str(); +} diff --git a/src/main.cpp b/src/main.cpp index 22fbc34..b127c72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ #include "rand_ai.hpp" #define WINDOW_TITLE "2048" -#define WINDOW_WIDTH 640 +#define WINDOW_WIDTH 600 #define WINDOW_HEIGHT 480 #define GAME_GRID_SIZE 4 |
