Skip to content

Commit b5a9569

Browse files
committed
player: Add "shrink" special ability
As with the other special abilities, the function call in _physics_process() that implements this ability is commented out.
1 parent b390a54 commit b5a9569

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

project.godot

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ player_2_phase={
7171
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
7272
]
7373
}
74+
player_2_shrink={
75+
"deadzone": 0.5,
76+
"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":83,"key_label":0,"unicode":111,"location":0,"echo":false,"script":null)
77+
, 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":83,"physical_keycode":0,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
78+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
79+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":7,"pressure":0.0,"pressed":true,"script":null)
80+
]
81+
}
7482
player_1_jump={
7583
"deadzone": 0.5,
7684
"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)
@@ -104,6 +112,13 @@ player_1_phase={
104112
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
105113
]
106114
}
115+
player_1_shrink={
116+
"deadzone": 0.5,
117+
"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":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
118+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
119+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":7,"pressure":0.0,"pressed":true,"script":null)
120+
]
121+
}
107122

108123
[layer_names]
109124

scripts/actions.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const ACTIONS = [
1414
&"right",
1515
&"teleport",
1616
&"phase",
17+
&"shrink",
1718
]
1819

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

scripts/player.gd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extends CharacterBody2D
55

66
const GLIDE_TERMINAL_VELOCITY = 100
77
const TELEPORT_DISTANCE = 512
8+
const JUMP_VELOCITY_SCALE_WHEN_SMALL = 0.85
89

910
## Which player controls this character?
1011
@export var player: Global.Player = Global.Player.ONE
@@ -55,6 +56,8 @@ var double_jump_armed: bool = false
5556
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
5657
var original_position: Vector2
5758

59+
var _is_shrunk := false
60+
5861
@onready var _sprite: AnimatedSprite2D = %AnimatedSprite2D
5962
@onready var _initial_sprite_frames: SpriteFrames = %AnimatedSprite2D.sprite_frames
6063
@onready var _double_jump_particles: CPUParticles2D = %DoubleJumpParticles
@@ -158,6 +161,21 @@ func _phase() -> void:
158161
_sprite.modulate.a = 1
159162

160163

164+
func _shrink() -> void:
165+
if Input.is_action_just_pressed(Actions.lookup(player, "shrink")):
166+
_is_shrunk = not _is_shrunk
167+
168+
if _is_shrunk:
169+
# Shrink the player-character's sprite and collision shape
170+
scale = Vector2(0.5, 0.5)
171+
else:
172+
scale = Vector2(1, 1)
173+
174+
if _is_shrunk:
175+
if velocity.y < -jump_velocity * JUMP_VELOCITY_SCALE_WHEN_SMALL:
176+
velocity.y = -jump_velocity * JUMP_VELOCITY_SCALE_WHEN_SMALL
177+
178+
161179
func _physics_process(delta):
162180
# Don't move if there are no lives left.
163181
if Global.lives <= 0:
@@ -185,6 +203,8 @@ func _physics_process(delta):
185203
if coyote_timer <= 0:
186204
velocity.y += gravity * delta
187205

206+
# _shrink()
207+
188208
# Get the input direction and handle the movement/deceleration.
189209
var direction = Input.get_axis(Actions.lookup(player, "left"), Actions.lookup(player, "right"))
190210
if direction:

0 commit comments

Comments
 (0)