game/sdlpp/sdlpp_collision.hpp

59 lines
2.1 KiB
C++
Raw Normal View History

2020-11-21 19:57:40 +00:00
#ifndef SDLPP_HPP_COLLISION
#define SDLPP_HPP_COLLISION
#include "sdlpp_common.hpp"
#include "sdlpp_renderer.hpp"
#include "sdlpp_vector.hpp"
2021-03-13 14:05:16 +00:00
#include "sdlpp_line.hpp"
2021-01-30 21:23:45 +00:00
#include <memory>
2021-03-13 14:05:16 +00:00
#include <vector>
2020-11-21 19:57:40 +00:00
namespace SDLPP {
2020-11-22 22:37:55 +00:00
class SDLPPSCOPE CollisionPolygon {
2020-11-21 19:57:40 +00:00
public:
CollisionPolygon( double x, double y );
2021-03-13 14:05:16 +00:00
CollisionPolygon( const Vec2D< double > &input );
2021-04-26 19:57:31 +00:00
CollisionPolygon( double x, double y, uint64_t id );
CollisionPolygon( const Vec2D< double > &input, uint64_t id );
2020-11-21 19:57:40 +00:00
virtual ~CollisionPolygon() {}
virtual bool colidesWith( const CollisionPolygon &other ) const = 0;
virtual bool isCircle() const = 0;
virtual bool isInfinite() const;
virtual void setInfinite();
virtual int topmost() const = 0;
virtual int bottommost() const = 0;
virtual int leftmost() const = 0;
virtual int rightmost() const = 0;
2021-04-26 19:57:31 +00:00
virtual void updateCollision( int x, int y, int w, int h,
uint64_t objectId );
2021-03-13 14:05:16 +00:00
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;
2020-11-21 19:57:40 +00:00
virtual void render( Renderer &renderer ) = 0;
void setPos(const Vec2D<double> &pos);
void setPos(double x, double y);
2020-11-21 19:57:40 +00:00
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;
2021-03-13 14:05:16 +00:00
virtual std::vector< Line< int > > getLines() const = 0;
2021-04-26 19:57:31 +00:00
uint64_t getId();
void setId( uint64_t id );
2020-11-21 19:57:40 +00:00
protected:
2021-03-13 14:05:16 +00:00
Vec2D< double > original;
Vec2D< int > position;
2020-11-21 19:57:40 +00:00
bool infinite = false;
SDL_Color sdl_color = { 0, 0, 0, 0 };
SDL_Color sdl_outline = { 0, 0, 0, 0 };
2021-04-26 19:57:31 +00:00
uint64_t _id = -1;
2020-11-21 19:57:40 +00:00
};
2020-11-22 22:37:55 +00:00
SDLPPSCOPE bool infinityIntersection( const SDLPP::CollisionPolygon &infinite,
2020-11-22 22:48:45 +00:00
const SDLPP::CollisionPolygon &other );
2020-11-22 22:37:55 +00:00
SDLPPSCOPE bool intersects( const SDLPP::CollisionPolygon &p1,
2020-11-22 22:48:45 +00:00
const SDLPP::CollisionPolygon &p2 );
2020-11-21 19:57:40 +00:00
} // namespace SDLPP
#endif