Skip to content

Commit e72401f

Browse files
authored
Merge pull request #44 from endlessm/specials
Add special abilities, commented out by default
2 parents 8a13ef0 + 4643c11 commit e72401f

File tree

8 files changed

+203
-1
lines changed

8 files changed

+203
-1
lines changed
4.35 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[remap]
2+
3+
importer="oggvorbisstr"
4+
type="AudioStreamOggVorbis"
5+
uid="uid://dmx2rtf2vy1"
6+
path="res://.godot/imported/244654__dsg__pop-2.ogg-27b8aa37b813c338a8b122e748e26d18.oggvorbisstr"
7+
8+
[deps]
9+
10+
source_file="res://assets/sounds/244654__dsg__pop-2.ogg"
11+
dest_files=["res://.godot/imported/244654__dsg__pop-2.ogg-27b8aa37b813c338a8b122e748e26d18.oggvorbisstr"]
12+
13+
[params]
14+
15+
loop=false
16+
loop_offset=0
17+
bpm=0
18+
beat_count=0
19+
bar_beats=4
30.9 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[remap]
2+
3+
importer="oggvorbisstr"
4+
type="AudioStreamOggVorbis"
5+
uid="uid://p0b3e0t7h8j3"
6+
path="res://.godot/imported/596541__tothrec2__large-wings-flapping-foley.ogg-715998e9d4f908348de867f3ceb6fce5.oggvorbisstr"
7+
8+
[deps]
9+
10+
source_file="res://assets/sounds/596541__tothrec2__large-wings-flapping-foley.ogg"
11+
dest_files=["res://.godot/imported/596541__tothrec2__large-wings-flapping-foley.ogg-715998e9d4f908348de867f3ceb6fce5.oggvorbisstr"]
12+
13+
[params]
14+
15+
loop=false
16+
loop_offset=0
17+
bpm=0
18+
beat_count=0
19+
bar_beats=4

components/player/player.tscn

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://8st4scqt06l8"]
1+
[gd_scene load_steps=9 format=3 uid="uid://8st4scqt06l8"]
22

33
[ext_resource type="Script" uid="uid://umb21eb2y1oj" path="res://scripts/player.gd" id="1_w3ms2"]
44
[ext_resource type="SpriteFrames" uid="uid://bo581k1esb50n" path="res://components/player/spriteframes-red.tres" id="2_msaml"]
5+
[ext_resource type="AudioStream" uid="uid://dmx2rtf2vy1" path="res://assets/sounds/244654__dsg__pop-2.ogg" id="3_ph1f6"]
56
[ext_resource type="AudioStream" uid="uid://bx1joarpc14j5" path="res://assets/sounds/538066__stevielematt__boing.ogg" id="3_wa6cj"]
7+
[ext_resource type="AudioStream" uid="uid://p0b3e0t7h8j3" path="res://assets/sounds/596541__tothrec2__large-wings-flapping-foley.ogg" id="4_mpawu"]
68

79
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_7x5a4"]
810
radius = 31.0
@@ -13,6 +15,11 @@ random_pitch = 1.1
1315
streams_count = 1
1416
stream_0/stream = ExtResource("3_wa6cj")
1517

