From d7f4d5e9d14137a5162559a0fb14261eb796504d Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 22 Feb 2018 11:30:25 -0500 Subject: [PATCH] [Hero 5] Delete portals in pairs --- scripts/heroes/5_portal.gd | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/scripts/heroes/5_portal.gd b/scripts/heroes/5_portal.gd index 640508e..92fcdaa 100644 --- a/scripts/heroes/5_portal.gd +++ b/scripts/heroes/5_portal.gd @@ -18,6 +18,12 @@ func _ready(): for player in get_node("/root/Level/Players").get_children(): player.connect("body_entered", self, "player_collided", [player]) +func _exit_tree(): + # We delete in pairs + if other: + maker_node.placement.placed.remove(index - 1) + other.queue_free() + func init(maker): var maker_portals = maker.placement.placed @@ -29,33 +35,29 @@ func init(maker): var color = color_set[int(second)] var mat = SpatialMaterial.new() - color.a = 0.5 - mat.flags_transparent = true + # color.a = 0.5 + # mat.flags_transparent = true mat.albedo_color = color get_node("MeshInstance").set_surface_material(0, mat) .init(maker) +func place(): + .place() + var second = index % 2 != 0 + if second: + # Our responsibility to complete the pairing + other = maker_node.placement.placed[index - 1] + other.other = self + func player_collided(with, player): if with == self: portal(player) -func find_other(): - var maker_portals = maker_node.placement.placed - var count = maker_portals.size() - # If index is odd, we're the second (1, 3...), if even, first (0, 4...) - var second = index % 2 != 0 - var delta = -1 if second else 1 - if index + delta < count: - other = maker_portals[index + delta] # Second-to-last: we're already included - return other - else: - return null - func portal(player): if player.player_info.is_right_team == maker_node.player_info.is_right_team: - if find_other(): - var spawn_distance = 2 + if other: + var spawn_distance = 1.75 # Find a sane place to spawn # -Z is in the direction of the portal # X is enough away from the portal to avoid infinite loop