Tetris: formatting
This commit is contained in:
parent
2f20661b5b
commit
594316dcea
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
std::shared_ptr< SDLPP::Texture > TetrisBlock::block_texture = nullptr;
|
std::shared_ptr< SDLPP::Texture > TetrisBlock::block_texture = nullptr;
|
||||||
#ifdef FEATURE
|
#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
|
#endif
|
||||||
|
|
||||||
TetrisBlock::TetrisBlock( double x, double y, double w, double h,
|
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 ) {
|
if ( TetrisBlock::block_texture == nullptr ) {
|
||||||
TetrisBlock::block_texture =
|
TetrisBlock::block_texture =
|
||||||
std::make_shared< SDLPP::Texture >( renderer, "block.png" );
|
std::make_shared< SDLPP::Texture >( renderer, "block.png" );
|
||||||
TetrisBlock::block_texture->setAlpha(240);
|
TetrisBlock::block_texture->setAlpha( 240 );
|
||||||
}
|
}
|
||||||
if ( g_show_3d )
|
if ( g_show_3d )
|
||||||
#ifdef FEATURE
|
#ifdef FEATURE
|
||||||
setTexture( TetrisBlock::block_texture, 0, 0, 125, 125 );
|
setTexture( TetrisBlock::block_texture, 0, 0, 125, 125 );
|
||||||
setAnimationFrames( blockanim );
|
setAnimationFrames( blockanim );
|
||||||
setAnimationSpeed(4);
|
setAnimationSpeed( 4 );
|
||||||
#else
|
#else
|
||||||
setTexture( TetrisBlock::block_texture );
|
setTexture( TetrisBlock::block_texture );
|
||||||
#endif
|
#endif
|
||||||
@ -154,20 +157,18 @@ void TetrisPiece::rotate() {
|
|||||||
auto &positions = pieces_rel_position[i];
|
auto &positions = pieces_rel_position[i];
|
||||||
auto piece_position = piece->getPos();
|
auto piece_position = piece->getPos();
|
||||||
original_pos[i] = piece_position;
|
original_pos[i] = piece_position;
|
||||||
piece_position += { positions[0] * BLOCK_SIZE -
|
piece_position +=
|
||||||
positions[1] * BLOCK_SIZE,
|
{ positions[0] * BLOCK_SIZE - positions[1] * BLOCK_SIZE,
|
||||||
positions[2] * BLOCK_SIZE -
|
positions[2] * BLOCK_SIZE - positions[3] * BLOCK_SIZE };
|
||||||
positions[3] * BLOCK_SIZE };
|
|
||||||
auto bottom = positions[3];
|
auto bottom = positions[3];
|
||||||
auto top = positions[2];
|
auto top = positions[2];
|
||||||
positions[3] = positions[1];
|
positions[3] = positions[1];
|
||||||
positions[2] = positions[0];
|
positions[2] = positions[0];
|
||||||
positions[1] = top;
|
positions[1] = top;
|
||||||
positions[0] = bottom;
|
positions[0] = bottom;
|
||||||
piece_position += { positions[1] * BLOCK_SIZE -
|
piece_position +=
|
||||||
positions[0] * BLOCK_SIZE,
|
{ positions[1] * BLOCK_SIZE - positions[0] * BLOCK_SIZE,
|
||||||
positions[3] * BLOCK_SIZE -
|
positions[3] * BLOCK_SIZE - positions[2] * BLOCK_SIZE };
|
||||||
positions[2] * BLOCK_SIZE };
|
|
||||||
piece->setPos( piece_position );
|
piece->setPos( piece_position );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,11 +208,11 @@ void TetrisPiece::setPos( const std::pair< double, double > &pos ) {
|
|||||||
setPos( pos.first, pos.second );
|
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() );
|
setPos( vec.getX(), vec.getY() );
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLPP::Vec2D<double> TetrisPiece::getPos() {
|
SDLPP::Vec2D< double > TetrisPiece::getPos() {
|
||||||
auto &piece = pieces[0];
|
auto &piece = pieces[0];
|
||||||
auto &relpositions = pieces_rel_position[0];
|
auto &relpositions = pieces_rel_position[0];
|
||||||
auto pos = piece->getPos();
|
auto pos = piece->getPos();
|
||||||
@ -260,7 +261,7 @@ bool TetrisPiece::isRight( const SDLPP::RenderObject &block ) const {
|
|||||||
void TetrisPiece::movePiece( double x, double y ) {
|
void TetrisPiece::movePiece( double x, double y ) {
|
||||||
for ( auto &block : getObjects() ) {
|
for ( auto &block : getObjects() ) {
|
||||||
auto pos = block->getPos();
|
auto pos = block->getPos();
|
||||||
block->setPos( pos + SDLPP::Vec2D<double>( x, y ) );
|
block->setPos( pos + SDLPP::Vec2D< double >( x, y ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ public:
|
|||||||
std::vector< std::shared_ptr< TetrisBlock > > &getObjects();
|
std::vector< std::shared_ptr< TetrisBlock > > &getObjects();
|
||||||
void setPos( double x, double y );
|
void setPos( double x, double y );
|
||||||
void setPos( const std::pair< double, double > &pos );
|
void setPos( const std::pair< double, double > &pos );
|
||||||
void setPos( const SDLPP::Vec2D<double> &vec );
|
void setPos( const SDLPP::Vec2D< double > &vec );
|
||||||
SDLPP::Vec2D<double> getPos();
|
SDLPP::Vec2D< double > getPos();
|
||||||
void clear();
|
void clear();
|
||||||
void startDescend();
|
void startDescend();
|
||||||
void stopDescend();
|
void stopDescend();
|
||||||
@ -70,7 +70,7 @@ private:
|
|||||||
|
|
||||||
std::vector< std::vector< int > > pieces_rel_position;
|
std::vector< std::vector< int > > pieces_rel_position;
|
||||||
std::vector< std::shared_ptr< TetrisBlock > > pieces;
|
std::vector< std::shared_ptr< TetrisBlock > > pieces;
|
||||||
std::vector< SDLPP::Vec2D<double> > original_pos;
|
std::vector< SDLPP::Vec2D< double > > original_pos;
|
||||||
bool descend = false;
|
bool descend = false;
|
||||||
int userMovement = 0;
|
int userMovement = 0;
|
||||||
bool rotate_allowed = true;
|
bool rotate_allowed = true;
|
||||||
|
@ -98,7 +98,7 @@ check_floor:
|
|||||||
g_cur_object->movePiece( 0, -BLOCK_SIZE );
|
g_cur_object->movePiece( 0, -BLOCK_SIZE );
|
||||||
for ( auto &block : g_cur_object->getObjects() ) {
|
for ( auto &block : g_cur_object->getObjects() ) {
|
||||||
if ( scene->getCollisions( *block, { GAME_OVER } ).size() > 0 ) {
|
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_active_scenes.push_back( g_game_over_scene );
|
||||||
g_input_functions.push_back( gameOverSceneInput );
|
g_input_functions.push_back( gameOverSceneInput );
|
||||||
#ifdef FEATURE
|
#ifdef FEATURE
|
||||||
|
@ -54,5 +54,5 @@ std::vector< std::shared_ptr< TetrisPiece > ( * )(
|
|||||||
std::shared_ptr< SDLPP::Font > g_font{};
|
std::shared_ptr< SDLPP::Font > g_font{};
|
||||||
std::shared_ptr< SDLPP::FontConfiguration > g_font_config{};
|
std::shared_ptr< SDLPP::FontConfiguration > g_font_config{};
|
||||||
|
|
||||||
std::vector<std::shared_ptr<SDLPP::Scene>> g_update_scenes{};
|
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::RenderObject > > g_update_objects{};
|
||||||
|
@ -57,7 +57,7 @@ extern std::vector< std::shared_ptr< TetrisPiece > ( * )(
|
|||||||
extern std::shared_ptr< SDLPP::Font > g_font;
|
extern std::shared_ptr< SDLPP::Font > g_font;
|
||||||
extern std::shared_ptr< SDLPP::FontConfiguration > g_font_config;
|
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::Scene > > g_update_scenes;
|
||||||
extern std::vector<std::shared_ptr<SDLPP::RenderObject>> g_update_objects;
|
extern std::vector< std::shared_ptr< SDLPP::RenderObject > > g_update_objects;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user