game/tetris/custom_classes.hpp

82 lines
2.7 KiB
C++
Raw Normal View History

#ifndef TETRIS_CUSTOM_CLASSES_H
#define TETRIS_CUSTOM_CLASSES_H
2020-11-21 19:58:52 +00:00
#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,
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,
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;
2020-11-21 19:58:52 +00:00
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 );
2021-03-13 17:37:23 +00:00
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 );
2020-11-21 19:58:52 +00:00
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;
2021-03-13 17:37:23 +00:00
std::vector< SDLPP::Vec2D< double > > original_pos;
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 };
bool _hidden = false;
};
#endif