Files
game/sdlpp/sdlpp_collision.hpp
T

57 lines
2.0 KiB
C++
Raw Normal View History

2020-11-21 20:57:40 +01:00
#ifndef SDLPP_HPP_COLLISION
#define SDLPP_HPP_COLLISION
#include "sdlpp_common.hpp"
#include "sdlpp_renderer.hpp"
2021-03-12 22:33:46 +01:00
#include "sdlpp_vector.hpp"
2021-03-13 15:05:16 +01:00
#include "sdlpp_line.hpp"
2021-01-30 22:23:45 +01:00
#include <memory>
2021-03-13 15:05:16 +01:00
#include <vector>
2020-11-21 20:57:40 +01:00
namespace SDLPP {
2020-11-22 23:37:55 +01:00
class SDLPPSCOPE CollisionPolygon {
2020-11-21 20:57:40 +01:00
public:
CollisionPolygon( double x, double y );
2021-03-13 15:05:16 +01:00
CollisionPolygon( const Vec2D< double > &input );
2021-04-26 21:57:31 +02:00
CollisionPolygon( double x, double y, uint64_t id );
CollisionPolygon( const Vec2D< double > &input, uint64_t id );
2020-11-21 20:57:40 +01: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 21:57:31 +02:00
virtual void updateCollision( int x, int y, int w, int h,
uint64_t objectId );
2021-03-13 15:05:16 +01: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 20:57:40 +01:00
virtual void render( Renderer &renderer ) = 0;
int getX() const;
int getY() const;
void setColor( const std::string &color );
void setOutlineColor( const std::string &color );
2021-03-12 22:33:46 +01:00
virtual std::shared_ptr< CollisionPolygon > copySelf() = 0;
2021-03-13 15:05:16 +01:00
virtual std::vector< Line< int > > getLines() const = 0;
2021-04-26 21:57:31 +02:00
uint64_t getId();
void setId( uint64_t id );
2020-11-21 20:57:40 +01:00
protected:
2021-03-13 15:05:16 +01:00
Vec2D< double > original;
Vec2D< int > position;
2020-11-21 20:57:40 +01:00
bool infinite = false;
SDL_Color sdl_color = { 0, 0, 0, 0 };
SDL_Color sdl_outline = { 0, 0, 0, 0 };
2021-04-26 21:57:31 +02:00
uint64_t _id = -1;
2020-11-21 20:57:40 +01:00
};
2020-11-22 23:37:55 +01:00
SDLPPSCOPE bool infinityIntersection( const SDLPP::CollisionPolygon &infinite,
2020-11-22 23:48:45 +01:00
const SDLPP::CollisionPolygon &other );
2020-11-22 23:37:55 +01:00
SDLPPSCOPE bool intersects( const SDLPP::CollisionPolygon &p1,
2020-11-22 23:48:45 +01:00
const SDLPP::CollisionPolygon &p2 );
2020-11-21 20:57:40 +01:00
} // namespace SDLPP
#endif