From 9fad900a5175a676bb72d44a159e0d3862f74064 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 27 Dec 2021 03:50:11 +0100 Subject: [PATCH] The world generator now will look up the a spawner node, and get the starting coordinates from it. --- .../world_generators/TerraWorldGenerator.gd | 10 ++++++++++ game/tw/TerraWorldBlocky.gd | 14 +++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/game/scripts/world_generators/TerraWorldGenerator.gd b/game/scripts/world_generators/TerraWorldGenerator.gd index 79d2a9db..31c3ff73 100644 --- a/game/scripts/world_generators/TerraWorldGenerator.gd +++ b/game/scripts/world_generators/TerraWorldGenerator.gd @@ -35,9 +35,19 @@ func setup(world : TerraWorld, level_seed : int, spawn_mobs : bool, library: Ter _library = library if world_gen_world != null: + world_gen_world.setup() world_gen_world.setup_terra_library(_library, _level_seed) _library.refresh_rects() +func get_spawn_chunk_position() -> Vector2: + if world_gen_world != null: + var spawner = world_gen_world.get_content_with_name("Spawner") + + if spawner: + return spawner.get_spawn_chunk_position() + + return Vector2() + func _generate_chunk(chunk : TerraChunk) -> void: if world_gen_world == null: return diff --git a/game/tw/TerraWorldBlocky.gd b/game/tw/TerraWorldBlocky.gd index 7eefce7d..d6bbc504 100644 --- a/game/tw/TerraWorldBlocky.gd +++ b/game/tw/TerraWorldBlocky.gd @@ -287,7 +287,7 @@ func spawn(start_x : int, start_z : int) -> void: for x in range(start_x - chunk_spawn_range, chunk_spawn_range + start_x): for z in range(start_z - chunk_spawn_range, chunk_spawn_range + start_z): - + var l : float = (spv - Vector2(x, z)).length() if l > chunk_spawn_range: @@ -346,16 +346,20 @@ func load_character(file_name : String) -> void: _player.set_physics_process(false) mob_level = _player.clevel - - set_player(_player.get_body()) - + #_player.sseed = 2 Server.sset_seed(_player.sseed) if level_generator != null: level_generator.setup(self, _player.sseed, true, library) + + var spawn_chunk_pos : Vector2 = level_generator.get_spawn_chunk_position() + var ppos : Vector3 = Vector3(spawn_chunk_pos.x * chunk_size_x * voxel_scale, 100, spawn_chunk_pos.y * chunk_size_z * voxel_scale) + + _player.set_transform_3d(Transform(Basis(), ppos)) + set_player(_player.get_body()) - spawn(0, 0) + spawn(spawn_chunk_pos.x, spawn_chunk_pos.y) set_process(true)