finish title screen, fix game logic, add textures, somehow forgot the T tetromino lol
@@ -30,7 +30,7 @@ target_link_libraries(SDL_TD
|
|||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB ASSETS
|
file(GLOB ASSETS
|
||||||
"assets/*.png"
|
"assets/*"
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(ASSET ${ASSETS})
|
foreach(ASSET ${ASSETS})
|
||||||
|
|||||||
BIN
assets/BORDER.png
Normal file
|
After Width: | Height: | Size: 236 B |
BIN
assets/I.png
|
Before Width: | Height: | Size: 622 B |
BIN
assets/I_END.png
Normal file
|
After Width: | Height: | Size: 240 B |
BIN
assets/I_ENDR.png
Normal file
|
After Width: | Height: | Size: 223 B |
BIN
assets/I_MID.png
Normal file
|
After Width: | Height: | Size: 242 B |
BIN
assets/I_MIDR.png
Normal file
|
After Width: | Height: | Size: 231 B |
BIN
assets/I_START.png
Normal file
|
After Width: | Height: | Size: 246 B |
BIN
assets/I_STARTR.png
Normal file
|
After Width: | Height: | Size: 231 B |
BIN
assets/J.png
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 225 B |
BIN
assets/L.png
|
Before Width: | Height: | Size: 630 B After Width: | Height: | Size: 205 B |
BIN
assets/O.png
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 210 B |
BIN
assets/S.png
|
Before Width: | Height: | Size: 581 B After Width: | Height: | Size: 223 B |
BIN
assets/T.png
Normal file
|
After Width: | Height: | Size: 224 B |
BIN
assets/Z.png
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 210 B |
BIN
assets/tetris-gb.ttf
Normal file
BIN
assets/title.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
assets/title_bg.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
32
src/Game.cpp
@@ -19,6 +19,8 @@ bool Game::init(const char* title, int w, int h) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_SetWindowMinimumSize(window.get( ), 800, 650);
|
||||||
|
|
||||||
renderer = std::shared_ptr<SDL_Renderer>(
|
renderer = std::shared_ptr<SDL_Renderer>(
|
||||||
SDL_CreateRenderer(window.get( ), -1, SDL_RENDERER_ACCELERATED),
|
SDL_CreateRenderer(window.get( ), -1, SDL_RENDERER_ACCELERATED),
|
||||||
[ ](SDL_Renderer* r) { SDL_DestroyRenderer(r); }
|
[ ](SDL_Renderer* r) { SDL_DestroyRenderer(r); }
|
||||||
@@ -28,11 +30,15 @@ bool Game::init(const char* title, int w, int h) {
|
|||||||
SDL_Log("Failed to create renderer: %s", SDL_GetError( ));
|
SDL_Log("Failed to create renderer: %s", SDL_GetError( ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
int ww, wh;
|
||||||
|
SDL_GetWindowSize(window.get( ), &ww, &wh);
|
||||||
|
|
||||||
gameRenderer = make_shared<Renderer>(renderer);
|
gameRenderer = make_shared<Renderer>(renderer, ww, wh);
|
||||||
gameBoard = make_shared<GameBoard>( );
|
gameBoard = make_shared<GameBoard>( );
|
||||||
|
|
||||||
bgm = std::shared_ptr<Mix_Music>(Mix_LoadMUS("/home/crylia/Dokumente/git/tetris_sdl/assets/bgm.mp3"), [ ](Mix_Music* m) {
|
handleWindowResize( );
|
||||||
|
|
||||||
|
bgm = std::shared_ptr<Mix_Music>(Mix_LoadMUS("assets/bgm.mp3"), [ ](Mix_Music* m) {
|
||||||
Mix_FreeMusic(m);
|
Mix_FreeMusic(m);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,7 +79,10 @@ void Game::run( ) {
|
|||||||
void Game::inputHandler( ) {
|
void Game::inputHandler( ) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_QUIT) { SDL_Quit( ); } else if (event.type == SDL_KEYDOWN) {
|
if (event.type == SDL_QUIT) {
|
||||||
|
SDL_Quit( );
|
||||||
|
quit = true;
|
||||||
|
} else if (event.type == SDL_KEYDOWN) {
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.sym) {
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
case SDLK_a:
|
case SDLK_a:
|
||||||
@@ -106,10 +115,25 @@ void Game::inputHandler( ) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||||
|
handleWindowResize( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::handleWindowResize( ) {
|
||||||
|
int windowWidth, windowHeight;
|
||||||
|
SDL_GetWindowSize(window.get( ), &windowWidth, &windowHeight);
|
||||||
|
|
||||||
|
gameRenderer->setBlockSize(windowHeight / gameBoard->getLockedTetrominos( ).size( ));
|
||||||
|
|
||||||
|
int offsetX = (windowWidth - gameBoard->getLockedTetrominos( )[0].size( ) * gameRenderer->getBlockSize( )) / 2;
|
||||||
|
int offsetY = (windowHeight - gameBoard->getLockedTetrominos( ).size( ) * gameRenderer->getBlockSize( )) / 2;
|
||||||
|
gameRenderer->setOffset(offsetX, offsetY);
|
||||||
|
|
||||||
|
gameRenderer->setWindowSize(windowWidth, windowHeight);
|
||||||
|
}
|
||||||
|
|
||||||
void Game::update( ) {
|
void Game::update( ) {
|
||||||
Uint32 currentTime = SDL_GetTicks( );
|
Uint32 currentTime = SDL_GetTicks( );
|
||||||
Uint32 deltaTime = currentTime - lastUpdateTime;
|
Uint32 deltaTime = currentTime - lastUpdateTime;
|
||||||
@@ -122,7 +146,7 @@ void Game::update( ) {
|
|||||||
|
|
||||||
void Game::render( ) {
|
void Game::render( ) {
|
||||||
//Set default color to black
|
//Set default color to black
|
||||||
SDL_SetRenderDrawColor(renderer.get( ), 20, 20, 20, 255);
|
SDL_SetRenderDrawColor(renderer.get( ), 248, 248, 248, 255);
|
||||||
SDL_RenderClear(renderer.get( ));
|
SDL_RenderClear(renderer.get( ));
|
||||||
|
|
||||||
gameRenderer->renderBoard(*gameBoard);
|
gameRenderer->renderBoard(*gameBoard);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ private:
|
|||||||
void render( );
|
void render( );
|
||||||
void inputHandler( );
|
void inputHandler( );
|
||||||
|
|
||||||
|
void handleWindowResize( );
|
||||||
|
|
||||||
unique_ptr<SDL_Window, void(*)(SDL_Window*)> window;
|
unique_ptr<SDL_Window, void(*)(SDL_Window*)> window;
|
||||||
shared_ptr<SDL_Renderer> renderer;
|
shared_ptr<SDL_Renderer> renderer;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
GameBoard::GameBoard( )
|
GameBoard::GameBoard( )
|
||||||
: lockedTetrominos(20, vector<int>(10, 0)), lockedColors(20, std::vector<SDL_Color>(10, { 0, 0, 0, 0 })), score(0), level(1), collision(false) {
|
: lockedTetrominos(20, vector<int>(10, 0)), lockedColors(20, std::vector<SDL_Color>(10, { 0, 0, 0, 255 })), score(0), level(1), collision(false) {
|
||||||
spawnNewTetromino( );
|
spawnNewTetromino( );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,37 +41,86 @@ bool GameBoard::checkCollision(const Tetromino& tetromino) const {
|
|||||||
void GameBoard::lockTetromino( ) {
|
void GameBoard::lockTetromino( ) {
|
||||||
const auto& shape = currentTetromino->getShape( );
|
const auto& shape = currentTetromino->getShape( );
|
||||||
int x = currentTetromino->getX( ), y = currentTetromino->getY( );
|
int x = currentTetromino->getX( ), y = currentTetromino->getY( );
|
||||||
|
double angle = currentTetromino->getRotationAngle( );
|
||||||
|
TetrominoShape tetrominoShape = currentTetromino->getShapeEnumn( );
|
||||||
|
|
||||||
for (int row = 0; row < shape.size( ); ++row)
|
if (tetrominoShape == TetrominoShape::I) {
|
||||||
for (int col = 0; col < shape[row].size( ); ++col)
|
if (angle == 90 || angle == 270) {
|
||||||
if (shape[row][col] != 0) {
|
for (int col = 0; col < shape[0].size( ); ++col) {
|
||||||
int lockedTetrominosX = x + col;
|
int lockedTetrominosX = x + col;
|
||||||
int lockedTetrominosY = y + row;
|
int lockedTetrominosY = y;
|
||||||
if (lockedTetrominosY >= 0 && lockedTetrominosX < height) {
|
|
||||||
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = 1;
|
if (lockedTetrominosY >= 0 && lockedTetrominosX >= 0 && lockedTetrominosX < width) {
|
||||||
|
if (col == 0) {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(TetrominoShape::I_ENDR) + 1;
|
||||||
|
} else if (col == 3) {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(TetrominoShape::I_STARTR) + 1;
|
||||||
|
} else {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(TetrominoShape::I_MIDR) + 1;
|
||||||
|
}
|
||||||
lockedColors[lockedTetrominosY][lockedTetrominosX] = currentTetromino->getColor( );
|
lockedColors[lockedTetrominosY][lockedTetrominosX] = currentTetromino->getColor( );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (int row = 0; row < shape.size( ); ++row) {
|
||||||
|
for (int col = 0; col < shape[row].size( ); ++col) {
|
||||||
|
if (shape[row][col] != 0) {
|
||||||
|
int lockedTetrominosX = x;
|
||||||
|
int lockedTetrominosY = y + row;
|
||||||
|
|
||||||
|
if (lockedTetrominosY >= 0 && lockedTetrominosX >= 0 && lockedTetrominosX < width && lockedTetrominosY < height) {
|
||||||
|
if (row == 0) {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(TetrominoShape::I_END) + 1;
|
||||||
|
} else if (row == 3) {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(TetrominoShape::I_START) + 1;
|
||||||
|
} else {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(TetrominoShape::I_MID) + 1;
|
||||||
|
}
|
||||||
|
lockedColors[lockedTetrominosY][lockedTetrominosX] = currentTetromino->getColor( );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int row = 0; row < shape.size( ); ++row) {
|
||||||
|
for (int col = 0; col < shape[row].size( ); ++col) {
|
||||||
|
if (shape[row][col] != 0) {
|
||||||
|
int lockedTetrominosX = x + col;
|
||||||
|
int lockedTetrominosY = y + row;
|
||||||
|
|
||||||
|
if (lockedTetrominosY >= 0 && lockedTetrominosX >= 0 && lockedTetrominosX < width && lockedTetrominosY < height) {
|
||||||
|
lockedTetrominos[lockedTetrominosY][lockedTetrominosX] = static_cast<int>(tetrominoShape) + 1;
|
||||||
|
lockedColors[lockedTetrominosY][lockedTetrominosX] = currentTetromino->getColor( );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameBoard::clearLines( ) {
|
void GameBoard::clearLines( ) {
|
||||||
for (int row = 0; row < height; row++)
|
for (int row = 0; row < height; row++) {
|
||||||
if (all_of(lockedTetrominos[row].begin( ), lockedTetrominos[row].end( ), [ ](int cell) {return cell != 0;})) {
|
if (all_of(lockedTetrominos[row].begin( ), lockedTetrominos[row].end( ), [ ](int cell) { return cell != 0; })) {
|
||||||
lockedTetrominos.erase(lockedTetrominos.begin( ) + row);
|
lockedTetrominos.erase(lockedTetrominos.begin( ) + row);
|
||||||
lockedTetrominos.insert(lockedTetrominos.begin( ), vector<int>(width, 0));
|
lockedColors.erase(lockedColors.begin( ) + row);
|
||||||
score += 100;
|
|
||||||
if ((score % 1000) == 0)
|
|
||||||
level++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
lockedTetrominos.insert(lockedTetrominos.begin( ), vector<int>(width, 0));
|
||||||
|
lockedColors.insert(lockedColors.begin( ), vector<SDL_Color>(width, { 0, 0, 0, 0 }));
|
||||||
|
|
||||||
|
score += 100;
|
||||||
|
if (score % 1000 == 0) {
|
||||||
|
level++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
void GameBoard::spawnNewTetromino( ) {
|
void GameBoard::spawnNewTetromino( ) {
|
||||||
random_device dev;
|
random_device dev;
|
||||||
mt19937 rng(dev( ));
|
mt19937 rng(dev( ));
|
||||||
uniform_int_distribution<mt19937::result_type> dist6(0, static_cast<int>(TetrominoShape::COUNT) - 1);
|
uniform_int_distribution<mt19937::result_type> dist6(0, static_cast<int>(TetrominoShape::COUNT) - 1);
|
||||||
TetrominoShape shape = static_cast<TetrominoShape>(dist6(rng));
|
TetrominoShape shape = static_cast<TetrominoShape>(dist6(rng));
|
||||||
currentTetromino = make_unique<Tetromino>(shape);
|
currentTetromino = make_unique<Tetromino>(shape);
|
||||||
currentTetromino->setTexture(shape);
|
|
||||||
currentTetromino->move(width / 2 - 1, 0);
|
currentTetromino->move(width / 2 - 1, 0);
|
||||||
|
|
||||||
if (checkCollision(*currentTetromino))
|
if (checkCollision(*currentTetromino))
|
||||||
@@ -117,4 +166,5 @@ void GameBoard::reset( ) {
|
|||||||
lockedColors.clear( );
|
lockedColors.clear( );
|
||||||
score = 0;
|
score = 0;
|
||||||
level = 1;
|
level = 1;
|
||||||
|
collision = false;
|
||||||
}
|
}
|
||||||
|
|||||||
263
src/Renderer.cpp
@@ -1,18 +1,27 @@
|
|||||||
#include "Renderer.hpp"
|
#include "Renderer.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Renderer::Renderer(shared_ptr<SDL_Renderer> renderer) : renderer(renderer), blockSize(30) {
|
Renderer::Renderer(shared_ptr<SDL_Renderer> renderer, int w, int h) : renderer(renderer), blockSize(30), windowHeight(h), windowWidth(w) {
|
||||||
setRenderer(renderer);
|
setRenderer(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::setRenderer(shared_ptr<SDL_Renderer> renderer) {
|
void Renderer::setRenderer(shared_ptr<SDL_Renderer> renderer) {
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
loadTexture("/home/crylia/Dokumente/git/tetris_sdl/assets/single.png", TetrominoShape::I);
|
loadTexture("assets/single.png", TetrisAssets::SINGLE);
|
||||||
loadTexture("/home/crylia/Dokumente/git/tetris_sdl/assets/single.png", TetrominoShape::J);
|
loadTexture("assets/border.png", TetrisAssets::BORDER);
|
||||||
loadTexture("/home/crylia/Dokumente/git/tetris_sdl/assets/single.png", TetrominoShape::L);
|
loadTexture("assets/J.png", TetrisAssets::J);
|
||||||
loadTexture("/home/crylia/Dokumente/git/tetris_sdl/assets/single.png", TetrominoShape::S);
|
loadTexture("assets/L.png", TetrisAssets::L);
|
||||||
loadTexture("/home/crylia/Dokumente/git/tetris_sdl/assets/single.png", TetrominoShape::O);
|
loadTexture("assets/T.png", TetrisAssets::T);
|
||||||
loadTexture("/home/crylia/Dokumente/git/tetris_sdl/assets/single.png", TetrominoShape::Z);
|
loadTexture("assets/O.png", TetrisAssets::O);
|
||||||
|
loadTexture("assets/S.png", TetrisAssets::S);
|
||||||
|
loadTexture("assets/Z.png", TetrisAssets::Z);
|
||||||
|
loadTexture("assets/I_MID.png", TetrisAssets::I);
|
||||||
|
loadTexture("assets/I_END.png", TetrisAssets::I_END);
|
||||||
|
loadTexture("assets/I_MID.png", TetrisAssets::I_MID);
|
||||||
|
loadTexture("assets/I_START.png", TetrisAssets::I_START);
|
||||||
|
loadTexture("assets/I_ENDR.png", TetrisAssets::I_ENDR);
|
||||||
|
loadTexture("assets/I_MIDR.png", TetrisAssets::I_MIDR);
|
||||||
|
loadTexture("assets/I_STARTR.png", TetrisAssets::I_STARTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderBoard(const GameBoard& gameBoard) {
|
void Renderer::renderBoard(const GameBoard& gameBoard) {
|
||||||
@@ -29,14 +38,22 @@ void Renderer::drawScoreboard(int score, int level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::drawGrid(const GameBoard& board) {
|
void Renderer::drawGrid(const GameBoard& board) {
|
||||||
SDL_SetRenderDrawColor(renderer.get( ), 100, 100, 100, 255);
|
int borderThickness = 10, gridThickness = 1;
|
||||||
|
int innerBorderThickness = blockSize / 4;
|
||||||
|
|
||||||
int w = board.getLockedTetrominos( )[0].size( ), h = board.getLockedTetrominos( ).size( );
|
int w = board.getLockedTetrominos( )[0].size( );
|
||||||
for (int x = 0; x <= w; ++x)
|
int h = board.getLockedTetrominos( ).size( );
|
||||||
SDL_RenderDrawLine(renderer.get( ), x * blockSize, 0, x * blockSize, h * blockSize);
|
|
||||||
|
|
||||||
for (int y = 0; y <= h; ++y)
|
int totalWidth = w * blockSize;
|
||||||
SDL_RenderDrawLine(renderer.get( ), 0, y * blockSize, w * blockSize, y * blockSize);
|
int totalHeight = h * blockSize;
|
||||||
|
|
||||||
|
for (int y = 0; y < (h + (innerBorderThickness * h)); ++y) {
|
||||||
|
SDL_Rect leftBlock = { offsetX - blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
renderTexture(TetrisAssets::BORDER, leftBlock.x, leftBlock.y - (innerBorderThickness * y + 1), leftBlock.w, leftBlock.h);
|
||||||
|
|
||||||
|
SDL_Rect rightBlock = { offsetX + totalWidth, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
renderTexture(TetrisAssets::BORDER, rightBlock.x, rightBlock.y - (innerBorderThickness * y + 1), rightBlock.w, rightBlock.h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::drawLockedBlocks(const GameBoard& gameBoard) {
|
void Renderer::drawLockedBlocks(const GameBoard& gameBoard) {
|
||||||
@@ -47,16 +64,19 @@ void Renderer::drawLockedBlocks(const GameBoard& gameBoard) {
|
|||||||
for (int col = 0; col < lockedTetrominos[row].size( ); ++col) {
|
for (int col = 0; col < lockedTetrominos[row].size( ); ++col) {
|
||||||
int blockType = lockedTetrominos[row][col];
|
int blockType = lockedTetrominos[row][col];
|
||||||
if (blockType != 0) {
|
if (blockType != 0) {
|
||||||
SDL_Rect block = { col * blockSize, row * blockSize, blockSize, blockSize };
|
SDL_Rect block = { offsetX + col * blockSize, offsetY + row * blockSize, blockSize, blockSize };
|
||||||
|
|
||||||
SDL_SetTextureBlendMode(textures[TetrominoShape::I], SDL_BLENDMODE_BLEND);
|
TetrominoShape shape = static_cast<TetrominoShape>(blockType - 1);
|
||||||
|
TetrisAssets asset = shapeToAsset(shape);
|
||||||
|
|
||||||
SDL_Color color = lockedColors[row][col];
|
if (textures[asset]) {
|
||||||
if (textures[TetrominoShape::I]) {
|
SDL_Color color = lockedColors[row][col];
|
||||||
SDL_SetTextureColorMod(textures[TetrominoShape::I], color.r, color.g, color.b);
|
SDL_SetTextureBlendMode(textures[asset], SDL_BLENDMODE_BLEND);
|
||||||
renderTexture(TetrominoShape::I, block.x, block.y, block.w, block.h);
|
SDL_SetTextureColorMod(textures[asset], color.r, color.g, color.b);
|
||||||
|
renderTexture(asset, block.x, block.y, block.w, block.h);
|
||||||
} else {
|
} else {
|
||||||
SDL_SetRenderDrawColor(renderer.get( ), color.r, color.g, color.b, 255);
|
SDL_Log("Texture not found for asset: %d", asset);
|
||||||
|
SDL_SetRenderDrawColor(renderer.get( ), 255, 0, 0, 255);
|
||||||
SDL_RenderFillRect(renderer.get( ), &block);
|
SDL_RenderFillRect(renderer.get( ), &block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,52 +84,203 @@ void Renderer::drawLockedBlocks(const GameBoard& gameBoard) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TetrisAssets Renderer::shapeToAsset(const TetrominoShape shape) {
|
||||||
|
switch (shape) {
|
||||||
|
case TetrominoShape::I:
|
||||||
|
return TetrisAssets::I;
|
||||||
|
case TetrominoShape::O:
|
||||||
|
return TetrisAssets::O;
|
||||||
|
case TetrominoShape::T:
|
||||||
|
return TetrisAssets::T;
|
||||||
|
case TetrominoShape::J:
|
||||||
|
return TetrisAssets::J;
|
||||||
|
case TetrominoShape::L:
|
||||||
|
return TetrisAssets::L;
|
||||||
|
case TetrominoShape::S:
|
||||||
|
return TetrisAssets::S;
|
||||||
|
case TetrominoShape::Z:
|
||||||
|
return TetrisAssets::Z;
|
||||||
|
case TetrominoShape::I_END:
|
||||||
|
return TetrisAssets::I_END;
|
||||||
|
case TetrominoShape::I_START:
|
||||||
|
return TetrisAssets::I_START;
|
||||||
|
case TetrominoShape::I_MID:
|
||||||
|
return TetrisAssets::I_MID;
|
||||||
|
case TetrominoShape::I_ENDR:
|
||||||
|
return TetrisAssets::I_ENDR;
|
||||||
|
case TetrominoShape::I_STARTR:
|
||||||
|
return TetrisAssets::I_STARTR;
|
||||||
|
case TetrominoShape::I_MIDR:
|
||||||
|
return TetrisAssets::I_MIDR;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::drawTetromino(const Tetromino& tetromino) {
|
void Renderer::drawTetromino(const Tetromino& tetromino) {
|
||||||
const auto& shape = tetromino.getShape( );
|
const auto& shape = tetromino.getShape( );
|
||||||
int x = tetromino.getX( ), y = tetromino.getY( );
|
int x = tetromino.getX( ), y = tetromino.getY( );
|
||||||
auto t = tetromino.getTexture( );
|
|
||||||
|
|
||||||
double angle = tetromino.getRotationAngle( );
|
double angle = tetromino.getRotationAngle( );
|
||||||
|
|
||||||
SDL_SetTextureBlendMode(textures[t], SDL_BLENDMODE_BLEND);
|
TetrominoShape tetrominoShape = tetromino.getShapeEnumn( );
|
||||||
SDL_Color color = tetromino.getColor( );
|
|
||||||
SDL_SetTextureColorMod(textures[t], color.r, color.g, color.b);
|
|
||||||
|
|
||||||
for (int row = 0; row < shape.size( ); ++row) {
|
SDL_SetTextureBlendMode(textures[shapeToAsset(tetrominoShape)], SDL_BLENDMODE_BLEND);
|
||||||
for (int col = 0; col < shape[row].size( ); ++col) {
|
SDL_Color color = tetromino.getColor( );
|
||||||
if (shape[row][col] != 0) {
|
SDL_SetTextureColorMod(textures[shapeToAsset(tetrominoShape)], color.r, color.g, color.b);
|
||||||
SDL_Rect destRect = { (x + col) * blockSize, (y + row) * blockSize, blockSize, blockSize };
|
|
||||||
SDL_Point center = { blockSize / 2, blockSize / 2 };
|
if (tetrominoShape == TetrominoShape::I) {
|
||||||
SDL_RenderCopyEx(renderer.get( ), textures[t], nullptr, &destRect, angle, ¢er, SDL_FLIP_NONE);
|
SDL_SetTextureColorMod(textures[TetrisAssets::I_START], color.r, color.g, color.b);
|
||||||
|
SDL_SetTextureColorMod(textures[TetrisAssets::I_MID], color.r, color.g, color.b);
|
||||||
|
SDL_SetTextureColorMod(textures[TetrisAssets::I_END], color.r, color.g, color.b);
|
||||||
|
|
||||||
|
if (angle == 90) {
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
SDL_Rect destRect = { offsetX + (x + i) * blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
SDL_RenderCopyEx(renderer.get( ), textures[TetrisAssets::I_MID], nullptr, &destRect, angle, nullptr, SDL_FLIP_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect startRect = { offsetX + (x + 0) * blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
SDL_RenderCopyEx(renderer.get( ), textures[TetrisAssets::I_START], nullptr, &startRect, angle, nullptr, SDL_FLIP_NONE);
|
||||||
|
|
||||||
|
SDL_Rect endRect = { offsetX + (x + 3) * blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
SDL_RenderCopyEx(renderer.get( ), textures[TetrisAssets::I_END], nullptr, &endRect, angle, nullptr, SDL_FLIP_NONE);
|
||||||
|
} else if (angle == 270) {
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
SDL_Rect destRect = { offsetX + (x + i) * blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
SDL_RenderCopyEx(renderer.get( ), textures[TetrisAssets::I_MID], nullptr, &destRect, angle, nullptr, SDL_FLIP_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect startRect = { offsetX + (x + 0) * blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
SDL_RenderCopyEx(renderer.get( ), textures[TetrisAssets::I_END], nullptr, &startRect, angle, nullptr, SDL_FLIP_NONE);
|
||||||
|
|
||||||
|
SDL_Rect endRect = { offsetX + (x + 3) * blockSize, offsetY + y * blockSize, blockSize, blockSize };
|
||||||
|
SDL_RenderCopyEx(renderer.get( ), textures[TetrisAssets::I_START], nullptr, &endRect, angle, nullptr, SDL_FLIP_NONE);
|
||||||
|
} else {
|
||||||
|
SDL_Rect destRect1 = { offsetX + (x + 0) * blockSize, offsetY + (y + 0) * blockSize, blockSize, blockSize };
|
||||||
|
SDL_Rect destRect2 = { offsetX + (x + 0) * blockSize, offsetY + (y + 1) * blockSize, blockSize, blockSize };
|
||||||
|
SDL_Rect destRect3 = { offsetX + (x + 0) * blockSize, offsetY + (y + 2) * blockSize, blockSize, blockSize };
|
||||||
|
SDL_Rect destRect4 = { offsetX + (x + 0) * blockSize, offsetY + (y + 3) * blockSize, blockSize, blockSize };
|
||||||
|
|
||||||
|
renderTexture(TetrisAssets::I_END, destRect1.x, destRect1.y, destRect1.w, destRect1.h);
|
||||||
|
renderTexture(TetrisAssets::I_MID, destRect2.x, destRect2.y, destRect2.w, destRect2.h);
|
||||||
|
renderTexture(TetrisAssets::I_MID, destRect3.x, destRect3.y, destRect3.w, destRect3.h);
|
||||||
|
renderTexture(TetrisAssets::I_START, destRect4.x, destRect4.y, destRect4.w, destRect4.h);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int row = 0; row < shape.size( ); ++row) {
|
||||||
|
for (int col = 0; col < shape[row].size( ); ++col) {
|
||||||
|
if (shape[row][col] != 0) {
|
||||||
|
SDL_Rect destRect = { offsetX + (x + col) * blockSize, offsetY + (y + row) * blockSize, blockSize, blockSize };
|
||||||
|
SDL_Point center = { blockSize / 2, blockSize / 2 };
|
||||||
|
SDL_RenderCopy(renderer.get( ), textures[shapeToAsset(tetrominoShape)], nullptr, &destRect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Renderer::loadTexture(const string& filePath, const TetrominoShape shape) {
|
bool Renderer::loadTexture(const string& filePath, const TetrisAssets asset) {
|
||||||
SDL_Texture* texture = IMG_LoadTexture(renderer.get( ), filePath.c_str( ));
|
SDL_Texture* texture = IMG_LoadTexture(renderer.get( ), filePath.c_str( ));
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
SDL_Log("Failed to load Texture: %s\n%s", filePath, SDL_GetError( ));
|
SDL_Log("Failed to load Texture: %s\n%s", filePath, SDL_GetError( ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
textures[shape] = texture;
|
textures[asset] = texture;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderTexture(const TetrominoShape shape, int x, int y, int width, int height) {
|
void Renderer::renderTexture(const TetrisAssets asset, int x, int y, int width, int height) {
|
||||||
SDL_Rect destRect{ x,y,width,height };
|
SDL_Rect destRect{ x,y,width,height };
|
||||||
SDL_RenderCopy(renderer.get( ), textures[shape], nullptr, &destRect);
|
SDL_RenderCopy(renderer.get( ), textures[asset], nullptr, &destRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderStartScreen( ) {
|
void Renderer::renderStartScreen( ) {
|
||||||
SDL_SetRenderDrawColor(renderer.get( ), 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer.get( ), 248, 248, 248, 255);
|
||||||
SDL_RenderClear(renderer.get( ));
|
SDL_RenderClear(renderer.get( ));
|
||||||
|
|
||||||
renderText("Tetris", 100, 100, 128, SDL_Color{ 200,200,200 });
|
int borderThickness = 20;
|
||||||
|
SDL_Rect borderRect = {
|
||||||
|
borderThickness,
|
||||||
|
borderThickness,
|
||||||
|
windowWidth - 2 * borderThickness,
|
||||||
|
windowHeight - 2 * borderThickness
|
||||||
|
};
|
||||||
|
SDL_SetRenderDrawColor(renderer.get( ), 0, 0, 0, 255);
|
||||||
|
SDL_RenderDrawRect(renderer.get( ), &borderRect);
|
||||||
|
|
||||||
|
SDL_Surface* titleSurface = IMG_Load("assets/title.png");
|
||||||
|
if (!titleSurface) {
|
||||||
|
SDL_Log("Failed to load title surface: %s", SDL_GetError( ));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto titleTexture = SDL_CreateTextureFromSurface(renderer.get( ), titleSurface);
|
||||||
|
SDL_FreeSurface(titleSurface);
|
||||||
|
if (!titleTexture) {
|
||||||
|
SDL_Log("Failed to create title texture: %s", SDL_GetError( ));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float titleScaleFactor = 0.5f;
|
||||||
|
int titleWidth = static_cast<int>(windowWidth * titleScaleFactor);
|
||||||
|
int titleHeight = static_cast<int>(titleWidth * 0.315f);
|
||||||
|
|
||||||
|
SDL_Rect titleRect = {
|
||||||
|
(windowWidth / 2) - (titleWidth / 2),
|
||||||
|
static_cast<int>(windowHeight * 0.2f),
|
||||||
|
titleWidth,
|
||||||
|
titleHeight
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer.get( ), titleTexture, nullptr, &titleRect);
|
||||||
|
SDL_DestroyTexture(titleTexture);
|
||||||
|
|
||||||
|
SDL_Surface* titleBg = IMG_Load("assets/title_bg.png");
|
||||||
|
if (!titleBg) {
|
||||||
|
SDL_Log("Failed to load background surface: %s", SDL_GetError( ));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto titleBgTexture = SDL_CreateTextureFromSurface(renderer.get( ), titleBg);
|
||||||
|
int originalBgWidth = titleBg->w;
|
||||||
|
int originalBgHeight = titleBg->h;
|
||||||
|
SDL_FreeSurface(titleBg);
|
||||||
|
if (!titleBgTexture) {
|
||||||
|
SDL_Log("Failed to create background texture: %s", SDL_GetError( ));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float bgScaleFactor = 0.8f;
|
||||||
|
int titleBgWidth = static_cast<int>(windowWidth * bgScaleFactor);
|
||||||
|
int titleBgHeight = static_cast<int>(titleBgWidth * (static_cast<float>(originalBgHeight) / originalBgWidth));
|
||||||
|
if (titleBgHeight > windowHeight * 0.4f) {
|
||||||
|
titleBgHeight = static_cast<int>(windowHeight * 0.4f);
|
||||||
|
titleBgWidth = static_cast<int>(titleBgHeight * (static_cast<float>(originalBgWidth) / originalBgHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect titleBgRect = {
|
||||||
|
(windowWidth / 2) - (titleBgWidth / 2),
|
||||||
|
static_cast<int>(windowHeight * 0.5f),
|
||||||
|
titleBgWidth,
|
||||||
|
titleBgHeight
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer.get( ), titleBgTexture, nullptr, &titleBgRect);
|
||||||
|
SDL_DestroyTexture(titleBgTexture);
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
TTF_Font* font = TTF_OpenFont("assets/tetris-gb.ttf", 16);
|
||||||
|
TTF_SizeText(font, "PRESS START", &w, &h);
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
|
||||||
|
renderText("press G to start", (windowWidth / 2) - (w / 2), windowHeight - 100, 16, SDL_Color{ 0, 0, 0 });
|
||||||
|
|
||||||
SDL_RenderPresent(renderer.get( ));
|
SDL_RenderPresent(renderer.get( ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Renderer::renderGameOver(int score, int level) {
|
void Renderer::renderGameOver(int score, int level) {
|
||||||
SDL_SetRenderDrawColor(renderer.get( ), 0, 0, 0, 128);
|
SDL_SetRenderDrawColor(renderer.get( ), 0, 0, 0, 128);
|
||||||
SDL_RenderClear(renderer.get( ));
|
SDL_RenderClear(renderer.get( ));
|
||||||
@@ -123,7 +294,7 @@ void Renderer::renderGameOver(int score, int level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderText(string text, int x, int y, int size, SDL_Color color) {
|
void Renderer::renderText(string text, int x, int y, int size, SDL_Color color) {
|
||||||
TTF_Font* font = TTF_OpenFont("/usr/share/fonts/TTF/OpenSans-Regular.ttf", size);
|
TTF_Font* font = TTF_OpenFont("assets/tetris-gb.ttf", size);
|
||||||
SDL_Surface* surface = TTF_RenderText_Solid(font, text.c_str( ), color);
|
SDL_Surface* surface = TTF_RenderText_Solid(font, text.c_str( ), color);
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
SDL_Log("Failed to create surface: %s", TTF_GetError( ));
|
SDL_Log("Failed to create surface: %s", TTF_GetError( ));
|
||||||
@@ -149,3 +320,21 @@ void Renderer::renderText(string text, int x, int y, int size, SDL_Color color)
|
|||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
TTF_CloseFont(font);
|
TTF_CloseFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int Renderer::getBlockSize( ) const { return blockSize; }
|
||||||
|
|
||||||
|
void Renderer::setBlockSize(int newBlockSize) { blockSize = newBlockSize; }
|
||||||
|
|
||||||
|
void Renderer::setOffset(int newX, int newY) {
|
||||||
|
offsetX = newX;
|
||||||
|
offsetY = newY;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int Renderer::getOffsetX( ) const { return offsetX; }
|
||||||
|
|
||||||
|
const int Renderer::getOffsetY( ) const { return offsetY; }
|
||||||
|
|
||||||
|
void Renderer::setWindowSize(int w, int h) {
|
||||||
|
windowWidth = w;
|
||||||
|
windowHeight = h;
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,24 @@ extern "C" {
|
|||||||
|
|
||||||
#include "GameBoard.hpp"
|
#include "GameBoard.hpp"
|
||||||
|
|
||||||
|
enum class TetrisAssets {
|
||||||
|
BORDER,
|
||||||
|
SINGLE,
|
||||||
|
I,
|
||||||
|
I_MID,
|
||||||
|
I_START,
|
||||||
|
I_END,
|
||||||
|
I_MIDR,
|
||||||
|
I_STARTR,
|
||||||
|
I_ENDR,
|
||||||
|
J,
|
||||||
|
L,
|
||||||
|
O,
|
||||||
|
S,
|
||||||
|
Z,
|
||||||
|
T,
|
||||||
|
};
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
private:
|
private:
|
||||||
void drawGrid(const GameBoard& gameBoard);
|
void drawGrid(const GameBoard& gameBoard);
|
||||||
@@ -19,19 +37,34 @@ private:
|
|||||||
void drawTetromino(const Tetromino& tetromino);
|
void drawTetromino(const Tetromino& tetromino);
|
||||||
void drawScoreboard(int score, int level);
|
void drawScoreboard(int score, int level);
|
||||||
|
|
||||||
shared_ptr<SDL_Renderer> renderer;
|
TetrisAssets shapeToAsset(const TetrominoShape shape);
|
||||||
int blockSize;
|
|
||||||
|
|
||||||
unordered_map<TetrominoShape, SDL_Texture*> textures;
|
shared_ptr<SDL_Renderer> renderer;
|
||||||
|
|
||||||
|
int blockSize;
|
||||||
|
int offsetX;
|
||||||
|
int offsetY;
|
||||||
|
int screenSpacing = 50;
|
||||||
|
int windowHeight = 0;
|
||||||
|
int windowWidth = 0;
|
||||||
|
|
||||||
|
unordered_map<TetrisAssets, SDL_Texture*> textures;
|
||||||
public:
|
public:
|
||||||
Renderer(shared_ptr<SDL_Renderer> renderer);
|
Renderer(shared_ptr<SDL_Renderer> renderer, int w, int h);
|
||||||
|
|
||||||
void setRenderer(shared_ptr<SDL_Renderer> renderer);
|
void setRenderer(shared_ptr<SDL_Renderer> renderer);
|
||||||
void renderBoard(const GameBoard& gb);
|
void renderBoard(const GameBoard& gb);
|
||||||
|
|
||||||
bool loadTexture(const string& filePath, const TetrominoShape shape);
|
bool loadTexture(const string& filePath, const TetrisAssets shape);
|
||||||
void renderTexture(const TetrominoShape shape, int x, int y, int width, int height);
|
void renderTexture(const TetrisAssets shape, int x, int y, int width, int height);
|
||||||
void renderStartScreen( );
|
void renderStartScreen( );
|
||||||
void renderGameOver(int score, int level);
|
void renderGameOver(int score, int level);
|
||||||
void renderText(string text, int x, int y, int size, SDL_Color color);
|
void renderText(string text, int x, int y, int size, SDL_Color color);
|
||||||
|
|
||||||
|
const int getBlockSize( ) const;
|
||||||
|
void setBlockSize(int newBlockSize);
|
||||||
|
void setOffset(int newX, int newY);
|
||||||
|
const int getOffsetX( ) const;
|
||||||
|
const int getOffsetY( ) const;
|
||||||
|
void setWindowSize(int w, int h);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "Tetromino.hpp"
|
#include "Tetromino.hpp"
|
||||||
#include "GameBoard.hpp"
|
#include "GameBoard.hpp"
|
||||||
|
#include <iostream>
|
||||||
Tetromino::Tetromino(TetrominoShape shape) : x(0), y(0) {
|
Tetromino::Tetromino(TetrominoShape shape) : x(0), y(0), textureShape(shape) {
|
||||||
initializeShape(shape);
|
initializeShape(shape);
|
||||||
currentRotationState = 1;
|
currentRotationState = 1;
|
||||||
|
|
||||||
@@ -16,29 +16,44 @@ Tetromino::Tetromino(TetrominoShape shape) : x(0), y(0) {
|
|||||||
|
|
||||||
switch (dist6(rng)) {
|
switch (dist6(rng)) {
|
||||||
case 0:
|
case 0:
|
||||||
color.r = 255;
|
color.r = 0;
|
||||||
|
color.g = 191;
|
||||||
|
color.b = 255;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
color.g = 255;
|
color.r = 255;
|
||||||
|
color.g = 215;
|
||||||
|
color.b = 0;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
color.b = 255;
|
color.r = 138;
|
||||||
|
color.g = 43;
|
||||||
|
color.b = 226;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
color.r = 255;
|
color.r = 0;
|
||||||
color.g = 255;
|
color.g = 204;
|
||||||
|
color.b = 102;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
color.g = 255;
|
color.r = 255;
|
||||||
color.b = 255;
|
color.g = 69;
|
||||||
|
color.b = 0;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
color.r = 30;
|
||||||
|
color.g = 144;
|
||||||
color.b = 255;
|
color.b = 255;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
color.r = 255;
|
color.r = 255;
|
||||||
|
color.g = 140;
|
||||||
|
color.b = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tetromino::initializeShape(TetrominoShape s) {
|
void Tetromino::initializeShape(TetrominoShape s) {
|
||||||
@@ -61,6 +76,9 @@ void Tetromino::initializeShape(TetrominoShape s) {
|
|||||||
case TetrominoShape::L:
|
case TetrominoShape::L:
|
||||||
shape = { {0, 0, 1}, {1, 1, 1} };
|
shape = { {0, 0, 1}, {1, 1, 1} };
|
||||||
break;
|
break;
|
||||||
|
case TetrominoShape::T:
|
||||||
|
shape = { {1, 1, 1}, {0, 1, 0} };
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
shape = { {0} };
|
shape = { {0} };
|
||||||
break;
|
break;
|
||||||
@@ -102,11 +120,9 @@ double Tetromino::getRotationAngle( ) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const vector<vector<int>>& Tetromino::getShape( ) const { return shape; }
|
const vector<vector<int>>& Tetromino::getShape( ) const { return shape; }
|
||||||
|
const TetrominoShape Tetromino::getShapeEnumn( ) const { return textureShape; }
|
||||||
|
|
||||||
int Tetromino::getX( ) const { return x; }
|
int Tetromino::getX( ) const { return x; }
|
||||||
int Tetromino::getY( ) const { return y; }
|
int Tetromino::getY( ) const { return y; }
|
||||||
|
|
||||||
void Tetromino::setTexture(const TetrominoShape shape) { this->textureShape = shape; }
|
|
||||||
const TetrominoShape Tetromino::getTexture( ) const { return textureShape; }
|
|
||||||
|
|
||||||
SDL_Color Tetromino::getColor( ) const { return color; }
|
SDL_Color Tetromino::getColor( ) const { return color; }
|
||||||
|
|||||||
@@ -17,7 +17,14 @@ enum class TetrominoShape {
|
|||||||
S,
|
S,
|
||||||
Z,
|
Z,
|
||||||
J,
|
J,
|
||||||
COUNT //Used to know the ammount of shapes
|
T,
|
||||||
|
COUNT, //Used to know the ammount of shapes
|
||||||
|
I_END,
|
||||||
|
I_START,
|
||||||
|
I_MID,
|
||||||
|
I_ENDR,
|
||||||
|
I_STARTR,
|
||||||
|
I_MIDR,
|
||||||
};
|
};
|
||||||
|
|
||||||
class GameBoard;
|
class GameBoard;
|
||||||
@@ -42,10 +49,9 @@ public:
|
|||||||
double getRotationAngle( ) const;
|
double getRotationAngle( ) const;
|
||||||
|
|
||||||
const vector<vector<int>>& getShape( ) const;
|
const vector<vector<int>>& getShape( ) const;
|
||||||
|
const TetrominoShape getShapeEnumn( ) const;
|
||||||
int getX( ) const;
|
int getX( ) const;
|
||||||
int getY( ) const;
|
int getY( ) const;
|
||||||
|
|
||||||
void setTexture(const TetrominoShape textureName);
|
|
||||||
const TetrominoShape getTexture( ) const;
|
|
||||||
SDL_Color getColor( ) const;
|
SDL_Color getColor( ) const;
|
||||||
};
|
};
|
||||||
|
|||||||