game/sdlpp/sdlpp_rectcolider.hpp

52 lines
1.8 KiB
C++

#ifndef SDLPP_HPP_RECT_COLIDER
#define SDLPP_HPP_RECT_COLIDER
#include "sdlpp_common.hpp"
#include "sdlpp_collision.hpp"
#include "sdlpp_vector.hpp"
#include "sdlpp_line.hpp"
#include <limits>
#include <vector>
namespace SDLPP {
class SDLPPSCOPE RectColider : public CollisionPolygon {
public:
RectColider( double x, double y, double w, double h );
RectColider( const Vec2D< double > &top_left, const Vec2D< double > &size );
RectColider( double x, double y, double w, double h, uint64_t id );
RectColider( const Vec2D< double > &top_left, const Vec2D< double > &size,
uint64_t id );
virtual ~RectColider() {}
virtual bool colidesWith( const CollisionPolygon &other ) const override;
virtual bool isCircle() const override;
virtual int topmost() const override;
virtual int bottommost() const override;
virtual int leftmost() const override;
virtual int rightmost() const override;
virtual void updateCollision( int x, int y, int w, int h,
uint64_t id ) override;
virtual void render( Renderer &renderer, const SDL_Color &color,
const SDL_Color &outline_color ) override;
virtual void render( Renderer &renderer, const SDL_Color &color ) override;
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();
double width() const;
double height() const;
int pixel_width() const;
int pixel_height() const;
Vec2D< double > _size;
Vec2D< int > _size_pixel;
Vec2D< int > min_size = {0, 0};
};
} // end of namespace SDLPP
#endif