initial biome generation with forest support
This commit is contained in:
parent
4d7af7ed69
commit
4030f040b6
10 changed files with 200 additions and 12 deletions
BIN
maps/varkaus_10x10km_1000px.png
Normal file
BIN
maps/varkaus_10x10km_1000px.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 131 KiB |
14
maps/varkaus_10x10km_1000px.png.import
Normal file
14
maps/varkaus_10x10km_1000px.png.import
Normal file
|
@ -0,0 +1,14 @@
|
|||
[remap]
|
||||
|
||||
importer="image"
|
||||
type="Image"
|
||||
uid="uid://bujeshs11asmb"
|
||||
path="res://.godot/imported/varkaus_10x10km_1000px.png-e4dfbae59b6511cd7f5092e2690ac3e6.image"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://maps/varkaus_10x10km_1000px.png"
|
||||
dest_files=["res://.godot/imported/varkaus_10x10km_1000px.png-e4dfbae59b6511cd7f5092e2690ac3e6.image"]
|
||||
|
||||
[params]
|
||||
|
BIN
maps/varkaus_10x10km_2160px.png
Normal file
BIN
maps/varkaus_10x10km_2160px.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
34
maps/varkaus_10x10km_2160px.png.import
Normal file
34
maps/varkaus_10x10km_2160px.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c6sheli4j1m6x"
|
||||
path="res://.godot/imported/varkaus_10x10km_2160px.png-c01279e17674065996861dce21d58a5f.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://maps/varkaus_10x10km_2160px.png"
|
||||
dest_files=["res://.godot/imported/varkaus_10x10km_2160px.png-c01279e17674065996861dce21d58a5f.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
BIN
maps/varkaus_256x256px_test.png
Normal file
BIN
maps/varkaus_256x256px_test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
14
maps/varkaus_256x256px_test.png.import
Normal file
14
maps/varkaus_256x256px_test.png.import
Normal file
|
@ -0,0 +1,14 @@
|
|||
[remap]
|
||||
|
||||
importer="image"
|
||||
type="Image"
|
||||
uid="uid://boqavhoxnpyla"
|
||||
path="res://.godot/imported/varkaus_256x256px_test.png-473f28b8dc9e0f5d18c042490c776914.image"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://maps/varkaus_256x256px_test.png"
|
||||
dest_files=["res://.godot/imported/varkaus_256x256px_test.png-473f28b8dc9e0f5d18c042490c776914.image"]
|
||||
|
||||
[params]
|
||||
|
20
scenes/BiomeNoiseTesting.tscn
Normal file
20
scenes/BiomeNoiseTesting.tscn
Normal file
|
@ -0,0 +1,20 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://d373de88jug8x"]
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_ncuso"]
|
||||
noise_type = 3
|
||||
seed = 35
|
||||
frequency = 0.008
|
||||
fractal_octaves = 3
|
||||
fractal_lacunarity = 1.0
|
||||
fractal_gain = 1.746
|
||||
fractal_ping_pong_strength = 25.0
|
||||
domain_warp_fractal_type = 2
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_l3pkr"]
|
||||
width = 1024
|
||||
height = 1024
|
||||
noise = SubResource("FastNoiseLite_ncuso")
|
||||
|
||||
[node name="BiomeNoise" type="Sprite2D"]
|
||||
position = Vector2(528, 520)
|
||||
texture = SubResource("NoiseTexture2D_l3pkr")
|
|
@ -506,7 +506,14 @@ texture = ExtResource("5_bqev6")
|
|||
2:1/0 = 0
|
||||
3:1/0 = 0
|
||||
4:1/0 = 0
|
||||
5:1/next_alternative_id = 4
|
||||
5:1/0 = 0
|
||||
5:1/1 = 1
|
||||
5:1/1/flip_h = true
|
||||
5:1/2 = 2
|
||||
5:1/2/flip_v = true
|
||||
5:1/3 = 3
|
||||
5:1/3/transpose = true
|
||||
6:1/0 = 0
|
||||
7:1/0 = 0
|
||||
8:1/0 = 0
|
||||
|
|
|
@ -10,14 +10,14 @@ class_name Main
|
|||
extends Node
|
||||
|
||||
# The idea is for the user to be able to choose the map from GUI later
|
||||
var map_filename: String = "res://maps/tampere_200px_crop.png"
|
||||
var map_filename: String = "res://maps/varkaus_256x256px_test.png"
|
||||
var _world := World.new()
|
||||
var _world_generator := WorldGeneration.new()
|
||||
|
||||
func _init():
|
||||
DisplayServer.window_set_size(
|
||||
#Vector2i(Globals.DEFAULT_X_RES, Globals.DEFAULT_Y_RES)
|
||||
Vector2i(2560,1440)
|
||||
Vector2i(3800,2000)
|
||||
)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
|
|
@ -14,6 +14,25 @@ var directions:Array = [
|
|||
|
||||
var count:int = 0
|
||||
|
||||
func choose_forest_tile(tile:Vector2i) -> Vector2i:
|
||||
var surrounding_tiles:Array = []
|
||||
|
||||
# determine which directions have forest around the tile
|
||||
for dir in directions:
|
||||
# avoid index out of bounds
|
||||
if (tile.y+dir.y >= Globals.map_image_size.y) or (tile.x+dir.x >= Globals.map_image_size.x):
|
||||
surrounding_tiles.append(Globals.TILE_TERRAIN)
|
||||
elif map_tile_data[tile.y+dir.y][tile.x+dir.x] == Globals.TILE_FOREST:
|
||||
surrounding_tiles.append(Globals.TILE_FOREST)
|
||||
continue
|
||||
surrounding_tiles.append(Globals.TILE_TERRAIN)
|
||||
|
||||
var selected_tile = match_forest_tile(surrounding_tiles)
|
||||
if selected_tile.x == -1 or selected_tile.y == -1:
|
||||
selected_tile = Vector2i(0,0)
|
||||
|
||||
return selected_tile
|
||||
|
||||
func choose_tile(tile:Vector2i) -> Vector2i:
|
||||
var surrounding_tiles:Array = []
|
||||
|
||||
|
@ -36,11 +55,42 @@ func choose_tile(tile:Vector2i) -> Vector2i:
|
|||
func choose_randomly(list_of_entries:Array[int]) -> int:
|
||||
return list_of_entries[randi() % list_of_entries.size()]
|
||||
|
||||
#
|
||||
# Generates biomes, like forest and bog
|
||||
#
|
||||
func generate_biomes() -> void:
|
||||
pass
|
||||
|
||||
print("biome generation")
|
||||
var fnl = FastNoiseLite.new()
|
||||
fnl.noise_type = FastNoiseLite.TYPE_PERLIN
|
||||
fnl.seed = randi()
|
||||
fnl.frequency = 0.1
|
||||
fnl.fractal_type = FastNoiseLite.FRACTAL_FBM
|
||||
fnl.fractal_octaves = 3
|
||||
fnl.fractal_lacunarity = 1
|
||||
fnl.fractal_gain = 1.746
|
||||
|
||||
var water_next_to_tile:bool = false
|
||||
|
||||
#var noise_img = Image.new()
|
||||
#noise_img = fnl.get_image(Globals.map_image_size.x, Globals.map_image_size.y)
|
||||
for y in map_tile_data.size():
|
||||
for x in map_tile_data[y].size():
|
||||
# replace non-water with biomes
|
||||
if map_tile_data[y][x] > 0:
|
||||
water_next_to_tile = false
|
||||
# don't put forest next to water
|
||||
for dir in directions:
|
||||
if (y+dir.y >= Globals.map_image_size.y) or (x+dir.x >= Globals.map_image_size.x):
|
||||
continue
|
||||
if map_tile_data[y+dir.y][x+dir.x] == Globals.TILE_WATER:
|
||||
water_next_to_tile = true
|
||||
|
||||
if !water_next_to_tile:
|
||||
var noise_sample = fnl.get_noise_2d(x,y)
|
||||
if noise_sample < 0.1:
|
||||
count += 1
|
||||
map_tile_data[y][x] = Globals.TILE_FOREST
|
||||
|
||||
print("maata korvattu ", count)
|
||||
|
||||
func generate_world(filename) -> bool:
|
||||
# Try to load the image which we used to place water & ground to world map
|
||||
|
@ -59,7 +109,6 @@ func generate_world(filename) -> bool:
|
|||
smooth_land_features()
|
||||
generate_biomes()
|
||||
set_tilemap_tiles()
|
||||
#print("Recursions:", count)
|
||||
|
||||
# center camera to world map
|
||||
emit_signal(
|
||||
|
@ -69,8 +118,51 @@ func generate_world(filename) -> bool:
|
|||
)
|
||||
return true
|
||||
|
||||
func match_forest_tile(surrounding_tiles) -> Vector2i:
|
||||
match surrounding_tiles:
|
||||
# 4 forest tiles around land
|
||||
[2,2,2,2]:
|
||||
return Vector2i(5,1) # forest tile
|
||||
|
||||
# 3 forest tiles around land
|
||||
[2,2,2,1]:
|
||||
return Vector2i(5,1) # forest tile
|
||||
[2,2,1,2]:
|
||||
return Vector2i(5,1) # forest tile
|
||||
[2,1,2,2]:
|
||||
return Vector2i(5,1) # forest tile
|
||||
[1,2,2,2]:
|
||||
return Vector2i(5,1) # forest tile
|
||||
|
||||
# 2 forest tiles around land
|
||||
[2,2,1,1]: # south & east
|
||||
return Vector2i(28,0)
|
||||
[1,2,2,1]: # north & east
|
||||
return Vector2i(26,0)
|
||||
[1,1,2,2]: # north & west
|
||||
return Vector2i(24,0)
|
||||
[2,1,1,2]: # south & west
|
||||
return Vector2i(22,0)
|
||||
|
||||
# 1 forest tile around land
|
||||
[1,1,1,2]: # west only
|
||||
return Vector2i(23,0)
|
||||
[1,1,2,1]: # north only
|
||||
return Vector2i(25,0)
|
||||
[1,2,1,1]: # east only
|
||||
return Vector2i(27,0)
|
||||
[2,1,1,1]: # south only
|
||||
return Vector2i(29,0)
|
||||
|
||||
_: # otherwise skip drawing
|
||||
return Vector2i(-1,-1)
|
||||
|
||||
func match_tile(surrounding_tiles) -> Vector2i:
|
||||
match surrounding_tiles:
|
||||
# 4 land tiles around water
|
||||
[1,1,1,1]:
|
||||
return Vector2i(0,0) # land tile
|
||||
|
||||
# 3 land tiles around water
|
||||
[1,1,1,0]:
|
||||
return Vector2i(0,0) # land tile
|
||||
|
@ -136,7 +228,15 @@ func set_tilemap_tiles() -> void:
|
|||
Globals.LAYER_TERRAIN,
|
||||
Vector2i(x, y),
|
||||
2,
|
||||
Vector2i(0,0),
|
||||
choose_forest_tile(Vector2i(x,y)),
|
||||
0
|
||||
)
|
||||
Globals.TILE_FOREST:
|
||||
Globals.world_map.set_cell(
|
||||
Globals.LAYER_TERRAIN,
|
||||
Vector2i(x, y),
|
||||
2,
|
||||
Vector2i(5,1),
|
||||
choose_randomly([0,1,2,3])
|
||||
)
|
||||
_: #default
|
||||
|
@ -146,7 +246,7 @@ func set_tilemap_tiles() -> void:
|
|||
# Fill water tiles, surrounded in 3-4 sides by land, with land.
|
||||
# Do it recursively with limit of n recursions!
|
||||
func smooth_land_features() -> void:
|
||||
# for testing avoid map borders to make it simpler to implement
|
||||
# TODO for testing avoid map borders to make it simpler to implement
|
||||
for y in range(1, Globals.map_image_size.y-1):
|
||||
for x in range(1, Globals.map_image_size.x-1):
|
||||
if map_tile_data[y][x] != Globals.TILE_WATER:
|
||||
|
@ -158,7 +258,6 @@ func smooth_recursively(pos:Vector2i) -> void:
|
|||
# now we are supposed to be inspecting a tile with land
|
||||
# 1 = water 0 = land
|
||||
var surrounding_tiles:Array = []
|
||||
count += 1
|
||||
|
||||
# determine which directions have land around the tile
|
||||
for dir in directions:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue