Flip zombo sprites, turning always to player

This commit is contained in:
Reimar 2025-11-03 14:07:27 +01:00
parent 7fecd9d451
commit fda8d5ffe8
3 changed files with 15 additions and 5 deletions

View File

@ -51,6 +51,12 @@ void GameRenderer::draw_sprite(const Sprite &sprite, const int x, const int y) c
SDL_RenderCopy(renderer, sprite.texture, nullptr, &rect);
}
void GameRenderer::draw_sprite_flipped(const Sprite &sprite, const int x, const int y) const
{
const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height };
SDL_RenderCopyEx(renderer, sprite.texture, nullptr, &rect, 0, nullptr, SDL_FLIP_HORIZONTAL);
}
void GameRenderer::draw_sprite_rotated(const Sprite &sprite, const int x, const int y, const double angle) const
{
const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height };

View File

@ -26,6 +26,8 @@ public:
void draw_sprite(const Sprite &sprite, int x, int y) const;
void draw_sprite_flipped(const Sprite &sprite, int x, int y) const;
void draw_sprite_rotated(const Sprite &sprite, int x, int y, double angle) const;
void clear_screen(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const;

View File

@ -10,9 +10,11 @@ void Zombo::update(const double player_x, const double player_y)
void Zombo::draw(const GameRenderer *renderer, const Sprite &sprite, double player_x, double player_y) const
{
renderer->draw_sprite(
sprite,
(int)(x - sprite.width / 2 + renderer->screen_width / 2 - player_x),
(int)(y - sprite.height / 2 + renderer->screen_height / 2 - player_y)
);
int draw_x = (int)(x - sprite.width / 2 + renderer->screen_width / 2 - player_x);
int draw_y = (int)(y - sprite.height / 2 + renderer->screen_height / 2 - player_y);
if (x < player_x)
renderer->draw_sprite(sprite, draw_x, draw_y);
else
renderer->draw_sprite_flipped(sprite, draw_x, draw_y);
}