#ifndef TETRIS_CUSTOM_CLASSES_H #define TETRIS_CUSTOM_CLASSES_H #include "../sdlpp/sdlpp.hpp" #include "config.hpp" class TetrisBlock : public SDLPP::RectangleRender { public: TetrisBlock() = delete; TetrisBlock( double x, double y, double w, double h, const std::shared_ptr< SDLPP::Renderer > &r, const std::string &img_or_color, bool is_polygon, int index, std::shared_ptr< SDLPP::Scene > scene, std::vector< int > &bag ); TetrisBlock( const TetrisBlock &other ); ~TetrisBlock(); virtual std::shared_ptr< RenderObject > copySelf() override; virtual void copyTo( std::shared_ptr< RenderObject > other ) override; std::shared_ptr< TetrisBlock > copyInScene(); bool isSamePos( const SDLPP::RenderObject &other ) const; virtual void specialAction( int code ) override; void turnIntoShadow(); private: std::string getPieceName(); void setColors(); int _index = 0; std::shared_ptr< SDLPP::Scene > _scene; std::vector< int > &pieces_bag; static std::shared_ptr< SDLPP::Texture > block_texture; }; class TetrisPiece { public: TetrisPiece(); void addPiece( std::shared_ptr< TetrisBlock > piece, int x, int y ); void rotate(); void revert(); 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 clear(); void startDescend(); void stopDescend(); void startMovement(); void stopMovement(); bool isDescending(); bool isMoving(); bool isLeft( const SDLPP::RenderObject &block ) const; bool isRight( const SDLPP::RenderObject &block ) const; void movePiece( double x, double y ); void disableRotation(); void turnIntoShadow(); std::shared_ptr< TetrisPiece > copySelf(); void destroy(); void addMovement( int x, int y ); std::pair< int, int > getMovement() const; void setHidden( bool hidden ); bool getHidden(); private: bool isPosition( const SDLPP::RenderObject &block, int pos ) const; void resetBlock( int index, std::shared_ptr< TetrisBlock > piece ); void addBlockInPos( std::shared_ptr< TetrisBlock > piece, const std::vector< int > &relpos ); std::vector< std::vector< int > > pieces_rel_position; std::vector< std::shared_ptr< TetrisBlock > > pieces; std::vector< SDLPP::Vec2D< double > > original_pos; bool descend = false; int userMovement = 0; bool rotate_allowed = true; std::pair< int, int > movement = { 0, 0 }; bool _hidden = false; }; #endif