SDLPP: rectcolider now has min height/width property

This commit is contained in:
zv0n 2021-05-25 12:18:03 +02:00
parent b75b44201a
commit 7390f684f5
2 changed files with 16 additions and 0 deletions

View File

@ -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,

View File

@ -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