aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README.md4
-rw-r--r--include/graphics.hpp4
-rw-r--r--screenshot.pngbin0 -> 3424 bytes
-rw-r--r--src/graphics.cpp50
-rw-r--r--src/main.cpp2
6 files changed, 44 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 681f96e..49d9ee6 100644
--- a/Makefile
+++ b/Makefile
@@ -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")
diff --git a/README.md b/README.md
index a145ec5..73a2487 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,9 @@
# 2048
+(shitty) 2048 game.
+
+![screenshot](./screenshot.png)
+
## 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
new file mode 100644
index 0000000..e667aa6
--- /dev/null
+++ b/screenshot.png
Binary files differ
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