Simon From Jakobsen 7584609f33 fix and stub errors
2025-10-29 12:42:41 +01:00

26 lines
688 B
C++

#include "Arrow.hpp"
#include <cmath>
#include <numbers>
Arrow::Arrow(GameRenderer *renderer, const double x, const double y, const double angle)
: renderer(renderer), x(x), y(y), angle(angle)
{
sprite = renderer->load_sprite("./assets/arrow.png", 22, 8);
}
void Arrow::draw(const double player_x, const double player_y) const
{
renderer->draw_sprite_rotated(
sprite,
(int)(x - sprite.width / 2 + renderer->screen_width / 2 - player_x),
(int)(y - sprite.height / 2 + renderer->screen_height / 2 - player_y),
angle * 180 / std::numbers::pi
);
}
void Arrow::update()
{
x += std::cos(angle) * speed;
y += std::sin(angle) * speed;
}