Skip to content

Commit

Permalink
SpriteHandler.h:
Browse files Browse the repository at this point in the history
* BitmapSprite now has a plot_line function which allows you to render a line straight into a bitmap texture frame of the sprite. The frame number argument is the sim_frame here (not sure if it is the best choice, but works for now).
  • Loading branch information
razterizer committed Nov 15, 2024
1 parent 6f79ac9 commit d2a5b6e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions SpriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,31 @@ class BitmapSprite : public Sprite
texture->materials.assign(area, mat);
}

bool plot_line(int sim_frame, const RC& p0, const RC& p1,
std::optional<char> ch,
std::optional<Color> fg_color,
std::optional<Color> bg_color,
std::optional<int> mat)
{
auto* texture = get_curr_frame(sim_frame);
if (texture == nullptr)
return false;
std::vector<RC> points;
bresenham::plot_line(p0, p1, points);
for (const auto& pt : points)
{
auto r = math::roundI(pt.r) - pos.r;
auto c = math::roundI(pt.c) - pos.c;
auto textel = (*texture)(r, c);
textel.ch = ch.value_or(textel.ch);
textel.fg_color = fg_color.value_or(textel.fg_color);
textel.bg_color = bg_color.value_or(textel.bg_color);
textel.mat = mat.value_or(textel.mat);
texture->set_textel(r, c, textel);
}
return true;
}

void flip_ud(int anim_frame)
{
auto* texture = fetch_frame(anim_frame);
Expand Down

0 comments on commit d2a5b6e

Please sign in to comment.