18+
[sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_ph1f6"]
19+
random_pitch = 1.2
20+
streams_count = 1
21+
stream_0/stream = ExtResource("3_ph1f6")
22+
1623
[node name="Player" type="CharacterBody2D" groups=["players"]]
1724
collision_layer = 3
1825
collision_mask = 5
@@ -51,3 +58,12 @@ one_way_collision = true
5158
[node name="JumpSFX" type="AudioStreamPlayer" parent="SoundEffects"]
5259
unique_name_in_owner = true
5360
stream = SubResource("AudioStreamRandomizer_mpawu")
61+
62+
[node name="GlideSFX" type="AudioStreamPlayer" parent="SoundEffects"]
63+
unique_name_in_owner = true
64+
stream = ExtResource("4_mpawu")
65+
66+
[node name="TeleportSFX" type="AudioStreamPlayer" parent="SoundEffects"]
67+
unique_name_in_owner = true
68+
stream = SubResource("AudioStreamRandomizer_ph1f6")
69+
volume_db = -10.0

project.godot

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ player_2_right={
5959
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":1,"axis":0,"axis_value":1.0,"script":null)
6060
]
6161
}
62+
player_2_teleport={
63+
"deadzone": 0.5,
64+
"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":4194325,"key_label":0,"unicode":0,"location":1,"echo":false,"script":null)
65+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
66+
]
67+
}
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+
}
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+
}
6282
player_1_jump={
6383
"deadzone": 0.5,
6484
"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)
@@ -80,6 +100,25 @@ player_1_right={
80100
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
81101
]
82102
}
103+
player_1_teleport={
104+
"deadzone": 0.5,
105+
"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":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
106+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
107+
]
108+
}
109+
player_1_phase={
110+
"deadzone": 0.5,
111+
"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)
112+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
113+
]
114+
}
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+
}
83122

84123
[layer_names]
85124

scripts/actions.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const ACTIONS = [
1212
&"jump",
1313
&"left",
1414
&"right",
15+
&"teleport",
16+
&"phase",
17+
&"shrink",
1518
]
1619

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

scripts/player.gd

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ class_name Player
33
extends CharacterBody2D
44
## A player's character, which can walk, jump, and stomp on enemies.
55

6+
## The player-character's maximum downwards speed while gliding.
7+
## Making this number smaller allows the player to glide further.
8+
## [br][br]
9+
## Used by [method _glide].
10+
const GLIDE_TERMINAL_VELOCITY = 100
11+
12+
## How many pixels the player-character should teleport horizontally when the
13+
## teleport special ability is used.
14+
## [br][br]
15+
## Used by [method _teleport].
16+
const TELEPORT_DISTANCE = 512
17+
18+
## How much to scale [member jump_velocity] when the player-character is shrunk. Setting this close
19+
## to or below [code]0[/code] prevents jumping; setting this to [code]1[/code] or greater causes
20+
## jumps while shrunk to be the same as normal size.
21+
## [br][br]
22+
## Used by [method _shrink].
23+
const JUMP_VELOCITY_SCALE_WHEN_SMALL = 0.85
24+
625
## Which player controls this character?
726
@export var player: Global.Player = Global.Player.ONE
827

@@ -52,11 +71,16 @@ var double_jump_armed: bool = false
5271
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
5372
var original_position: Vector2
5473

74+
# Whether the player-character is currently shrunk. See _shrink().
75+
var _is_shrunk := false
76+
5577
@onready var _sprite: AnimatedSprite2D = %AnimatedSprite2D
5678
@onready var _initial_sprite_frames: SpriteFrames = %AnimatedSprite2D.sprite_frames
5779
@onready var _double_jump_particles: CPUParticles2D = %DoubleJumpParticles
5880

5981
@onready var _jump_sfx: AudioStreamPlayer = %JumpSFX
82+
@onready var _glide_sfx: AudioStreamPlayer = %GlideSFX
83+
@onready var _teleport_sfx: AudioStreamPlayer = %TeleportSFX
6084

6185

6286
func _set_sprite_frames(new_sprite_frames):
@@ -106,11 +130,87 @@ func stomp():
106130
_jump()
107131

108132

