From e4423cc8490b7f5ec3449f568bf64e81f4d03248 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sun, 5 Jun 2022 04:38:44 -0600 Subject: add more food types, refactored code and tidy up stuff --- src/tools/world_generator/scripts/walker_head.gd | 42 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'src/tools/world_generator/scripts/walker_head.gd') diff --git a/src/tools/world_generator/scripts/walker_head.gd b/src/tools/world_generator/scripts/walker_head.gd index dc71db1..2ad9650 100644 --- a/src/tools/world_generator/scripts/walker_head.gd +++ b/src/tools/world_generator/scripts/walker_head.gd @@ -2,8 +2,8 @@ extends Node2D export(NodePath) var TILEMAP_NP: NodePath export(PackedScene) var WALKER_UNIT_NP: PackedScene -export(int, 5, 100, 1) var STARTING_UNIT_COUNT: int = 5 -export(int, 3, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 3 +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) @@ -23,6 +23,15 @@ func _ready() -> void: _fill_empty_space() +func get_cells_around(size: int=INITIAL_SAFE_ZONE_SIZE) -> Array: + var locations: Array = [] + for i in range(-size, size): + for j in range(-size, size): + locations.append(Vector2(i, j)) + + return locations + + func _place_safe_zone() -> void: var size: int = INITIAL_SAFE_ZONE_SIZE for i in range(-size, size): @@ -44,27 +53,40 @@ 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) + + +func _get_empty_cells_location() -> Array: + var locations: Array = [] var rect: Rect2 = 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 poses: Vector2= Vector2(rect.position.x + x, rect.position.y + y) - if tilemap.get_cell(int(poses.x), int(poses.y)) == TileMap.INVALID_CELL: - tilemap.set_cellv(poses, Global.WORLD_TILE_WALL) + 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: + locations.append(location) + + return locations func _on_world_gen_walker_started(id: int) -> void: - print("Walker unit %s started." % id) + # print("Walker unit %s started." % id) + pass func _on_world_gen_walker_finished(id: int) -> void: - print("Walker unit %s finished." % id) + # print("Walker unit %s finished." % id) + pass func _on_world_gen_walker_died(id: int) -> void: - print("Walker unit %s died." % id) + # print("Walker unit %s died." % id) + pass func _on_world_gen_spawn_walker_unit(location: Vector2) -> void: - print("Spawning new walking unit.") + # print("Spawning new walking unit.") + pass _spawn_walker_unit(location) -- cgit v1.2.3