5 #include "../graphics/Canvas.h"
10 Tileset::Tileset(Texture &&tex, Vector<int> size)
11 : sprite(std::move(tex), size / 2)
19 void Tileset::DrawFG(Canvas &canv, Vector<int> to, const World &world, Vector<int> at) {
20 const Tile &mid = world.TileAt(at);
21 if (!mid.HasFG()) return;
23 const Vector<int> ul = at + Vector<int>(-1, -1);
24 const Vector<int> u = at + Vector<int>(0, -1);
25 const Vector<int> ur = at + Vector<int>(1, -1);
26 const Vector<int> l = at + Vector<int>(-1, 0);
27 const Vector<int> r = at + Vector<int>(1, 0);
28 const Vector<int> dl = at + Vector<int>(-1, 1);
29 const Vector<int> d = at + Vector<int>(0, 1);
30 const Vector<int> dr = at + Vector<int>(1, 1);
32 const bool mul = !world.InBounds(ul) || world.TileAt(ul).MatchesFG(mid);
33 const bool mu = !world.InBounds(u) || world.TileAt(u).MatchesFG(mid);
34 const bool mur = !world.InBounds(ur) || world.TileAt(ur).MatchesFG(mid);
35 const bool ml = !world.InBounds(l) || world.TileAt(l).MatchesFG(mid);
36 const bool mr = !world.InBounds(r) || world.TileAt(r).MatchesFG(mid);
37 const bool mdl = !world.InBounds(dl) || world.TileAt(dl).MatchesFG(mid);
38 const bool md = !world.InBounds(d) || world.TileAt(d).MatchesFG(mid);
39 const bool mdr = !world.InBounds(dr) || world.TileAt(dr).MatchesFG(mid);
41 const int tl = (ml << 2) | (mul << 1) | (mu);
42 const int tr = (mr << 2) | (mur << 1) | (mu);
43 const int bl = (ml << 2) | (mdl << 1) | (md);
44 const int br = (mr << 2) | (mdr << 1) | (md);
46 const Vector<int> off = Vector<int>(0, mid.GetFG() * subCount.y);
47 sprite.Draw(Vector<int>(off.x + tl, off.y), canv, to);
48 sprite.Draw(Vector<int>(off.x + tr, off.y + 1), canv, Vector<int>(to.x + subSize.x, to.y));
49 sprite.Draw(Vector<int>(off.x + bl, off.y + 2), canv, Vector<int>(to.x, to.y + subSize.y));
50 sprite.Draw(Vector<int>(off.x + br, off.y + 3), canv, Vector<int>(to.x + subSize.x, to.y + subSize.y));