Skip to content

Commit

Permalink
✏️ support specifying angles for entities that have textures
Browse files Browse the repository at this point in the history
  • Loading branch information
tackyunicorn committed Dec 5, 2024
1 parent 2a388e5 commit 7d03e76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/engine/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Render::Render(Entity *entity) {
this->texture_template = "";
this->shape = Shape::Rectangle;
this->color = Color{0, 0, 0, 255};
this->angle = 0;
this->anchor = nullptr;
this->border = Border{false, Color{0, 0, 0, 255}};
this->camera = std::make_shared<Entity>("camera", EntityCategory::Camera);
}
Expand All @@ -19,6 +21,8 @@ SDL_Texture *Render::GetTexture() { return this->texture; }
std::string Render::GetTextureTemplate() { return this->texture_template; }
Shape Render::GetShape() { return this->shape; }
Color Render::GetColor() { return this->color; }
double Render::GetAngle() { return this->angle; }
SDL_Point *Render::GetAnchor() { return this->anchor; }
Border Render::GetBorder() { return this->border; }

void Render::SetCamera(std::shared_ptr<Entity> camera) { this->camera = camera; }
Expand All @@ -30,6 +34,8 @@ void Render::SetTextureTemplate(std::string texture_template) {
}
void Render::SetShape(Shape shape) { this->shape = shape; }
void Render::SetColor(Color color) { this->color = color; }
void Render::SetAngle(double angle) { this->angle = angle; }
void Render::SetAnchor(SDL_Point *anchor) { this->anchor = anchor; }
void Render::SetBorder(Border border) { this->border = border; }

void Render::RenderEntity() {
Expand Down Expand Up @@ -65,7 +71,8 @@ void Render::RenderEntity() {
SDL_RenderFillRect(app->renderer, &rectangle);
}
} else {
SDL_RenderCopy(app->renderer, this->texture, NULL, &rectangle);
SDL_RenderCopyEx(app->renderer, this->texture, NULL, &rectangle, this->angle, this->anchor,
SDL_FLIP_NONE);
if (this->border.show) {
SDL_SetRenderDrawBlendMode(app->renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app->renderer, border_r, border_g, border_b, border_a);
Expand Down
6 changes: 6 additions & 0 deletions src/engine/includes/Render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Render : public Component {
std::string texture_template;
Shape shape;
Color color;
double angle;
SDL_Point *anchor;
Border border;
std::shared_ptr<Entity> camera;

Expand All @@ -23,6 +25,8 @@ class Render : public Component {
std::string GetTextureTemplate();
Shape GetShape();
Color GetColor();
double GetAngle();
SDL_Point *GetAnchor();
Border GetBorder();

void SetCamera(std::shared_ptr<Entity> camera);
Expand All @@ -31,6 +35,8 @@ class Render : public Component {
void SetTextureTemplate(std::string texture_template);
void SetShape(Shape shape);
void SetColor(Color color);
void SetAngle(double angle);
void SetAnchor(SDL_Point *anchor);
void SetBorder(Border border);

void RenderEntity();
Expand Down

0 comments on commit 7d03e76

Please sign in to comment.