New collision detection

This commit is contained in:
2021-03-13 15:05:16 +01:00
parent 258ce51cfe
commit d2cf54556e
12 changed files with 186 additions and 125 deletions
+9 -5
View File
@@ -4,13 +4,15 @@
#include "sdlpp_common.hpp"
#include "sdlpp_renderer.hpp"
#include "sdlpp_vector.hpp"
#include "sdlpp_line.hpp"
#include <memory>
#include <vector>
namespace SDLPP {
class SDLPPSCOPE CollisionPolygon {
public:
CollisionPolygon( double x, double y );
CollisionPolygon( const Vec2D<double> &input );
CollisionPolygon( const Vec2D< double > &input );
virtual ~CollisionPolygon() {}
virtual bool colidesWith( const CollisionPolygon &other ) const = 0;
virtual bool isCircle() const = 0;
@@ -21,18 +23,20 @@ public:
virtual int leftmost() const = 0;
virtual int rightmost() const = 0;
virtual void updateCollision( int x, int y, int w, int h );
virtual void render( Renderer &renderer,
const std::tuple< int, int, int, int > &color ) = 0;
virtual void render( Renderer &renderer, const SDL_Color &color,
const SDL_Color &outline_color ) = 0;
virtual void render( Renderer &renderer, const SDL_Color &color ) = 0;
virtual void render( Renderer &renderer ) = 0;
int getX() const;
int getY() const;
void setColor( const std::string &color );
void setOutlineColor( const std::string &color );
virtual std::shared_ptr< CollisionPolygon > copySelf() = 0;
virtual std::vector< Line< int > > getLines() const = 0;
protected:
Vec2D<double> original;
Vec2D<int> position;
Vec2D< double > original;
Vec2D< int > position;
bool infinite = false;
SDL_Color sdl_color = { 0, 0, 0, 0 };
SDL_Color sdl_outline = { 0, 0, 0, 0 };