From 6bf8c2cb88617758f4ad5beacbf6251a81a07508 Mon Sep 17 00:00:00 2001 From: Reimar Date: Mon, 27 Oct 2025 09:45:26 +0100 Subject: [PATCH] Allow rotating sprites --- src/GameRenderer.cpp | 7 +++++++ src/GameRenderer.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/GameRenderer.cpp b/src/GameRenderer.cpp index e33c2ec..d897bbc 100644 --- a/src/GameRenderer.cpp +++ b/src/GameRenderer.cpp @@ -54,6 +54,13 @@ void GameRenderer::draw_sprite(const Sprite sprite, const int x, const int y) co SDL_RenderCopy(renderer, sprite.texture, nullptr, &rect); } +void GameRenderer::draw_sprite_rotated(const Sprite sprite, const int x, const int y, const double angle, const int center_x, const int center_y) const +{ + const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height }; + const SDL_Point center = { .x = center_x, .y = center_y }; + SDL_RenderCopyEx(renderer, sprite.texture, nullptr, &rect, angle, ¢er, SDL_FLIP_NONE); +} + void GameRenderer::clear_screen(const int r, const int g, const int b, const int a) const { SDL_SetRenderDrawColor(renderer, r, g, b, a); diff --git a/src/GameRenderer.hpp b/src/GameRenderer.hpp index 2d0891d..c4770a8 100644 --- a/src/GameRenderer.hpp +++ b/src/GameRenderer.hpp @@ -25,6 +25,8 @@ public: void draw_sprite(Sprite sprite, int x, int y) const; + void draw_sprite_rotated(Sprite sprite, int x, int y, double angle, int center_x, int center_y) const; + void clear_screen(int r, int g, int b, int a) const; void flush() const;