-
-
Notifications
You must be signed in to change notification settings - Fork 82
RPG World Map
Kasugaccho edited this page Aug 22, 2020
·
5 revisions
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)
ใใใ็ตต(40ร40px, 1ใใน)ใฎใฏใผใซใใใใ(8000ร8000px, 200ใใน)ใฎใตใณใใซ็ปๅใงใใ
Copyright (c) 2018-2021 As Project.
Distributed under the Boost Software License, Version 1.0.(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)