Created
June 7, 2018 09:11
-
-
Save sknjpn/de306d4096349e2ed7bafdef227dada0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # include <Siv3D.hpp> // OpenSiv3D v0.2.5 | |
| class Node | |
| { | |
| Vec2 m_position; //物理的な座標 | |
| Point m_point; //仮想上の座標 | |
| public: | |
| Node(Point point) | |
| : m_point(point) | |
| , m_position(point.x + (point.y % 2 ? Cos(60_deg) : 0.0), point.y * Cos(30_deg)) //奇数列は半分ずらし、縦横比も変更 | |
| {} | |
| //getter | |
| Vec2 get_position() const { return m_position; } | |
| }; | |
| void Main() | |
| { | |
| //ポインタ形式のマップデータを作成 | |
| Grid<Node*> nodes(40, 40); | |
| //マップ初期化 | |
| for (auto p : step(nodes.size())) | |
| { | |
| nodes[p.y][p.x] = new Node(p); | |
| } | |
| while (System::Update()) | |
| { | |
| auto r = 16.0; //Node間の距離 | |
| auto hexagon = Shape2D::Hexagon(r / 2.0 / Cos(30_deg)).asPolygon(); //重いので最初に生成しておく | |
| for (auto p : step(nodes.size())) | |
| { | |
| auto* n = nodes[p.y][p.x]; | |
| //マウスからの距離で高度を設定 | |
| auto height = Max(0.0, 1.0 - Cursor::PosF().distanceFrom(n->get_position() * r) / 128.0); | |
| //描画 | |
| hexagon | |
| .movedBy(n->get_position() * r) | |
| .draw(ColorF(Palette::Red, height)) | |
| .drawFrame(KeySpace.pressed() ? 1.0 : 0.0); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment