diff options
Diffstat (limited to 'src/tools/world_generator/scripts')
-rw-r--r-- | src/tools/world_generator/scripts/walker_head.gd | 19 | ||||
-rw-r--r-- | src/tools/world_generator/scripts/walker_unit.gd | 6 | ||||
-rw-r--r-- | src/tools/world_generator/scripts/world_generator.gd | 6 |
3 files changed, 19 insertions, 12 deletions
diff --git a/src/tools/world_generator/scripts/walker_head.gd b/src/tools/world_generator/scripts/walker_head.gd index 2ad9650..8bc5c4b 100644 --- a/src/tools/world_generator/scripts/walker_head.gd +++ b/src/tools/world_generator/scripts/walker_head.gd @@ -1,11 +1,13 @@ extends Node2D -export(NodePath) var TILEMAP_NP: NodePath +export(NodePath) var GROUND_TILEMAP_NP: NodePath +export(NodePath) var WALL_TILEMAP_NP: NodePath export(PackedScene) var WALKER_UNIT_NP: PackedScene export(int, 4, 100, 1) var STARTING_UNIT_COUNT: int = 6 export(int, 2, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 2 -onready var tilemap: TileMap = get_node(TILEMAP_NP) +onready var ground_tilemap: TileMap = get_node(GROUND_TILEMAP_NP) +onready var wall_tilemap: TileMap = get_node(WALL_TILEMAP_NP) var max_x: int = 0 var max_y: int = 0 @@ -36,7 +38,11 @@ func _place_safe_zone() -> void: var size: int = INITIAL_SAFE_ZONE_SIZE for i in range(-size, size): for j in range(-size, size): - tilemap.set_cell(i, j, Global.WORLD_TILE_PATH) + ground_tilemap.set_cell(i, j, get_random_tile()) + + +func get_random_tile() -> int: + return randi() % Global.GROUND_TILE_AMOUNT func _spawn_walker_units() -> void: @@ -55,17 +61,18 @@ func _spawn_walker_unit(spawn_position: Vector2) -> void: func _fill_empty_space() -> void: var locations: Array = _get_empty_cells_location() for location in locations: - tilemap.set_cellv(location, Global.WORLD_TILE_WALL) + # doesn't matter which index is set, as long as its form the wall tilemap + wall_tilemap.set_cellv(location, 0) func _get_empty_cells_location() -> Array: var locations: Array = [] - var rect: Rect2 = tilemap.get_used_rect() + var rect: Rect2 = ground_tilemap.get_used_rect() var margin: int = map_margin for x in range(-margin, rect.size.x + margin): for y in range (-margin, rect.size.y + margin): var location: Vector2 = Vector2(rect.position.x + x, rect.position.y + y) - if tilemap.get_cell(int(location.x), int(location.y)) == TileMap.INVALID_CELL: + if ground_tilemap.get_cell(int(location.x), int(location.y)) == TileMap.INVALID_CELL: locations.append(location) return locations diff --git a/src/tools/world_generator/scripts/walker_unit.gd b/src/tools/world_generator/scripts/walker_unit.gd index cfa8f91..3107367 100644 --- a/src/tools/world_generator/scripts/walker_unit.gd +++ b/src/tools/world_generator/scripts/walker_unit.gd @@ -30,7 +30,7 @@ var walk_straight_length: float func start(id: int) -> void: Event.emit_signal("world_gen_walker_started", id) _walker_head = get_parent() - _tilemap = _walker_head.tilemap + _tilemap = _walker_head.ground_tilemap _randomize_stats() var path_steps: Array = _get_path_steps() @@ -70,11 +70,11 @@ func _set_path_tiles(path_steps: Array) -> bool: # get initial tile location var location: Vector2 = get_parent().global_position * Global.TILE_SIZE var move_direction: Vector2 - _set_tile(location, 0) + _set_tile(location, _walker_head.get_random_tile()) for step in path_steps: move_direction = direction[step] location += move_direction * Global.TILE_SIZE - _set_tile(location, Global.WORLD_TILE_PATH) + _set_tile(location, _walker_head.get_random_tile()) if randf() < birth_chance and not given_birth: Event.emit_signal("world_gen_spawn_walker_unit", location) diff --git a/src/tools/world_generator/scripts/world_generator.gd b/src/tools/world_generator/scripts/world_generator.gd index 5de84ea..cbc5dd5 100644 --- a/src/tools/world_generator/scripts/world_generator.gd +++ b/src/tools/world_generator/scripts/world_generator.gd @@ -1,16 +1,16 @@ extends Node2D -onready var tilemap: TileMap = $TileMap +onready var ground_tilemap: TileMap = $GroundTileMap onready var walker_head: Node2D = $WalkerHead func get_valid_map_coords() -> Array: var safe_area: Array = walker_head.get_cells_around() - var cells_used: Array = tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH) + var cells_used: Array = ground_tilemap.get_used_cells() for location in safe_area: cells_used.erase(location) return cells_used func get_centered_world_position(location: Vector2) -> Vector2: - return tilemap.map_to_world(location) + Vector2.ONE * Global.TILE_SIZE / 2.0 + return ground_tilemap.map_to_world(location) + Vector2.ONE * Global.TILE_SIZE / 2.0 |