Tetris: formatting

This commit is contained in:
zvon 2021-03-13 18:37:23 +01:00
parent 2f20661b5b
commit 594316dcea
5 changed files with 23 additions and 22 deletions

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 ) );
}
}

View File

@ -40,8 +40,8 @@ public:
std::vector< std::shared_ptr< TetrisBlock > > &getObjects();
void setPos( double x, double y );
void setPos( const std::pair< double, double > &pos );
void setPos( const SDLPP::Vec2D<double> &vec );
SDLPP::Vec2D<double> getPos();
void setPos( const SDLPP::Vec2D< double > &vec );
SDLPP::Vec2D< double > getPos();
void clear();
void startDescend();
void stopDescend();
@ -70,7 +70,7 @@ private:
std::vector< std::vector< int > > pieces_rel_position;
std::vector< std::shared_ptr< TetrisBlock > > pieces;
std::vector< SDLPP::Vec2D<double> > original_pos;
std::vector< SDLPP::Vec2D< double > > original_pos;
bool descend = false;
int userMovement = 0;
bool rotate_allowed = true;

View File

@ -98,7 +98,7 @@ check_floor:
g_cur_object->movePiece( 0, -BLOCK_SIZE );
for ( auto &block : g_cur_object->getObjects() ) {
if ( scene->getCollisions( *block, { GAME_OVER } ).size() > 0 ) {
g_update_scenes.push_back(g_game_over_scene);
g_update_scenes.push_back( g_game_over_scene );
g_active_scenes.push_back( g_game_over_scene );
g_input_functions.push_back( gameOverSceneInput );
#ifdef FEATURE

View File

@ -54,5 +54,5 @@ std::vector< std::shared_ptr< TetrisPiece > ( * )(
std::shared_ptr< SDLPP::Font > g_font{};
std::shared_ptr< SDLPP::FontConfiguration > g_font_config{};
std::vector<std::shared_ptr<SDLPP::Scene>> g_update_scenes{};
std::vector<std::shared_ptr<SDLPP::RenderObject>> g_update_objects{};
std::vector< std::shared_ptr< SDLPP::Scene > > g_update_scenes{};
std::vector< std::shared_ptr< SDLPP::RenderObject > > g_update_objects{};

View File

@ -57,7 +57,7 @@ extern std::vector< std::shared_ptr< TetrisPiece > ( * )(
extern std::shared_ptr< SDLPP::Font > g_font;
extern std::shared_ptr< SDLPP::FontConfiguration > g_font_config;
extern std::vector<std::shared_ptr<SDLPP::Scene>> g_update_scenes;
extern std::vector<std::shared_ptr<SDLPP::RenderObject>> g_update_objects;
extern std::vector< std::shared_ptr< SDLPP::Scene > > g_update_scenes;
extern std::vector< std::shared_ptr< SDLPP::RenderObject > > g_update_objects;
#endif