SDLPP: rectcolider now has min height/width property
This commit is contained in:
parent
b75b44201a
commit
7390f684f5
@ -18,6 +18,13 @@ int RectColider::pixel_height() const {
|
|||||||
return _size_pixel.getY();
|
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::RectColider( double x, double y, double w, double h )
|
||||||
: RectColider( { x, y }, { w, 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 );
|
_size_pixel = Vec2D< int >( width() * w, height() * h );
|
||||||
if ( _id == static_cast< uint64_t >( -1 ) )
|
if ( _id == static_cast< uint64_t >( -1 ) )
|
||||||
_id = id;
|
_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,
|
void RectColider::render( Renderer &renderer, const SDL_Color &color,
|
||||||
|
@ -32,6 +32,8 @@ public:
|
|||||||
virtual void render( Renderer &renderer ) override;
|
virtual void render( Renderer &renderer ) override;
|
||||||
virtual std::shared_ptr< CollisionPolygon > copySelf() override;
|
virtual std::shared_ptr< CollisionPolygon > copySelf() override;
|
||||||
virtual std::vector< Line< int > > getLines() const override;
|
virtual std::vector< Line< int > > getLines() const override;
|
||||||
|
void setMinWidth( int width );
|
||||||
|
void setMinHeight( int height );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Rect getRect();
|
SDL_Rect getRect();
|
||||||
@ -43,6 +45,7 @@ private:
|
|||||||
|
|
||||||
Vec2D< double > _size;
|
Vec2D< double > _size;
|
||||||
Vec2D< int > _size_pixel;
|
Vec2D< int > _size_pixel;
|
||||||
|
Vec2D< int > min_size = {0, 0};
|
||||||
};
|
};
|
||||||
} // end of namespace SDLPP
|
} // end of namespace SDLPP
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user