game/sdlpp/sdlpp_rectcolider.hpp

49 lines
1.7 KiB
C++
Raw Normal View History

2020-11-21 19:57:40 +00:00
#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"
2020-11-21 19:57:40 +00:00
#include <limits>
#include <vector>
2020-11-21 19:57:40 +00:00
namespace SDLPP {
2020-11-22 22:37:55 +00:00
class SDLPPSCOPE RectColider : public CollisionPolygon {
2020-11-21 19:57:40 +00:00
public:
RectColider( double x, double y, double w, double h );
2021-03-13 14:05:16 +00:00
RectColider( const Vec2D< double > &top_left, const Vec2D< double > &size );
2021-04-26 19:57:31 +00:00
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 );
2020-11-21 19:57:40 +00:00
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;
2021-04-26 19:57:31 +00:00
virtual void updateCollision( int x, int y, int w, int h,
uint64_t id ) override;
2021-03-13 14:05:16 +00:00
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;
2020-11-21 19:57:40 +00:00
virtual void render( Renderer &renderer ) override;
2021-03-13 14:05:16 +00:00
virtual std::shared_ptr< CollisionPolygon > copySelf() override;
virtual std::vector< Line< int > > getLines() const override;
2020-11-21 19:57:40 +00:00
private:
SDL_Rect getRect();
double width() const;
double height() const;
int pixel_width() const;
int pixel_height() const;
2021-03-13 14:05:16 +00:00
Vec2D< double > _size;
Vec2D< int > _size_pixel;
2020-11-21 19:57:40 +00:00
};
} // end of namespace SDLPP
#endif