aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-28 09:18:13 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-28 09:18:13 +0100
commit71be3e36dbb402c3e84d87ea0255c08cb2a1b7ca (patch)
tree25a26be197fe64d2e4411ee0db1568fb6eb0b6f5 /src/crepe/facade/SDLContext.cpp
parent5fa57ab2d8f809b8cb6bd72f54567a01f3e63b95 (diff)
implemented feedback to have draw struct
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r--src/crepe/facade/SDLContext.cpp35
1 files changed, 11 insertions, 24 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 0d42a4c..7317a77 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -109,7 +109,7 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const {
};
}
SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, const Camera & cam,
- const double & img_scale) const {
+ const vec2 & cam_pos, const double & img_scale) const {
int width = sprite.height * sprite.aspect_ratio;
int height = sprite.height;
@@ -118,38 +118,25 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, const
height *= img_scale * cam.zoom;
return SDL_Rect{
- .x = static_cast<int>((pos.x - cam.pos.x + (cam.viewport.x / 2) - width / 2)),
- .y = static_cast<int>((pos.y - cam.pos.y + (cam.viewport.y / 2) - height / 2)),
+ .x = static_cast<int>((pos.x - cam_pos.x + (cam.viewport.x / 2) - width / 2)),
+ .y = static_cast<int>((pos.y - cam_pos.y + (cam.viewport.y / 2) - height / 2)),
.w = width,
.h = height,
};
}
-void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle,
- const double & img_scale, const Camera & cam) {
+void SDLContext::draw(const RenderCtx & ctx) {
SDL_RendererFlip render_flip
- = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x)
- | (SDL_FLIP_VERTICAL * sprite.flip.flip_y));
+ = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * ctx.sprite.flip.flip_x)
+ | (SDL_FLIP_VERTICAL * ctx.sprite.flip.flip_y));
- SDL_Rect srcrect = this->get_src_rect(sprite);
- SDL_Rect dstrect = this->get_dst_rect(sprite, pos, cam, img_scale);
+ SDL_Rect srcrect = this->get_src_rect(ctx.sprite);
+ SDL_Rect dstrect
+ = this->get_dst_rect(ctx.sprite, ctx.pos, ctx.cam, ctx.cam_pos, ctx.scale);
- SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image.texture.get(), &srcrect,
- &dstrect, angle, NULL, render_flip);
-}
-
-void SDLContext::draw(const Sprite & sprite, const Transform & transform, const Camera & cam) {
-
- SDL_RendererFlip render_flip
- = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x)
- | (SDL_FLIP_VERTICAL * sprite.flip.flip_y));
-
- SDL_Rect srcrect = this->get_src_rect(sprite);
- SDL_Rect dstrect = this->get_dst_rect(sprite, transform.position, cam, transform.scale);
-
- SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image.texture.get(), &srcrect,
- &dstrect, transform.rotation, NULL, render_flip);
+ SDL_RenderCopyEx(this->game_renderer.get(), ctx.sprite.sprite_image.texture.get(),
+ &srcrect, &dstrect, ctx.angle, NULL, render_flip);
}
void SDLContext::set_camera(const Camera & cam) {