Tetris: add block texture

This commit is contained in:
2020-09-29 18:22:26 +02:00
parent eb60c88dac
commit 7621dc8dd4
8 changed files with 61 additions and 27 deletions
+22 -7
View File
@@ -15,6 +15,9 @@ public:
_index = index;
pieces_bag[_index]--;
_scene = scene;
setColors();
if(g_show_3d)
setTexture("block.png");
}
TetrisBlock( const TetrisBlock &other ) : TetrisBlock(other.getDoubleRect().first.first,other.getDoubleRect().first.second,other.getDoubleRect().second.first,other.getDoubleRect().second.second,other.getRenderer(), other.getColor(), true, other._index, other._scene, other.pieces_bag) {}
~TetrisBlock() {
@@ -40,14 +43,21 @@ public:
virtual void specialAction( int code ) override {
switch(code) {
case PIECE_ACTION_UPDATE_COLOR: {
auto piece_name = getPieceName();
setColor(colors[piece_name]);
setOutlineColor(colors[piece_name + "_out"]);
setColors();
if(g_show_3d)
setTexture("block.png");
else
unsetTexture();
}
default:
break;
}
}
void turnIntoShadow() {
setId(SHADOW_ID);
_index = PIECE_SHADOW;
setColors();
}
private:
std::string getPieceName() {
@@ -66,11 +76,18 @@ private:
return "piece_L_left";
case PIECE_Z_LEFT:
return "piece_Z_left";
case PIECE_SHADOW:
return "shadow";
default:
break;
}
return "";
}
void setColors() {
auto piece_name = getPieceName();
setColor(colors[piece_name]);
setOutlineColor(colors[piece_name + "_out"]);
}
int _index = 0;
std::shared_ptr<SDLPP::Scene> _scene;
std::vector<int> &pieces_bag;
@@ -200,10 +217,8 @@ public:
}
void turnIntoShadow() {
for(auto &block : getObjects() ) {
block->setId(SHADOW_ID);
block->setColor(colors["shadow"]);
}
for(auto &block : getObjects() )
block->turnIntoShadow();
setHidden(!g_show_shadow);
}
std::shared_ptr<TetrisPiece> copySelf() {