Setup for multiple world layers. E.g. dungeons.

This commit is contained in:
Relintai 2019-12-22 21:49:05 +01:00
parent 0fb88a1538
commit 0d31d31204
6 changed files with 32 additions and 13 deletions

View File

@ -67,13 +67,13 @@ var casting_anim : bool = false
var last_mouse_over : Entity = null
var world : Navigation2D = null
var world : Node2D = null
func _ready() -> void:
camera = $Camera as Camera2D
world = get_node(world_path) as Navigation2D
world = get_node(world_path) as Node2D
func _physics_process(delta : float) -> void:
if world.initial_generation:

View File

@ -33,7 +33,6 @@ func _ready():
_shape.radius = 50
_query = Physics2DShapeQueryParameters.new()
_query.collision_layer = 2
_query.exclude = [ self ]
_query.shape_rid = _shape.get_rid()
@ -50,6 +49,8 @@ func _physics_process(delta):
update_visibility()
func update_visibility() -> void:
_query.collision_layer = get_collision_layer()
_query.transform = Transform2D(0, position)
var res : Array = get_world_2d().direct_space_state.intersect_shape(_query)

View File

@ -34,17 +34,20 @@ var _player_file_name : String
var _player : Entity
func _ready():
get_layer(2)
# print(get_layer(2))
pass # Replace with function body.
func get_layer(index : int) -> Navigation2D:
var ch : Navigation2D = get_child(index)
for ch in get_children():
if ch.has_method('collision_layer') and ch.collision_layer() == index:
return ch
var wl : Navigation2D = world_layer.instance() as Navigation2D
add_child(wl)
wl.collision_layer = index
return wl
func load_character(file_name: String) -> void:
_player_file_name = file_name
_player = Entities.load_player(file_name, Vector2(5, 5), 1) as Entity

File diff suppressed because one or more lines are too long

View File

@ -20,3 +20,12 @@ extends Navigation2D
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
var collision_layer : int
func add_entity(entity : Entity) -> void:
entity.owner = self
entity.collision_layer = collision_layer
func get_collision_layer() -> int:
return collision_layer

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://data/tilesets/tileset.tres" type="TileSet" id=1]
[ext_resource path="res://world/WorldLayer.gd" type="Script" id=2]
[node name="WorldLayer" type="Navigation2D"]
script = ExtResource( 2 )
[node name="Terrarin" type="TileMap" parent="."]
tile_set = ExtResource( 1 )