mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-25 00:54:19 +00:00
Only materialize if there's room
This commit is contained in:
parent
13d4813526
commit
850612104b
4 changed files with 18 additions and 5 deletions
|
@ -49,7 +49,4 @@ volume_db = -24.397
|
|||
wait_time = 2.108
|
||||
one_shot = true
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||
[connection signal="sleeping_state_changed" from="." to="." method="_on_sleeping_state_changed"]
|
||||
[connection signal="collected" from="Collectible" to="Collectible" method="_on_done"]
|
||||
|
|
|
@ -92,6 +92,8 @@ func _on_ghost_requested(scene: PackedScene, texture: Texture2D):
|
|||
|
||||
func _on_ghost_materialize():
|
||||
var instantiated = ghost.materialize()
|
||||
if not instantiated:
|
||||
return #TODO FIXME
|
||||
var spawner = instantiated.find_child("Spawner")
|
||||
if spawner != null:
|
||||
spawner.target = self
|
||||
|
|
|
@ -82,7 +82,7 @@ scene = ExtResource("13_4j8om")
|
|||
target = NodePath("..")
|
||||
buffer_cap = 1
|
||||
spawn_rect = Rect2(-20, 0, 40, 0)
|
||||
overlapping_body_count_limit = 128
|
||||
overlapping_body_count_limit = 16
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="NeckShape" type="CollisionShape2D" parent="DebugSpawner"]
|
||||
|
|
|
@ -34,6 +34,7 @@ var can_place: bool:
|
|||
get:
|
||||
return can_place
|
||||
set(value):
|
||||
can_place = value
|
||||
if value:
|
||||
preview_sprite.modulate = Color(1.0, 1.0, 1.0, 0.5)
|
||||
else:
|
||||
|
@ -70,8 +71,9 @@ func _input(event: InputEvent):
|
|||
position += delta
|
||||
last_input_event = event
|
||||
|
||||
## Update the value of [can_place].
|
||||
# DIRTY HACK: Relies on the placeable area being perfectly surrounded by solid bodies.
|
||||
func _physics_process(_delta: float):
|
||||
func update_can_place():
|
||||
var no_overlapping_bodies: bool = true
|
||||
var overlapping_bodies = get_overlapping_bodies()
|
||||
for body in overlapping_bodies:
|
||||
|
@ -87,6 +89,7 @@ func _physics_process(_delta: float):
|
|||
if area is PlaceableArea:
|
||||
is_in_placeable_area = true
|
||||
|
||||
print("[Ghost] No overlap: ", no_overlapping_bodies, " | In area: ", is_in_placeable_area)
|
||||
can_place = no_overlapping_bodies and is_in_placeable_area
|
||||
|
||||
|
||||
|
@ -99,7 +102,18 @@ func _physics_process(_delta: float):
|
|||
## Emitted when the [materialize] function has finished executing.
|
||||
signal materialized(node: Node)
|
||||
|
||||
|
||||
func _physics_process(_delta: float):
|
||||
update_can_place()
|
||||
|
||||
func materialize():
|
||||
if not can_place:
|
||||
return null
|
||||
var overlapping_bodies = get_overlapping_bodies()
|
||||
for body in overlapping_bodies:
|
||||
if body is PhysicsBody2D:
|
||||
if body.collision_layer & collision_mask_delete_placement:
|
||||
body.queue_free()
|
||||
var instantiated = scene_to_instantiate.instantiate()
|
||||
instantiated.global_position = global_position
|
||||
instantiated.rotation = rotation
|
||||
|
|
Loading…
Reference in a new issue