133+
## If the player-character is in the air, and the "jump" action is held, clamp the downwards
134+
## velocity to a constant. Must be called after applying gravity to the player-character.
135+
func _glide() -> void:
136+
if not is_on_floor() and Input.is_action_pressed(Actions.lookup(player, "jump")):
137+
if velocity.y > GLIDE_TERMINAL_VELOCITY:
138+
velocity.y = GLIDE_TERMINAL_VELOCITY
139+
140+
# Only play the sound effect when the player-character is moving downwards, not while
141+
# jumping upwards
142+
if velocity.y > 0 and not _glide_sfx.playing:
143+
_glide_sfx.play()
144+
elif _glide_sfx.playing:
145+
_glide_sfx.stop()
146+
147+
148+
## If the "teleport" action is pressed, and the player is moving the character horizontally,
149+
## teleport the character in that horizontal direction.
150+
func _teleport(input_direction: float) -> void:
151+
if (
152+
Input.is_action_just_pressed(Actions.lookup(player, "teleport"))
153+
and not is_zero_approx(input_direction)
154+
):
155+
# TODO: Check if we are teleporting into a wall (in which case the player should lose a
156+
# life) or an enemy (in which case maybe the enemy should be telefragged/defeated?)
157+
global_position.x += TELEPORT_DISTANCE * input_direction
158+
_teleport_sfx.play()
159+
160+
161+
## If the "phase" action is pressed, make the player-character invulnerable, but also unable to
162+
## interact with coins.
163+
func _phase() -> void:
164+
# Check if the player is holding the "phase" action button.
165+
if Input.is_action_just_pressed(Actions.lookup(player, "phase")):
166+
# While phasing, disable collisions on the PLAYER physics layer.
167+
set_collision_layer_value(Global.PhysicsLayers.PLAYER, false)
168+
set_collision_mask_value(Global.PhysicsLayers.PLAYER, false)
169+
170+
# Make the sprite semitransparent
171+
_sprite.modulate.a = 0.5
172+
173+
# TODO: Is this ability too powerful? Should it have a timer/stamina so the player can only
174+
# use it occasionally and for a short time?
175+
elif Input.is_action_just_released(Actions.lookup(player, "phase")):
176+
# Re-enable collisions on the PLAYER physics layer.
177+
set_collision_layer_value(Global.PhysicsLayers.PLAYER, true)
178+
set_collision_mask_value(Global.PhysicsLayers.PLAYER, true)
179+
180+
# Make the sprite opaque again
181+
_sprite.modulate.a = 1
182+
183+
184+
## When the "shrink" action is pressed, toggle the player between normal size and half-size. While
185+
## shrunk, the player can pass through narrower passages, but cannot jump so high.
186+
func _shrink() -> void:
187+
if Input.is_action_just_pressed(Actions.lookup(player, "shrink")):
188+
_is_shrunk = not _is_shrunk
189+
190+
if _is_shrunk:
191+
# Shrink the player-character's sprite and collision shape
192+
scale = Vector2(0.5, 0.5)
193+
else:
194+
scale = Vector2(1, 1)
195+
196+
if _is_shrunk:
197+
# Reduce the jump height while shrunk. _jump() sets velocity.y to -jump_velocity, so
198+
# clamping this to a smaller value cuts the initial upwards velocity, and hence the jump
199+
# height.
200+
if velocity.y < -jump_velocity * JUMP_VELOCITY_SCALE_WHEN_SMALL:
201+
velocity.y = -jump_velocity * JUMP_VELOCITY_SCALE_WHEN_SMALL
202+
203+
# TODO: should there be other consequences to being small? Could we make the player somehow more
204+
# vulnerable to enemies?
205+
206+
109207
func _physics_process(delta):
110208
# Don't move if there are no lives left.
111209
if Global.lives <= 0:
112210
return
113211

212+
# _phase()
213+
114214
# Handle jump
115215
if is_on_floor():
116216
coyote_timer = (coyote_time + delta)
@@ -131,6 +231,8 @@ func _physics_process(delta):
131231
if coyote_timer <= 0:
132232
velocity.y += gravity * delta
133233

234+
# _shrink()
235+
134236
# Get the input direction and handle the movement/deceleration.
135237
var direction = Input.get_axis(Actions.lookup(player, "left"), Actions.lookup(player, "right"))
136238
if direction:
@@ -142,6 +244,8 @@ func _physics_process(delta):
142244
else:
143245
velocity.x = move_toward(velocity.x, 0, acceleration * delta)
144246

247+
# _glide()
248+
145249
if velocity == Vector2.ZERO:
146250
_sprite.play("idle")
147251
else:
@@ -156,6 +260,8 @@ func _physics_process(delta):
156260

157261
move_and_slide()
158262

263+
# _teleport(direction)
264+
159265
coyote_timer -= delta
160266
jump_buffer_timer -= delta
161267

0 commit comments

Comments
 (0)