diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.cpp b/lib/Ray/sources/Drawables/2D/Rectangle.cpp index 284e9b27..5ad4b674 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.cpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.cpp @@ -12,8 +12,8 @@ namespace RAY::Drawables::Drawables2D { - Rectangle::Rectangle(const Vector2 &position, const Vector2 &dimensions, const Color &color) : - ADrawable2D(position, color), _dimensions(dimensions) + Rectangle::Rectangle(const Vector2 &position, const Vector2 &dimensions, const Color &color, float scale, float rotation) : + ADrawable2D(position, color, scale, rotation), _dimensions(dimensions) { } diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.hpp b/lib/Ray/sources/Drawables/2D/Rectangle.hpp index 6442a7f1..ca85b14f 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.hpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.hpp @@ -11,76 +11,83 @@ #include #include "Drawables/ADrawable2D.hpp" -namespace RAY::Drawables::Drawables2D { +namespace RAY::Drawables::Drawables2D +{ //! @brief Rectangle in a two-dimensional space - class Rectangle: public ADrawable2D + class Rectangle : public ADrawable2D { - public: - //! @brief Rectangle constructor - //! @param position position of top-left point - //! @param dimensions dimensions of the rectangle - //! @param Color Color of the rectangle - Rectangle(const Vector2 &position, const Vector2 &dimensions, const Color &color = WHITE); + public: + //! @brief Rectangle constructor + //! @param position position of top-left point + //! @param dimensions dimensions of the rectangle + //! @param Color Color of the rectangle + Rectangle(const Vector2 &position, + const Vector2 &dimensions, + const Color &color = WHITE, + float scale = 1, + float rotation = 0); - //! @brief Rectangle constructor - //! @param x x-position of top-left point - //! @param y y-position of top-left point - //! @param width width of the rectangle - //! @param length length of the rectangle - //! @param Color Color of the rectangle - Rectangle(int x, int y, int width, int height, const Color &color = WHITE); - - //! @brief A default copy constructor - Rectangle(const Rectangle &) = default; + //! @brief Rectangle constructor + //! @param x x-position of top-left point + //! @param y y-position of top-left point + //! @param width width of the rectangle + //! @param length length of the rectangle + //! @param Color Color of the rectangle + Rectangle(int x, int y, int width, int height, const Color &color = WHITE); - //! @brief A rectangle is assignable - Rectangle &operator=(const Rectangle &) = default; + //! @brief A default copy constructor + Rectangle(const Rectangle &) = default; - //! @brief A default destructor - virtual ~Rectangle() override = default; + //! @brief A rectangle is assignable + Rectangle &operator=(const Rectangle &) = default; - //! @return the dimensions of the rectangle - const Vector2 &getDimensions(void); + //! @brief A default destructor + virtual ~Rectangle() override = default; - //! @return the width of the rectangle - float getWidth(void) const; + //! @return the dimensions of the rectangle + const Vector2 &getDimensions(void); - //! @return the height of the rectangle - float getHeight(void) const; + //! @return the width of the rectangle + float getWidth(void) const; - //! @brief set dimensions - Rectangle &setDimensions(const Vector2 &dimensions); + //! @return the height of the rectangle + float getHeight(void) const; - //! @brief increment width of the rectangle - //! @param width incrementer - Rectangle &incrementWidth(float width); + //! @brief set dimensions + Rectangle &setDimensions(const Vector2 &dimensions); - //! @brief increment height of the rectangle - //! @param height incrementer - Rectangle &incrementHeight(float height); + //! @brief increment width of the rectangle + //! @param width incrementer + Rectangle &incrementWidth(float width); - //! @brief set rectangle's height - //! @param height height of the rectangle - Rectangle &setHeight(float height); + //! @brief increment height of the rectangle + //! @param height incrementer + Rectangle &incrementHeight(float height); - //! @brief set rectangle's width - //! @param width width of the rectangle - Rectangle &setWidth(float width); + //! @brief set rectangle's height + //! @param height height of the rectangle + Rectangle &setHeight(float height); - //! @brief set dimensions - Rectangle &setDimensions(float x, float y); + //! @brief set rectangle's width + //! @param width width of the rectangle + Rectangle &setWidth(float width); - //! @brief Draw point on window - virtual void drawOn(RAY::Window &) override; - //! @brief Draw point on image - virtual void drawOn(RAY::Image &image) override; + //! @brief set dimensions + Rectangle &setDimensions(float x, float y); - protected: - //! @brief Diemnsions of the rectangle - Vector2 _dimensions; - - INTERNAL: - operator ::Rectangle() const; + //! @brief Draw point on window + virtual void drawOn(RAY::Window &) override; + + //! @brief Draw point on image + virtual void drawOn(RAY::Image &image) override; + + protected: + //! @brief Diemnsions of the rectangle + Vector2 _dimensions; + + INTERNAL: + + operator ::Rectangle() const; }; }; diff --git a/lib/Ray/sources/Drawables/ADrawable2D.cpp b/lib/Ray/sources/Drawables/ADrawable2D.cpp index 0dd9804a..de5a0826 100644 --- a/lib/Ray/sources/Drawables/ADrawable2D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable2D.cpp @@ -11,14 +11,20 @@ namespace RAY::Drawables { - ADrawable2D::ADrawable2D(const Vector2 &position, const RAY::Color &color) : - _position(position), _color(color) + ADrawable2D::ADrawable2D(const Vector2 &position, const RAY::Color &color, float scale, float rotation) : + _rotation(rotation), + _scale(scale), + _position(position), + _color(color) { } - ADrawable2D::ADrawable2D(int x, int y, const RAY::Color &color) : - _position(static_cast(x), static_cast(y)), _color(color) + ADrawable2D::ADrawable2D(int x, int y, const RAY::Color &color, float scale, float rotation) : + _rotation(rotation), + _scale(scale), + _position(static_cast(x), static_cast(y)), + _color(color) { } @@ -50,4 +56,14 @@ namespace RAY::Drawables this->_color = color; return *this; } + + float ADrawable2D::getScale() const + { + return this->_scale; + } + + void ADrawable2D::setScale(float scale) + { + this->_scale = scale; + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable2D.hpp b/lib/Ray/sources/Drawables/ADrawable2D.hpp index f2364539..90988543 100644 --- a/lib/Ray/sources/Drawables/ADrawable2D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable2D.hpp @@ -24,12 +24,12 @@ namespace RAY::Drawables { //! @brief ADrawable constructor //! @param poition position of top-left point //! @param Color Color of the color - ADrawable2D(const Vector2 &position, const RAY::Color &color); + ADrawable2D(const Vector2 &position, const RAY::Color &color, float scale = 1, float rotation = 0); //! @brief ADrawable constructor //! @param x x-position of top-left point //! @param y y-position of top-left point //! @param Color Color of the color - ADrawable2D(int x, int y, const RAY::Color &color); + ADrawable2D(int x, int y, const RAY::Color &color, float scale = 1, float rotation = 0); //! @brief A default copy constructor ADrawable2D(const ADrawable2D &) = default; @@ -58,7 +58,16 @@ namespace RAY::Drawables { //! @brief Draw drawble on image virtual void drawOn(RAY::Image &image) = 0; + //! @brief scale getter + float getScale() const; + //! @brief scale setters + void setScale(float scale); + protected: + //! @brief rotation + float _rotation = 0; + //! @brief scale + float _scale = 1; //! @brief Top-left position Vector2 _position; //! @brief Color of the ADrawable diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index dfdf1213..477daa05 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -13,8 +13,8 @@ namespace RAY { Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture); - Texture::Texture(const std::string &filename, bool lonely): - Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), + Texture::Texture(const std::string &filename, bool lonely, float scale, float rotation): + Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE, scale, rotation), _texture(_texturesCache.fetch(filename, lonely)), _resourcePath(filename) { @@ -44,8 +44,6 @@ namespace RAY { void Texture::drawOn(RAY::Window &) { - float scale = this->_dimensions.x / this->_texture->width; - - DrawTextureEx(*this, this->_position, 0, scale, this->_color); + DrawTextureEx(*this, this->_position, 0, this->_scale, this->_color); } } diff --git a/lib/Ray/sources/Drawables/Texture.hpp b/lib/Ray/sources/Drawables/Texture.hpp index 931699e2..060e0da9 100644 --- a/lib/Ray/sources/Drawables/Texture.hpp +++ b/lib/Ray/sources/Drawables/Texture.hpp @@ -21,7 +21,7 @@ namespace RAY //! @brief Create an texture, loading a file //! @param filename: path to file to load //! @param lonely: should be set to true if the entity's loaded data must be independant from others - Texture(const std::string &filename, bool lonely = false); + Texture(const std::string &filename, bool lonely = false, float scale = 1, float rotation = 0); //! @brief A texture is copy constructable Texture(const Texture &) = default; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 418abae5..138a51ef 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -76,12 +76,12 @@ namespace BBM }); scene->addEntity("background image") - .addComponent(true, "assets/background_game.png", false) + .addComponent(true, "assets/background_game.png", false, 2, 0) .addComponent(); scene->addEntity("camera") .addComponent(8, 20, 7) .addComponent(Vector3f(8, 0, 8)); - //MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); + MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); return scene; }