Skip to content

Instantly share code, notes, and snippets.

@Reputeless
Created December 24, 2019 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reputeless/761a7897767002d4d5db94172ae950b4 to your computer and use it in GitHub Desktop.
Save Reputeless/761a7897767002d4d5db94172ae950b4 to your computer and use it in GitHub Desktop.
# include <Siv3D.hpp> // OpenSiv3D v0.4.2
void Main()
{
const Texture design(U"signboard_t1/design.png");
Grid<std::pair<int32, Texture>> pieces(8, 8);
for (auto p : step(pieces.size()))
{
const int32 index = p.y * 8 + p.x + 1;
pieces[p].first = index;
pieces[p].second = Texture(U"signboard_t1/pieces/p_{}.png"_fmt(index));
}
Grid<bool> locked(8, 8, false);
Optional<Point> selected;
while (System::Update())
{
for (auto p : step(pieces.size()))
{
Rect r = pieces[p].second.draw(p * 32);
r.drawFrame(1, 0, ColorF(0.5, Periodic::Sine0_1(1s)));
if (p == selected)
{
r.draw(ColorF(1, 0.2, 0, 0.3));
}
if (locked[p])
{
r.draw(ColorF(1.0, 1.0, 0.0, 0.2));
}
if (r.leftClicked())
{
if (selected)
{
std::swap(pieces[p], pieces[selected.value()]);
selected = none;
}
else
{
selected = p;
}
}
if (r.rightClicked())
{
locked[p] = !locked[p];
}
}
design.draw(256 + 4, 0);
if (SimpleGUI::Button(U"OK", Vec2(300, 300)))
{
for (auto y : step(pieces.height()))
{
Array<int32> line;
for (auto x : step(pieces.width()))
{
line << pieces[y][x].first;
}
Console << line.join(U" ", U"puts(\"", U"\");");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment