Skip to content

Commit 6a42b2f

Browse files
committed
WindCurrent.gd: Force-add/-remove all overlapping players when the current is activated/deactivated
1 parent 76dda77 commit 6a42b2f

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

Scripts/Gimmicks/WindCurrent.gd

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ var player_count = 0
1717
# the variable is only set to true after waiting for the fan to start working
1818
@export var activated: bool = true
1919

20+
var players: Array[PlayerChar] = []
21+
2022
signal player_entered
2123
signal all_players_exited
2224

@@ -29,13 +31,13 @@ func _physics_process(_delta: float) -> void:
2931
if not activated:
3032
return
3133

32-
for player: PlayerChar in get_overlapping_bodies():
34+
for player: PlayerChar in players:
3335
# ignore if player is dead or hit
3436
match player.get_state():
3537
PlayerChar.STATES.DIE, PlayerChar.STATES.HIT:
3638
continue
3739

38-
# Ignore if the player is on a gimmick (such as a water bar
40+
# Ignore if the player is on a gimmick (such as a water bar)
3941
if player.get_active_gimmick() != null:
4042
continue
4143

@@ -83,29 +85,48 @@ func _physics_process(_delta: float) -> void:
8385
player.set_state(PlayerChar.STATES.GIMMICK, player.get_predefined_hitbox(PlayerChar.HITBOXES.HORIZONTAL))
8486
player.get_avatar().get_animator().play("current")
8587

88+
func _add_player(player: PlayerChar) -> void:
89+
if player in players:
90+
return
8691

87-
func _on_current_body_entered(body: PlayerChar) -> void:
88-
body.set_gimmick_var("ActiveCurrent", self)
92+
players.append(player)
93+
player.set_gimmick_var("ActiveCurrent", self)
8994
player_entered.emit()
9095
player_count += 1
9196

97+
func _remove_player(player: PlayerChar) -> void:
98+
if not player in players:
99+
return
100+
101+
players.erase(player)
102+
if player.get_gimmick_var("ActiveCurrent") == self:
103+
player.unset_gimmick_var("ActiveCurrent")
104+
if normal_state_on_exit and player.get_state() == PlayerChar.STATES.GIMMICK:
105+
player.set_state(PlayerChar.STATES.NORMAL, player.get_predefined_hitbox(PlayerChar.HITBOXES.HORIZONTAL))
92106

93-
func _on_current_body_exited(body: PlayerChar) -> void:
94-
if body.get_gimmick_var("ActiveCurrent") == self:
95-
body.unset_gimmick_var("ActiveCurrent")
96-
if normal_state_on_exit and body.get_state() == PlayerChar.STATES.GIMMICK:
97-
body.set_state(PlayerChar.STATES.NORMAL, body.get_predefined_hitbox(PlayerChar.HITBOXES.HORIZONTAL))
98-
99107
player_count -= 1
100108
if player_count == 0:
101109
all_players_exited.emit()
102110

111+
112+
func _on_current_body_entered(body: PlayerChar) -> void:
113+
_add_player(body)
114+
115+
func _on_current_body_exited(body: PlayerChar) -> void:
116+
_remove_player(body)
117+
103118
func activate() -> void:
104119
if activated:
105120
return
121+
106122
activated = true
123+
for player: PlayerChar in get_overlapping_bodies():
124+
_add_player(player)
107125

108126
func deactivate() -> void:
109127
if not activated:
110128
return
129+
111130
activated = false
131+
for player: PlayerChar in players:
132+
_remove_player(player)

0 commit comments

Comments
 (0)