LoginSignup
13
9

More than 3 years have passed since last update.

ダンジョン生成ライブラリの紹介(ローグライク/ワールドマップ/迷路)

Last updated at Posted at 2018-12-16

初代ドラクエ/FFのようなRPGが作りたい……

という夢を叶えます。

RPGを制作するときの難関

戦闘シーンや会話シーンを作成するのは容易であったりしますが、
(他のゲームで使ったコードを容易に代用できたりする)

難易度が高いであろう”マップ生成"があるおかげで
他のゲームに比べ、RPG制作の難易度は高いと思います。

そこで、自動でマップ生成をしてくれるライブラリを紹介します。
"Siv3Dのサンプルコード付き"

地形自動生成ライブラリ

Logo-GIF

ダンジョン生成ライブラリです。

地形自動生成ライブラリ

includeフォルダを指定します。

ワールドマップ(中央に島が出来るタイプ)

1.png

#include <Siv3D.hpp>
#include <DTL.hpp>

#include <cstddef>
#include <array>
#include <bitset>

void Main() {

    constexpr std::size_t matrix_size_x{ 200 };
    constexpr std::size_t matrix_size_y{ 150 };
    constexpr std::size_t dungeon_pixel_size{ 2 };

    Window::Resize(int32(matrix_size_x * dungeon_pixel_size), int32(matrix_size_y * dungeon_pixel_size));

    std::array<std::bitset<matrix_size_x>, matrix_size_y> matrix{ {} };
    dtl::shape::SimpleVoronoiIsland<bool>(100, 0.5, 1, 0).draw(matrix);
    dtl::utility::CellularAutomation<bool>().draw(matrix);

    while (System::Update())
        for (std::size_t row{}; row < matrix.size(); ++row)
            for (std::size_t col{}; col < matrix[row].size(); ++col)
                Rect(int32(col * dungeon_pixel_size), int32(row * dungeon_pixel_size), int32(dungeon_pixel_size)).draw((matrix[row][col]) ? Color(255, 255, 255) : Color(0, 0, 0));

}

ワールドマップ(画面ループタイプ)

2.png

#include <Siv3D.hpp>
#include <DTL.hpp>

#include <cstddef>
#include <array>

void Main() {

    constexpr std::size_t matrix_size_x{ 256 };
    constexpr std::size_t matrix_size_y{ 128 };
    constexpr std::size_t dungeon_pixel_size{ 2 };

    Window::Resize(int32(matrix_size_x * dungeon_pixel_size), int32(matrix_size_y * dungeon_pixel_size));

    std::array<std::array<int, matrix_size_x>, matrix_size_y> matrix{ {} };
    dtl::shape::FractalLoopIsland<int>(0, 80, 40).draw(matrix);
    dtl::utility::Binarization<int>(20).drawOperator(matrix, [](const int value) {return (value >= 55); });
    dtl::utility::CellularAutomation<int>().draw(matrix);

    while (System::Update())
        for (std::size_t row{}; row < matrix.size(); ++row)
            for (std::size_t col{}; col < matrix[row].size(); ++col)
                Rect(int32(col * dungeon_pixel_size), int32(row * dungeon_pixel_size), int32(dungeon_pixel_size)).draw((matrix[row][col]) ? Color(255, 255, 255) : Color(0, 0, 0));

}

※縦横の大きさがともに16の倍数にならないとループしません。

迷路

3.png

#include <Siv3D.hpp>
#include <DTL.hpp>

#include <cstddef>
#include <array>
#include <bitset>

void Main() {

    constexpr std::size_t matrix_size_x{ 200 };
    constexpr std::size_t matrix_size_y{ 150 };
    constexpr std::size_t dungeon_pixel_size{ 2 };

    Window::Resize(int32(matrix_size_x * dungeon_pixel_size), int32(matrix_size_y * dungeon_pixel_size));

    std::array<std::bitset<matrix_size_x>, matrix_size_y> matrix{ {} };
    dtl::shape::MazeDig<bool>(1, 0).draw(matrix);

    while (System::Update())
        for (std::size_t row{}; row < matrix.size(); ++row)
            for (std::size_t col{}; col < matrix[row].size(); ++col)
                Rect(int32(col * dungeon_pixel_size), int32(row * dungeon_pixel_size), int32(dungeon_pixel_size)).draw((matrix[row][col]) ? Color(255, 255, 255) : Color(0, 0, 0));

}

ソースコードのライセンス

These codes are licensed under CC0.
CC0

ソースコードは自由に使用してください。

Siv3Dを利用する際はSiv3Dのライセンス
その他、使用する各ライブラリのライセンスを守って使用してください。

13
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9