diff options
author | BoredGuy <osome3717@gmail.com> | 2024-12-14 12:08:02 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2024-12-14 12:08:02 +0300 |
commit | fc3032135f4da3662d6b727c70f22049d6e09231 (patch) | |
tree | 8e0caba74cc6749c76f211540fe908f6b9a3d476 /Week1-Pacman/src/demo.c | |
parent | 993f45cec7a08a5b980ef5a08ea7ce19b877b743 (diff) |
Update
- Finish animation system
- Fix bug where leftward/upward movement was slightly faster than
downward/forward movement
Diffstat (limited to 'Week1-Pacman/src/demo.c')
-rw-r--r-- | Week1-Pacman/src/demo.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/Week1-Pacman/src/demo.c b/Week1-Pacman/src/demo.c index 5ab6c39..85ee2a3 100644 --- a/Week1-Pacman/src/demo.c +++ b/Week1-Pacman/src/demo.c @@ -8,14 +8,14 @@ void update_demo(struct demo* demo) { SDL_GetWindowSize(demo->win, &width, &height); SDL_GetRendererOutputSize(demo->ren, &pixel_width, &pixel_height); - demo->display_scale_x = pixel_width / width; - demo->display_scale_y = pixel_height / height; + demo->display_scale_x = (float)pixel_width / width; + demo->display_scale_y = (float)pixel_height / height; } void demo_rendercopy(struct demo* demo, SDL_Texture* texture, - SDL_Rect* s_rect, - SDL_Rect* d_rect) { + const SDL_Rect* s_rect, + const SDL_Rect* d_rect) { const float scale_x = demo->display_scale_x; const float scale_y = demo->display_scale_y; @@ -43,5 +43,45 @@ void demo_rendercopy(struct demo* demo, //Handle edge case where s_rect or d_rect are NULL SDL_RenderCopy(demo->ren, texture, s_rect ? &new_srect : NULL, - d_rect ?&new_drect : NULL); + d_rect ? &new_drect : NULL); +} + +void demo_rendercopy_ex(struct demo* demo, + SDL_Texture* texture, + const SDL_Rect* s_rect, + const SDL_Rect* d_rect, + const double angle, + const SDL_Point* center, + const SDL_RendererFlip flip) { + const float scale_x = demo->display_scale_x; + const float scale_y = demo->display_scale_y; + + SDL_Rect new_srect; + SDL_Rect new_drect; + + if(s_rect) { + new_srect = (SDL_Rect){ + .x = s_rect->x * scale_x, + .y = s_rect->y * scale_y, + .w = s_rect->w * scale_x, + .h = s_rect->h * scale_y + }; + } + + if(d_rect) { + new_drect = (SDL_Rect){ + .x = d_rect->x * scale_x, + .y = d_rect->y * scale_y, + .w = d_rect->w * scale_x, + .h = d_rect->h * scale_y + }; + } + + //Handle edge case where s_rect or d_rect are NULL + SDL_RenderCopyEx(demo->ren, texture, + s_rect ? &new_srect : NULL, + d_rect ? &new_drect : NULL, + angle, + center, + flip); } |