diff --git a/lib/Ray/include/Drawables/Basic/Circle.hpp b/lib/Ray/include/Drawables/Basic/Circle.hpp index ca7759a9..b9f55544 100644 --- a/lib/Ray/include/Drawables/Basic/Circle.hpp +++ b/lib/Ray/include/Drawables/Basic/Circle.hpp @@ -5,16 +5,33 @@ ** Pixel */ -#ifndef PIXEL_HPP_ -#define PIXEL_HPP_ +#ifndef CIRCLE_HPP_ +#define CIRCLE_HPP_ #include #include "Drawables/Drawable.hpp" namespace Ray { - struct Circle: public Drawable + class Circle: public Drawable { - int radius; + public: + Circle(Vector2 topLeftPos, int radius, Color); + Circle(int topLeftX, int topLeftY, int radius, Color); + Circle(const Circle &); + + Circle &operator=(const Circle &); + + ~Circle() = default; + + int getRadius(void) const; + + bool collide(const Rectangle &); + bool collide(const Line &); + bool collide(const Point &); + bool collide(const Circle &); + + private: + int radius; }; }; diff --git a/lib/Ray/include/Drawables/Basic/Line.hpp b/lib/Ray/include/Drawables/Basic/Line.hpp index af1438ae..48e36c57 100644 --- a/lib/Ray/include/Drawables/Basic/Line.hpp +++ b/lib/Ray/include/Drawables/Basic/Line.hpp @@ -5,16 +5,37 @@ ** Pixel */ -#ifndef PIXEL_HPP_ -#define PIXEL_HPP_ +#ifndef LINE_HPP_ +#define LINE_HPP_ #include #include "Drawables/Drawable.hpp" namespace Ray { - struct Line: public Drawable + class Line: public Drawable { - Vector2 dimensions; + public: + Line(Vector2 position, int length, Color); + Line(int x, int y, int length, Color); + Line(const Line &); + + Line &operator=(const Line &); + + ~Line() = default; + + int getLength(void) const; + int getRotation(void) const; + + Line &setLength(int); + Line &setRotation(int); + + bool collide(const Rectangle &); + bool collide(const Line &); + bool collide(const Point &); + bool collide(const Circle &); + private: + int _length; + int _rotation; }; }; diff --git a/lib/Ray/include/Drawables/Basic/Pixel.hpp b/lib/Ray/include/Drawables/Basic/Pixel.hpp deleted file mode 100644 index de0b3bd7..00000000 --- a/lib/Ray/include/Drawables/Basic/Pixel.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* -** EPITECH PROJECT, 2021 -** Bomberman -** File description: -** Pixel -*/ - -#ifndef PIXEL_HPP_ -#define PIXEL_HPP_ - -#include -#include "Drawables/Drawable.hpp" - -namespace Ray { - struct Point: public Drawable - { - - }; -}; - -#endif /* !PIXEL_HPP_ */ diff --git a/lib/Ray/include/Drawables/Basic/Point.hpp b/lib/Ray/include/Drawables/Basic/Point.hpp new file mode 100644 index 00000000..1e63c1b1 --- /dev/null +++ b/lib/Ray/include/Drawables/Basic/Point.hpp @@ -0,0 +1,33 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** Pixel +*/ + +#ifndef PIXEL_HPP_ +#define PIXEL_HPP_ + +#include +#include "Drawables/Drawable.hpp" + +namespace Ray { + class Point: public Drawable + { + public: + Point(Vector2 position, Color); + Point(int x, int y, Color); + Point(const Point &); + + Point &operator=(const Point &); + + ~Point() = default; + + bool collide(const Rectangle &); + bool collide(const Line &); + bool collide(const Point &); + bool collide(const Circle &); + }; +}; + +#endif /* !PIXEL_HPP_ */ diff --git a/lib/Ray/include/Drawables/Basic/Rectangle.hpp b/lib/Ray/include/Drawables/Basic/Rectangle.hpp new file mode 100644 index 00000000..46bd6fa8 --- /dev/null +++ b/lib/Ray/include/Drawables/Basic/Rectangle.hpp @@ -0,0 +1,40 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** Pixel +*/ + +#ifndef RECTANGLE_HPP_ +#define RECTANGLE_HPP_ + +#include +#include "Drawables/Drawable.hpp" + +namespace Ray { + class Rectangle: public Drawable + { + public: + Rectangle(Vector2 position, Vector2 dimensions,int length, Color); + Rectangle(int x, int y, int width, int height, int length, Color); + Rectangle(const Rectangle &); + + Rectangle &operator=(const Rectangle &); + + ~Rectangle() = default; + + const Vector2 &getDimensions(void); + + Rectangle &setDimensions(const Vector2 &position); + Rectangle &setDimensions(int x, int y); + + bool collide(const Rectangle &); + bool collide(const Line &); + bool collide(const Point &); + bool collide(const Circle &); + private: + Vector2 _dimensions; + }; +}; + +#endif /* !PIXEL_HPP_ */ diff --git a/lib/Ray/include/Drawables/Drawable.hpp b/lib/Ray/include/Drawables/Drawable.hpp index 05fad26a..00f5de0f 100644 --- a/lib/Ray/include/Drawables/Drawable.hpp +++ b/lib/Ray/include/Drawables/Drawable.hpp @@ -10,16 +10,36 @@ #include #include +#include "Drawables/Basic/Circle.hpp" +#include "Drawables/Basic/Line.hpp" +#include "Drawables/Basic/Rectangle.hpp" +#include "Drawables/Basic/Point.hpp" namespace Ray { - struct Drawable + class Drawable { - //top-left position - Vector2 position; + public: + Drawable(Vector2 position, Color color); + Drawable(int x, int y, Color color); + virtual ~Drawable() = 0; - Color color; + const Vector2 &getPosition(void) const; + const Color &getColor(void) const; + + Drawable &setPosition(const Vector2 &position); + Drawable &setPosition(int x, int y); + Drawable &setColor(const Color &color) const; + + virtual bool collide(const Rectangle &) = 0; + virtual bool collide(const Line &) = 0; + virtual bool collide(const Point &) = 0; + virtual bool collide(const Circle &) = 0; + + private: + //top-left position + Vector2 _position; + Color _color; - virtual ~Drawable() = 0; }; }; diff --git a/lib/Ray/include/Window.hpp b/lib/Ray/include/Window.hpp index 88664105..48107b62 100644 --- a/lib/Ray/include/Window.hpp +++ b/lib/Ray/include/Window.hpp @@ -12,6 +12,7 @@ #include #include "Vector.hpp" #include "Keyboard.hpp" +#include "Drawable.hpp" namespace Ray { class Window { @@ -66,6 +67,11 @@ class Window { // Must be called after last draw of iteration void endDrawing(void); + void drawRectangle(const Rectangle &); + void drawLine(const Line &); + void drawPoint(const Point &); + void drawCircle(const Circle &); + private: Ray::Vector2 _dimensions; std::string _title;