SDLPP: add collider IDs

This commit is contained in:
2021-04-26 21:57:31 +02:00
parent 19e66bf34a
commit dd6f37264c
16 changed files with 112 additions and 41 deletions
+12 -1
View File
@@ -25,6 +25,15 @@ RectColider::RectColider( const Vec2D< double > &top_left,
const Vec2D< double > &size )
: CollisionPolygon( top_left ), _size( size ) {}
RectColider::RectColider( double x, double y, double w, double h, uint64_t id )
: RectColider( { x, y }, { w, h }, id ) {}
RectColider::RectColider( const Vec2D< double > &top_left,
const Vec2D< double > &size, uint64_t id )
: RectColider( top_left, size ) {
_id = id;
}
bool RectColider::colidesWith( const SDLPP::CollisionPolygon &other ) const {
if ( other.isCircle() ) {
return other.colidesWith( *this );
@@ -57,9 +66,11 @@ int RectColider::rightmost() const {
isInfinite() * -1;
}
void RectColider::updateCollision( int x, int y, int w, int h ) {
void RectColider::updateCollision( int x, int y, int w, int h, uint64_t id ) {
position = Vec2D< int >( original.getX() * w + x, original.getY() * h + y );
_size_pixel = Vec2D< int >( width() * w, height() * h );
if ( _id == static_cast< uint64_t >( -1 ) )
_id = id;
}
void RectColider::render( Renderer &renderer, const SDL_Color &color,