mirror of
https://github.com/Relintai/broken_seals_2d.git
synced 2024-11-11 20:35:10 +01:00
Setup for multiple world layers. E.g. dungeons.
This commit is contained in:
parent
0fb88a1538
commit
0d31d31204
@ -67,13 +67,13 @@ var casting_anim : bool = false
|
|||||||
|
|
||||||
var last_mouse_over : Entity = null
|
var last_mouse_over : Entity = null
|
||||||
|
|
||||||
var world : Navigation2D = null
|
var world : Node2D = null
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
camera = $Camera as Camera2D
|
camera = $Camera as Camera2D
|
||||||
|
|
||||||
world = get_node(world_path) as Navigation2D
|
world = get_node(world_path) as Node2D
|
||||||
|
|
||||||
func _physics_process(delta : float) -> void:
|
func _physics_process(delta : float) -> void:
|
||||||
if world.initial_generation:
|
if world.initial_generation:
|
||||||
|
@ -33,7 +33,6 @@ func _ready():
|
|||||||
_shape.radius = 50
|
_shape.radius = 50
|
||||||
|
|
||||||
_query = Physics2DShapeQueryParameters.new()
|
_query = Physics2DShapeQueryParameters.new()
|
||||||
_query.collision_layer = 2
|
|
||||||
_query.exclude = [ self ]
|
_query.exclude = [ self ]
|
||||||
_query.shape_rid = _shape.get_rid()
|
_query.shape_rid = _shape.get_rid()
|
||||||
|
|
||||||
@ -50,6 +49,8 @@ func _physics_process(delta):
|
|||||||
update_visibility()
|
update_visibility()
|
||||||
|
|
||||||
func update_visibility() -> void:
|
func update_visibility() -> void:
|
||||||
|
_query.collision_layer = get_collision_layer()
|
||||||
|
|
||||||
_query.transform = Transform2D(0, position)
|
_query.transform = Transform2D(0, position)
|
||||||
var res : Array = get_world_2d().direct_space_state.intersect_shape(_query)
|
var res : Array = get_world_2d().direct_space_state.intersect_shape(_query)
|
||||||
|
|
||||||
|
@ -34,16 +34,19 @@ var _player_file_name : String
|
|||||||
var _player : Entity
|
var _player : Entity
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
get_layer(2)
|
# print(get_layer(2))
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
func get_layer(index : int) -> Navigation2D:
|
func get_layer(index : int) -> Navigation2D:
|
||||||
|
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
|
||||||
var ch : Navigation2D = get_child(index)
|
|
||||||
|
|
||||||
|
|
||||||
return ch
|
|
||||||
|
|
||||||
func load_character(file_name: String) -> void:
|
func load_character(file_name: String) -> void:
|
||||||
_player_file_name = file_name
|
_player_file_name = file_name
|
||||||
|
File diff suppressed because one or more lines are too long
@ -20,3 +20,12 @@ extends Navigation2D
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# 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
|
||||||
|
@ -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://data/tilesets/tileset.tres" type="TileSet" id=1]
|
||||||
|
[ext_resource path="res://world/WorldLayer.gd" type="Script" id=2]
|
||||||
|
|
||||||
[node name="WorldLayer" type="Navigation2D"]
|
[node name="WorldLayer" type="Navigation2D"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Terrarin" type="TileMap" parent="."]
|
[node name="Terrarin" type="TileMap" parent="."]
|
||||||
tile_set = ExtResource( 1 )
|
tile_set = ExtResource( 1 )
|
||||||
|
Loading…
Reference in New Issue
Block a user