diff --git a/source/code/sago/SagoSprite.cpp b/source/code/sago/SagoSprite.cpp index 3d59b20..7b6297e 100644 --- a/source/code/sago/SagoSprite.cpp +++ b/source/code/sago/SagoSprite.cpp @@ -64,7 +64,16 @@ void SagoSprite::Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y) cons DrawScaled(target, frameTime, x, y, data->imgCord.w, data->imgCord.h); } +void SagoSprite::DrawRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, const double angleRadian) const { + SDL_Point center = {this->data->origin.x, this->data->origin.y}; + DrawScaledAndRotated(target, frameTime, x, y, data->imgCord.w, data->imgCord.h, angleRadian, ¢er, SDL_FLIP_NONE); +} + void SagoSprite::DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) const { + DrawScaledAndRotated(target, frameTime, x, y, w, h, 0.0, nullptr, SDL_FLIP_NONE); +} + +void SagoSprite::DrawScaledAndRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h, const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip) const { if (!data->tex.get()) { std::cerr << "Texture is null!\n"; } @@ -79,7 +88,8 @@ void SagoSprite::DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y if (h > 0) { pos.h = h; } - SDL_RenderCopy(target, data->tex.get(), &rect, &pos); + double angleDegress = angleRadian/M_PI*180.0; + SDL_RenderCopyEx(target, data->tex.get(), &rect, &pos, angleDegress, center, flip); } void SagoSprite::Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part) const { diff --git a/source/code/sago/SagoSprite.hpp b/source/code/sago/SagoSprite.hpp index d57cbed..742cf76 100644 --- a/source/code/sago/SagoSprite.hpp +++ b/source/code/sago/SagoSprite.hpp @@ -44,6 +44,16 @@ public: void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y) const; /** + * Draws the sprite to a given render window + * @param target The render window to draw on + * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation + * @param x Place to draw the sprite + * @param y Place to draw the sprite + * @param angleRadian Angle to rotate the sprite around origin before drawing + */ + void DrawRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, const double angleRadian) const; + + /** * Draws part of the sprite to a given render window * @param target The render window to draw on * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation @@ -71,8 +81,11 @@ public: * @param y Place to draw the sprite */ void DrawProgressive(SDL_Renderer* target, float progress, int x, int y) const; + void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) const; - + void DrawScaledAndRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h, + const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip) const; + /** * Set a different origin. Normally it is the top left cornor. But in some cases you might want to center the origin or tranform it for other reasons * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default