Skip to content

RPG World Map

Kasugaccho edited this page Aug 22, 2020 · 5 revisions

ใƒใƒผใ‚ธใƒงใƒณ๏ผš0.4.12.0ไปฅ้™

ๅฎŸ่ฃ…ไพ‹ (C++11)

RPGใฎใƒฏใƒผใƒซใƒ‰ใƒžใƒƒใƒ—ใ‚’็”ปๅƒๅ‡บๅŠ›ใ™ใ‚‹ใƒ—ใƒญใ‚ฐใƒฉใƒ ใงใ™ใ€‚

#include <DTL.hpp>
#include <DTL/ImageWrite.hpp>
#include <cstddef>
#include <cstdint>
#include <new>
#include <memory>

int main() {

	using shape_t = std::uint_fast16_t;
	constexpr std::size_t size_x{ 512 };
	constexpr std::size_t size_y{ 512 };

	//ๆธฉๅบฆ
	std::unique_ptr<shape_t[][size_x] > temperature(new(std::nothrow) shape_t[size_y][size_x]);
	dtl::shape::PerlinIsland<shape_t>(12.0, 6, 240, 100).draw(temperature, size_x, size_y);

	//้™ๆฐด้‡
	std::unique_ptr<shape_t[][size_x] > amount_of_rainfall(new(std::nothrow) shape_t[size_y][size_x]);
	dtl::shape::PerlinIsland<shape_t>(12.0, 6, 225).draw(amount_of_rainfall, size_x, size_y);

	//ๆจ™้ซ˜
	std::unique_ptr<shape_t[][size_x] > elevation(new(std::nothrow) shape_t[size_y][size_x]);
	dtl::shape::PerlinSolitaryIsland<shape_t>(0.3, 0.4, 7.0, 6, 155).draw(elevation, size_x, size_y);

	std::unique_ptr<shape_t[][size_x] > land(new(std::nothrow) shape_t[size_y][size_x]);

	//ใƒใ‚คใ‚ชใƒผใƒ 
	std::unique_ptr<shape_t[][size_x] > biome(new(std::nothrow) shape_t[size_y][size_x]);

	enum : std::size_t {
		field_sea, //ๆตท
		field_lake, //ๆน–
		field_mountain, //ๅฑฑ
		field_desert, //็ ‚ๆผ 
		field_forest, //ๆฃฎๆž—
		field_rock, //ๅฒฉๅฑฑ
		field_hill, //ไธ˜
		field_savannah, //ใ‚ตใƒใƒณใƒŠ
		field_grass, //่‰ๅŽŸ
		field //้€šๅธธใฎๅœฐ้ข
	};

	//ใƒใ‚คใ‚ชใƒผใƒ ใฎๅˆ†้กžๅˆ†ใ‘
	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col) {

			temperature[row][col] -= elevation[row][col] / 2;
			land[row][col] = 1;
			if (elevation[row][col] < 110) {
				biome[row][col] = field_sea;
				land[row][col] = 0;
			}
			else if (temperature[row][col] < 45) biome[row][col] = field_rock;
			else if (amount_of_rainfall[row][col] < 25) biome[row][col] = field_savannah;
			else if (amount_of_rainfall[row][col] < 75) {
				if (temperature[row][col] < 120) biome[row][col] = field_desert;
				else biome[row][col] = field_desert;
			}
			else if (temperature[row][col] < 69) biome[row][col] = field_grass;
			else if (temperature[row][col] < 96) biome[row][col] = field;
			else if (temperature[row][col] < 120) biome[row][col] = field_forest;
			else if (amount_of_rainfall[row][col] < 125) biome[row][col] = field_mountain;
			else if (temperature[row][col] < 132) biome[row][col] = field_mountain;
			else biome[row][col] = field_mountain;
		}
	
	dtl::retouch::Bucket<shape_t>(1, 0, 0).draw(land, size_x, size_y);

	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col) {
			if (elevation[row][col] < 110 && land[row][col] == 0) biome[row][col] = field_lake;
		}

	dtl::storage::FilePNG<shape_t>("file_sample_rpg_world_map.png", 3).write(biome, size_x, size_y, [](const shape_t value, unsigned char* const color) {
		switch (value) {
		case field_sea:
			color[0] = 33;
			color[1] = 97;
			color[2] = 124;
			break;
		case field_lake:
			color[0] = 88;
			color[1] = 124;
			color[2] = 139;
			break;
		case field_mountain:
			color[0] = 101;
			color[1] = 100;
			color[2] = 60;
			break;
		case field_desert:
			color[0] = 217;
			color[1] = 195;
			color[2] = 143;
			break;
		case field_forest:
			color[0] = 110;
			color[1] = 149;
			color[2] = 59;
			break;
		case field_rock:
			color[0] = 120;
			color[1] = 125;
			color[2] = 108;
			break;
		case field_hill:
			color[0] = 145;
			color[1] = 177;
			color[2] = 113;
			break;
		case field_savannah:
			color[0] = 144;
			color[1] = 140;
			color[2] = 73;
			break;
		case field_grass:
			color[0] = 90;
			color[1] = 128;
			color[2] = 63;
			break;
		case field:
			color[0] = 139;
			color[1] = 181;
			color[2] = 59;
			break;
		}
		});

	return 0;
}

ๅ‡บๅŠ›

ๅ‡บๅŠ›็”ปๅƒ(512ร—512px)

wm512

็”ปๅƒ

ใƒ‰ใƒƒใƒˆ็ตต(40ร—40px, 1ใƒžใ‚น)ใฎใƒฏใƒผใƒซใƒ‰ใƒžใƒƒใƒ—(8000ร—8000px, 200ใƒžใ‚น)ใฎใ‚ตใƒณใƒ—ใƒซ็”ปๅƒใงใ™ใ€‚

wm8000 wm8000 wm8000 wm8000

้–ข้€ฃ้ …็›ฎ

dtl::shape::PerlinSolitaryIsland

dtl::shape::PerlinIsland

dtl::utility::PerlinNoise

dtl::shape::PerlinLoopIsland

RPG World Map Cliff

RPG World Map Cliff Planet

Clone this wiki locally