Tetris: formatting

This commit is contained in:
2021-03-13 18:37:23 +01:00
parent 2f20661b5b
commit 594316dcea
5 changed files with 23 additions and 22 deletions
+15 -14
View File
@@ -2,7 +2,10 @@
std::shared_ptr< SDLPP::Texture > TetrisBlock::block_texture = nullptr;
#ifdef FEATURE
const std::vector<SDL_Rect> blockanim = {{0,0,125,125}, {125,0,250,125}, {125,125,250,250}, {0,125,125,250}};
const std::vector< SDL_Rect > blockanim = { { 0, 0, 125, 125 },
{ 125, 0, 250, 125 },
{ 125, 125, 250, 250 },
{ 0, 125, 125, 250 } };
#endif
TetrisBlock::TetrisBlock( double x, double y, double w, double h,
@@ -19,13 +22,13 @@ TetrisBlock::TetrisBlock( double x, double y, double w, double h,
if ( TetrisBlock::block_texture == nullptr ) {
TetrisBlock::block_texture =
std::make_shared< SDLPP::Texture >( renderer, "block.png" );
TetrisBlock::block_texture->setAlpha(240);
TetrisBlock::block_texture->setAlpha( 240 );
}
if ( g_show_3d )
#ifdef FEATURE
setTexture( TetrisBlock::block_texture, 0, 0, 125, 125 );
setAnimationFrames( blockanim );
setAnimationSpeed(4);
setAnimationSpeed( 4 );
#else
setTexture( TetrisBlock::block_texture );
#endif
@@ -154,20 +157,18 @@ void TetrisPiece::rotate() {
auto &positions = pieces_rel_position[i];
auto piece_position = piece->getPos();
original_pos[i] = piece_position;
piece_position += { positions[0] * BLOCK_SIZE -
positions[1] * BLOCK_SIZE,
positions[2] * BLOCK_SIZE -
positions[3] * BLOCK_SIZE };
piece_position +=
{ positions[0] * BLOCK_SIZE - positions[1] * BLOCK_SIZE,
positions[2] * BLOCK_SIZE - positions[3] * BLOCK_SIZE };
auto bottom = positions[3];
auto top = positions[2];
positions[3] = positions[1];
positions[2] = positions[0];
positions[1] = top;
positions[0] = bottom;
piece_position += { positions[1] * BLOCK_SIZE -
positions[0] * BLOCK_SIZE,
positions[3] * BLOCK_SIZE -
positions[2] * BLOCK_SIZE };
piece_position +=
{ positions[1] * BLOCK_SIZE - positions[0] * BLOCK_SIZE,
positions[3] * BLOCK_SIZE - positions[2] * BLOCK_SIZE };
piece->setPos( piece_position );
}
}
@@ -207,11 +208,11 @@ void TetrisPiece::setPos( const std::pair< double, double > &pos ) {
setPos( pos.first, pos.second );
}
void TetrisPiece::setPos( const SDLPP::Vec2D<double> &vec ) {
void TetrisPiece::setPos( const SDLPP::Vec2D< double > &vec ) {
setPos( vec.getX(), vec.getY() );
}
SDLPP::Vec2D<double> TetrisPiece::getPos() {
SDLPP::Vec2D< double > TetrisPiece::getPos() {
auto &piece = pieces[0];
auto &relpositions = pieces_rel_position[0];
auto pos = piece->getPos();
@@ -260,7 +261,7 @@ bool TetrisPiece::isRight( const SDLPP::RenderObject &block ) const {
void TetrisPiece::movePiece( double x, double y ) {
for ( auto &block : getObjects() ) {
auto pos = block->getPos();
block->setPos( pos + SDLPP::Vec2D<double>( x, y ) );
block->setPos( pos + SDLPP::Vec2D< double >( x, y ) );
}
}