summaryrefslogtreecommitdiff
path: root/src/tools/world_generator/scripts
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-05 04:38:44 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-05 04:38:44 -0600
commite4423cc8490b7f5ec3449f568bf64e81f4d03248 (patch)
tree167f178e1197c21260f70eaffd0a3375742f3447 /src/tools/world_generator/scripts
parent36abc689d783774ce4f2d7b5a1bb621d8684be45 (diff)
add more food types, refactored code and tidy up stuff
Diffstat (limited to 'src/tools/world_generator/scripts')
-rw-r--r--src/tools/world_generator/scripts/walker_head.gd42
-rw-r--r--src/tools/world_generator/scripts/world_generator.gd10
2 files changed, 39 insertions, 13 deletions
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)
diff --git a/src/tools/world_generator/scripts/world_generator.gd b/src/tools/world_generator/scripts/world_generator.gd
index 5e8626b..5de84ea 100644
--- a/src/tools/world_generator/scripts/world_generator.gd
+++ b/src/tools/world_generator/scripts/world_generator.gd
@@ -1,11 +1,15 @@
extends Node2D
-export(NodePath) var TILEMAP_NP: NodePath
-onready var tilemap: TileMap = get_node(TILEMAP_NP)
+onready var tilemap: TileMap = $TileMap
+onready var walker_head: Node2D = $WalkerHead
func get_valid_map_coords() -> Array:
- return tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH)
+ var safe_area: Array = walker_head.get_cells_around()
+ var cells_used: Array = tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH)
+ for location in safe_area:
+ cells_used.erase(location)
+ return cells_used
func get_centered_world_position(location: Vector2) -> Vector2: