move shoreline setting to be part of set_tilemap_tiles
This commit is contained in:
parent
7651e574c1
commit
4d7af7ed69
2 changed files with 25 additions and 33 deletions
|
@ -10,7 +10,7 @@ class_name Main
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
# The idea is for the user to be able to choose the map from GUI later
|
# The idea is for the user to be able to choose the map from GUI later
|
||||||
var map_filename: String = "res://maps/tampere_10x10km_1000px.png"
|
var map_filename: String = "res://maps/tampere_200px_crop.png"
|
||||||
var _world := World.new()
|
var _world := World.new()
|
||||||
var _world_generator := WorldGeneration.new()
|
var _world_generator := WorldGeneration.new()
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,25 @@ var directions:Array = [
|
||||||
|
|
||||||
var count:int = 0
|
var count:int = 0
|
||||||
|
|
||||||
|
func choose_tile(tile:Vector2i) -> Vector2i:
|
||||||
|
var surrounding_tiles:Array = []
|
||||||
|
|
||||||
|
# determine which directions have land 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_WATER)
|
||||||
|
elif map_tile_data[tile.y+dir.y][tile.x+dir.x] == Globals.TILE_TERRAIN:
|
||||||
|
surrounding_tiles.append(Globals.TILE_TERRAIN)
|
||||||
|
continue
|
||||||
|
surrounding_tiles.append(Globals.TILE_WATER)
|
||||||
|
|
||||||
|
var selected_tile = match_tile(surrounding_tiles)
|
||||||
|
if selected_tile.x == -1 or selected_tile.y == -1:
|
||||||
|
selected_tile = Vector2i(1,0)
|
||||||
|
|
||||||
|
return selected_tile
|
||||||
|
|
||||||
func choose_randomly(list_of_entries:Array[int]) -> int:
|
func choose_randomly(list_of_entries:Array[int]) -> int:
|
||||||
return list_of_entries[randi() % list_of_entries.size()]
|
return list_of_entries[randi() % list_of_entries.size()]
|
||||||
|
|
||||||
|
@ -40,8 +59,7 @@ func generate_world(filename) -> bool:
|
||||||
smooth_land_features()
|
smooth_land_features()
|
||||||
generate_biomes()
|
generate_biomes()
|
||||||
set_tilemap_tiles()
|
set_tilemap_tiles()
|
||||||
set_shorelines()
|
#print("Recursions:", count)
|
||||||
print(count)
|
|
||||||
|
|
||||||
# center camera to world map
|
# center camera to world map
|
||||||
emit_signal(
|
emit_signal(
|
||||||
|
@ -98,46 +116,19 @@ func read_image_pixel_data():
|
||||||
if image.get_pixel(x, y) == Globals.WATER_TILE_COLOR_IN_MAP_FILE:
|
if image.get_pixel(x, y) == Globals.WATER_TILE_COLOR_IN_MAP_FILE:
|
||||||
map_tile_data[y][x] = Globals.TILE_WATER
|
map_tile_data[y][x] = Globals.TILE_WATER
|
||||||
else:
|
else:
|
||||||
map_tile_data[y][x] = Globals.TILE_TERRAIN
|
map_tile_data[y][x] = Globals.TILE_TERRAIN
|
||||||
|
|
||||||
func set_shorelines() -> void:
|
|
||||||
# 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):
|
|
||||||
# skip tiles with land
|
|
||||||
if map_tile_data[y][x] != Globals.TILE_WATER:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# now we are supposed to be inspecting a tile with land
|
|
||||||
# 1 = water 0 = land
|
|
||||||
var surrounding_tiles:Array = []
|
|
||||||
|
|
||||||
# determine which directions have land around the tile
|
|
||||||
for dir in directions:
|
|
||||||
if map_tile_data[y+dir.y][x+dir.x] == Globals.TILE_TERRAIN:
|
|
||||||
surrounding_tiles.append(Globals.TILE_TERRAIN)
|
|
||||||
continue
|
|
||||||
surrounding_tiles.append(Globals.TILE_WATER)
|
|
||||||
|
|
||||||
var selected_tile = match_tile(surrounding_tiles)
|
|
||||||
if selected_tile.x == -1 or selected_tile.y == -1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile
|
|
||||||
Globals.world_map.set_cell(Globals.LAYER_TERRAIN, Vector2i(x, y), 2, selected_tile, 0)
|
|
||||||
|
|
||||||
func set_tilemap_tiles() -> void:
|
func set_tilemap_tiles() -> void:
|
||||||
for y in map_tile_data.size():
|
for y in map_tile_data.size():
|
||||||
for x in map_tile_data[y].size():
|
for x in map_tile_data[y].size():
|
||||||
# layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile
|
# layer | position coords | tilemap id | coords of the tile at tilemap | alternative tile
|
||||||
# set water or ground
|
|
||||||
match map_tile_data[y][x]:
|
match map_tile_data[y][x]:
|
||||||
Globals.TILE_WATER:
|
Globals.TILE_WATER:
|
||||||
Globals.world_map.set_cell(
|
Globals.world_map.set_cell(
|
||||||
Globals.LAYER_TERRAIN,
|
Globals.LAYER_TERRAIN,
|
||||||
Vector2i(x, y),
|
Vector2i(x, y),
|
||||||
2,
|
2,
|
||||||
Vector2i(15,5),
|
choose_tile(Vector2i(x, y)), # choose tile based on surrounding tiles
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
Globals.TILE_TERRAIN:
|
Globals.TILE_TERRAIN:
|
||||||
|
@ -150,6 +141,7 @@ func set_tilemap_tiles() -> void:
|
||||||
)
|
)
|
||||||
_: #default
|
_: #default
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Fill water tiles, surrounded in 3-4 sides by land, with land.
|
# Fill water tiles, surrounded in 3-4 sides by land, with land.
|
||||||
# Do it recursively with limit of n recursions!
|
# Do it recursively with limit of n recursions!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue