diff --git a/sdlpp/sdlpp_rectcolider.cpp b/sdlpp/sdlpp_rectcolider.cpp index 06b2cd3..9b65da5 100644 --- a/sdlpp/sdlpp_rectcolider.cpp +++ b/sdlpp/sdlpp_rectcolider.cpp @@ -18,6 +18,13 @@ int RectColider::pixel_height() const { return _size_pixel.getY(); } +void RectColider::setMinWidth( int width ) { + min_size = {width, min_size.getY()}; +} +void RectColider::setMinHeight( int height ) { + min_size = {min_size.getX(), height}; +} + RectColider::RectColider( double x, double y, double w, double h ) : RectColider( { x, y }, { w, h } ) {} @@ -71,6 +78,12 @@ void RectColider::updateCollision( int x, int y, int w, int h, uint64_t id ) { _size_pixel = Vec2D< int >( width() * w, height() * h ); if ( _id == static_cast< uint64_t >( -1 ) ) _id = id; + if(_size_pixel.getX() < min_size.getX()) { + _size_pixel = {min_size.getX(), _size_pixel.getY()}; + } + if(_size_pixel.getY() < min_size.getY()) { + _size_pixel = {_size_pixel.getX(), min_size.getY()}; + } } void RectColider::render( Renderer &renderer, const SDL_Color &color, diff --git a/sdlpp/sdlpp_rectcolider.hpp b/sdlpp/sdlpp_rectcolider.hpp index 89cfb0c..986b28c 100644 --- a/sdlpp/sdlpp_rectcolider.hpp +++ b/sdlpp/sdlpp_rectcolider.hpp @@ -32,6 +32,8 @@ public: virtual void render( Renderer &renderer ) override; virtual std::shared_ptr< CollisionPolygon > copySelf() override; virtual std::vector< Line< int > > getLines() const override; + void setMinWidth( int width ); + void setMinHeight( int height ); private: SDL_Rect getRect(); @@ -43,6 +45,7 @@ private: Vec2D< double > _size; Vec2D< int > _size_pixel; + Vec2D< int > min_size = {0, 0}; }; } // end of namespace SDLPP #endif