2020-09-11 19:34:43 +00:00
|
|
|
#ifndef TETRIS_CUSTOM_CLASSES_H
|
|
|
|
#define TETRIS_CUSTOM_CLASSES_H
|
|
|
|
|
2020-11-21 19:58:52 +00:00
|
|
|
#include "../sdlpp/sdlpp.hpp"
|
2020-09-11 19:34:43 +00:00
|
|
|
#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,
|
2020-11-21 19:58:52 +00:00
|
|
|
const std::string &img_or_color, bool is_polygon, int index,
|
|
|
|
std::shared_ptr< SDLPP::Scene > scene,
|
2021-01-30 21:18:15 +00:00
|
|
|
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();
|
2020-09-11 19:34:43 +00:00
|
|
|
|
|
|
|
private:
|
2021-01-30 21:18:15 +00:00
|
|
|
std::string getPieceName();
|
|
|
|
void setColors();
|
|
|
|
|
2020-09-11 19:34:43 +00:00
|
|
|
int _index = 0;
|
2020-11-21 19:58:52 +00:00
|
|
|
std::shared_ptr< SDLPP::Scene > _scene;
|
|
|
|
std::vector< int > &pieces_bag;
|
2021-01-30 21:18:15 +00:00
|
|
|
static std::shared_ptr< SDLPP::Texture > block_texture;
|
2020-09-11 19:34:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TetrisPiece {
|
|
|
|
public:
|
2021-01-30 21:18:15 +00:00
|
|
|
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 );
|
2021-03-13 17:37:23 +00:00
|
|
|
void setPos( const SDLPP::Vec2D< double > &vec );
|
|
|
|
SDLPP::Vec2D< double > getPos();
|
2021-01-30 21:18:15 +00:00
|
|
|
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();
|
2020-09-11 19:34:43 +00:00
|
|
|
|
2021-01-30 21:18:15 +00:00
|
|
|
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();
|
2020-09-11 19:34:43 +00:00
|
|
|
|
|
|
|
private:
|
2021-01-30 21:18:15 +00:00
|
|
|
bool isPosition( const SDLPP::RenderObject &block, int pos ) const;
|
|
|
|
void resetBlock( int index, std::shared_ptr< TetrisBlock > piece );
|
2020-11-21 19:58:52 +00:00
|
|
|
void addBlockInPos( std::shared_ptr< TetrisBlock > piece,
|
2021-01-30 21:18:15 +00:00
|
|
|
const std::vector< int > &relpos );
|
|
|
|
|
2020-09-11 19:34:43 +00:00
|
|
|
std::vector< std::vector< int > > pieces_rel_position;
|
|
|
|
std::vector< std::shared_ptr< TetrisBlock > > pieces;
|
2021-03-13 17:37:23 +00:00
|
|
|
std::vector< SDLPP::Vec2D< double > > original_pos;
|
2020-09-11 19:34:43 +00:00
|
|
|
bool descend = false;
|
|
|
|
int userMovement = 0;
|
|
|
|
bool rotate_allowed = true;
|
2020-11-21 19:58:52 +00:00
|
|
|
std::pair< int, int > movement = { 0, 0 };
|
2020-09-11 19:34:43 +00:00
|
|
|
bool _hidden = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|