Flip zombo sprites, turning always to player
This commit is contained in:
parent
7fecd9d451
commit
fda8d5ffe8
@ -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);
|
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
|
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 };
|
const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height };
|
||||||
|
|||||||
@ -26,6 +26,8 @@ public:
|
|||||||
|
|
||||||
void draw_sprite(const Sprite &sprite, int x, int y) const;
|
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 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;
|
void clear_screen(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const;
|
||||||
|
|||||||
@ -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
|
void Zombo::draw(const GameRenderer *renderer, const Sprite &sprite, double player_x, double player_y) const
|
||||||
{
|
{
|
||||||
renderer->draw_sprite(
|
int draw_x = (int)(x - sprite.width / 2 + renderer->screen_width / 2 - player_x);
|
||||||
sprite,
|
int draw_y = (int)(y - sprite.height / 2 + renderer->screen_height / 2 - player_y);
|
||||||
(int)(x - sprite.width / 2 + renderer->screen_width / 2 - player_x),
|
|
||||||
(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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user