@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.0) | |||
project(swan) | |||
find_package(SDL2 REQUIRED) | |||
find_package(PNG) | |||
option(USE_CLANG_TIDY "Use clang-tidy for additional checks" ON) | |||
if(USE_CLANG_TIDY) | |||
@@ -28,10 +29,6 @@ if(CMAKE_BUILD_TYPE STREQUAL Sanitize OR CMAKE_BUILD_TYPE STREQUAL "") | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Debug) | |||
message(STATUS "Build mode: Debug") | |||
add_compile_options(-g -O0) | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Profile) | |||
message(STATUS "Build mode: Profile") | |||
add_compile_options(-g -Og -pg) | |||
add_link_options(-pg) | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Release) | |||
message(STATUS "Build mode: Release") | |||
add_compile_options(-O3 -flto) | |||
@@ -61,6 +58,10 @@ add_executable(swan | |||
src/main.cc) | |||
target_link_libraries(swan libswan ${libraries}) | |||
add_executable(perlin-test | |||
src/perlin-test.cc) | |||
target_link_libraries(perlin-test libswan PNG::PNG ${libraries}) | |||
set(assets | |||
assets/icon.png | |||
assets/music/happy-1.wav) |
@@ -13,6 +13,7 @@ set(assets | |||
assets/tiles/air.png | |||
assets/tiles/stone.png | |||
assets/tiles/dirt.png | |||
assets/tiles/leaves.png | |||
assets/tiles/tree-trunk.png) | |||
foreach(a ${assets}) | |||
configure_file("${a}" "${a}" COPYONLY) |
@@ -12,6 +12,10 @@ Swan::Tile::ID WGDefault::genTile(Swan::TilePos pos) { | |||
int grass_level = grassLevel(perlin_, pos.x); | |||
int stone_level = stoneLevel(perlin_, pos.x); | |||
// Caves | |||
if (pos.y > grass_level + 7 && perlin_.noise(pos.x / 43.37, pos.y / 16.37) > 0.2) | |||
return tAir_; | |||
if (pos.y > stone_level) | |||
return tStone_; | |||
else if (pos.y > grass_level) |
@@ -0,0 +1,52 @@ | |||
#include <swan/log.h> | |||
#include <PerlinNoise/PerlinNoise.hpp> | |||
#include <png++/png.hpp> | |||
static int grassLevel(const siv::PerlinNoise &perlin, int x) { | |||
return (int)(perlin.noise(x / 50.0, 0) * 13); | |||
} | |||
static int stoneLevel(const siv::PerlinNoise &perlin, int x) { | |||
return (int)(perlin.noise(x / 50.0, 10) * 10) + 10; | |||
} | |||
int main() { | |||
siv::PerlinNoise perlin = siv::PerlinNoise(100); | |||
int x1 = -1600; | |||
int x2 = 1600; | |||
int y1 = -800; | |||
int y2 = 800; | |||
png::image<png::gray_pixel> image(x2 - x1 + 1, y2 - y1 + 1); | |||
Swan::info << "perlin-test.png: " << (x2 - x1 + 1) << "x" << (y2 - y1 + 1); | |||
for (int x = x1; x <= x2; ++x) { | |||
int px = x - x1; | |||
int grass_level = grassLevel(perlin, x); | |||
int stone_level = stoneLevel(perlin, x); | |||
for (int y = y1; y <= y2; ++y) { | |||
int py = y - y1; | |||
if (y > grass_level + 10) { | |||
double l = perlin.noise(x / 41.37, y / 16.37); | |||
if (l > 0.2) | |||
image[py][px] = 255; | |||
else | |||
image[py][px] = 0; | |||
} else if (y >= grass_level) { | |||
image[py][px] = 0; | |||
} else { | |||
image[py][px] = 255; | |||
} | |||
if (y == grass_level) { | |||
image[py][px] = 128; | |||
} | |||
} | |||
} | |||
image.write("perlin-test.png"); | |||
} |