Skip to content

Commit e4a66af

Browse files
committed
player: Add "phase" ability
This adds an action that, while held, temporarily prevents the player-character from colliding with enemies or coins. The new action is bound to: - Player 1: Backspace - Player 2: Tab - Gamepad: Xbox X / PlayStation Square As with the other new actions, the function call to implement this is commented out.
1 parent 42a20a3 commit e4a66af

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

project.godot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ player_2_teleport={
6565
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
6666
]
6767
}
68+
player_2_phase={
69+
"deadzone": 0.2,
70+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
71+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
72+
]
73+
}
6874
player_1_jump={
6975
"deadzone": 0.5,
7076
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
@@ -92,6 +98,12 @@ player_1_teleport={
9298
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
9399
]
94100
}
101+
player_1_phase={
102+
"deadzone": 0.5,
103+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194308,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
104+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
105+
]
106+
}
95107

96108
[layer_names]
97109

scripts/actions.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ACTIONS = [
1313
&"left",
1414
&"right",
1515
&"teleport",
16+
&"phase",
1617
]
1718

1819
# Dictionary[Global.Player, Dictionary[StringName, StringName]]

scripts/player.gd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,36 @@ func _teleport(input_direction: float) -> void:
148148
_teleport_sfx.play()
149149

150150

151+
## If the "phase" action is pressed, make the player-character invulnerable, but also unable to
152+
## interact with coins.
153+
func _phase() -> void:
154+
# Check if the player is holding the "phase" action button.
155+
if Input.is_action_just_pressed(Actions.lookup(player, "phase")):
156+
# While phasing, disable collisions on the PLAYER physics layer.
157+
set_collision_layer_value(Global.PhysicsLayers.PLAYER, false)
158+
set_collision_mask_value(Global.PhysicsLayers.PLAYER, false)
159+
160+
# Make the sprite semitransparent
161+
_sprite.modulate.a = 0.5
162+
163+
# TODO: Is this ability too powerful? Should it have a timer/stamina so the player can only
164+
# use it occasionally and for a short time?
165+
elif Input.is_action_just_released(Actions.lookup(player, "phase")):
166+
# Re-enable collisions on the PLAYER physics layer.
167+
set_collision_layer_value(Global.PhysicsLayers.PLAYER, true)
168+
set_collision_mask_value(Global.PhysicsLayers.PLAYER, true)
169+
170+
# Make the sprite opaque again
171+
_sprite.modulate.a = 1
172+
173+
151174
func _physics_process(delta):
152175
# Don't move if there are no lives left.
153176
if Global.lives <= 0:
154177
return
155178

179+
# _phase()
180+
156181
# Handle jump
157182
if is_on_floor():
158183
coyote_timer = (coyote_time + delta)

0 commit comments

Comments
 (0)