Skip to content

Commit 03d162d

Browse files
committed
Add powerup for abilities
1 parent be36e1f commit 03d162d

12 files changed

Lines changed: 340 additions & 0 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: The Threadbare Authors
2+
# SPDX-License-Identifier: MPL-2.0
3+
~ start
4+
[wave amp=25 freq=5]You got a new ability! [b]{{ability_name}}[/b][/wave]
5+
=> END
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[remap]
2+
3+
importer="dialogue_manager"
4+
importer_version=15
5+
type="Resource"
6+
uid="uid://cj0i5jwlv8idi"
7+
path="res://.godot/imported/default_powerup.dialogue-7b4f95958377611890379db90e1904ef.tres"
8+
9+
[deps]
10+
11+
source_file="res://scenes/game_elements/props/powerup/components/default_powerup.dialogue"
12+
dest_files=["res://.godot/imported/default_powerup.dialogue-7b4f95958377611890379db90e1904ef.tres"]
13+
14+
[params]
15+
16+
defaults=true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:85521554f47d1985edb2fa23d6e55702f4f909b28564985522f73ac2cb2cdf9b
3+
size 955
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# SPDX-FileCopyrightText: The Threadbare Authors
2+
# SPDX-License-Identifier: MPL-2.0
3+
@tool
4+
extends Node2D
5+
## A powerup that, when interacted, enables a player ability.
6+
##
7+
## By default it also displays a dialogue telling the player that an ability
8+
## has been obtained.
9+
10+
## The player ability to enable.
11+
@export var ability: Enums.PlayerAbilities = Enums.PlayerAbilities.ABILITY_A
12+
13+
## Name for the ability to display if using the default dialogue.
14+
@export var ability_name: String
15+
16+
## Text to display in the label when the player gets close to interact with this powerup.
17+
@export var interact_action: String:
18+
set = _set_interact_action
19+
20+
## Asset of this powerup.
21+
@export var sprite_frames: SpriteFrames:
22+
set = _set_sprite_frames
23+
24+
## The powerup shines with this color through a shader.
25+
@export var highlight_color: Color = Color.WHITE:
26+
set = _set_highlight_color
27+
28+
## Dialogue to display when collecting the powerup.
29+
@export var dialogue: DialogueResource = preload("uid://cj0i5jwlv8idi")
30+
31+
var _tween: Tween
32+
33+
@onready var interact_area: InteractArea = %InteractArea
34+
@onready var highlight_effect: Sprite2D = %HighlightEffect
35+
@onready var sprite: AnimatedSprite2D = %Sprite
36+
@onready var interact_collision: CollisionShape2D = %InteractCollision
37+
@onready var ground_collision: CollisionShape2D = %GroundCollision
38+
39+
40+
func _set_interact_action(new_interact_action: String) -> void:
41+
interact_action = new_interact_action
42+
if is_node_ready():
43+
interact_area.action = interact_action
44+
45+
46+
func _set_sprite_frames(new_sprite_frames: SpriteFrames) -> void:
47+
sprite_frames = new_sprite_frames
48+
if is_node_ready():
49+
sprite.sprite_frames = sprite_frames
50+
sprite.play("default")
51+
52+
53+
func _set_highlight_color(new_highlight_color: Color) -> void:
54+
highlight_color = new_highlight_color
55+
if is_node_ready():
56+
highlight_effect.modulate = highlight_color
57+
58+
59+
func _ready() -> void:
60+
_set_interact_action(interact_action)
61+
_set_sprite_frames(sprite_frames)
62+
_set_highlight_color(highlight_color)
63+
if Engine.is_editor_hint():
64+
return
65+
GameState.abilities_changed.connect(_on_abilities_changed)
66+
_on_abilities_changed()
67+
68+
69+
func _notification(what: int) -> void:
70+
match what:
71+
NOTIFICATION_EDITOR_PRE_SAVE:
72+
# Since this is a tool script that plays the animations in the
73+
# editor, reset the frame progress before saving the scene.
74+
sprite.frame_progress = 0
75+
76+
77+
func _on_abilities_changed() -> void:
78+
var has_ability := GameState.has_ability(ability)
79+
ground_collision.disabled = has_ability
80+
interact_collision.disabled = has_ability
81+
highlight_effect.visible = not has_ability
82+
var alpha: float = 0.5 if has_ability else 1.0
83+
sprite.modulate = Color(Color.WHITE, alpha)
84+
_set_highlight_color(highlight_color)
85+
var highlight_material := highlight_effect.material as ShaderMaterial
86+
if highlight_material:
87+
highlight_material.set_shader_parameter(&"width", 0.4)
88+
89+
90+
func _on_interact_area_interaction_started(
91+
_player: Player, _from_right: bool, source: InteractArea
92+
) -> void:
93+
if _tween:
94+
_tween.kill()
95+
_tween = create_tween()
96+
_tween.tween_property(highlight_effect, "modulate", Color.WHITE, 0.5)
97+
_tween.tween_property(highlight_effect, "material:shader_parameter/width", 1.0, 1.0)
98+
await _tween.finished
99+
if dialogue:
100+
DialogueManager.show_dialogue_balloon(dialogue, "", [self])
101+
await DialogueManager.dialogue_ended
102+
source.end_interaction()
103+
GameState.set_ability(ability, true)
104+
105+
106+
func _on_interact_area_observers_changed() -> void:
107+
if _tween:
108+
_tween.kill()
109+
_tween = create_tween()
110+
var width: float = 0.8 if interact_area.is_being_observed else 0.4
111+
_tween.tween_property(highlight_effect, "material:shader_parameter/width", width, 1.0)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bhmae3daygmqh
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://dr1cdu5ien6jq"
6+
path="res://.godot/imported/powerup.png-a4ee45e73209b83508bc25ff7865937f.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://scenes/game_elements/props/powerup/components/powerup.png"
14+
dest_files=["res://.godot/imported/powerup.png-a4ee45e73209b83508bc25ff7865937f.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/uastc_level=0
22+
compress/rdo_quality_loss=0.0
23+
compress/hdr_compression=1
24+
compress/normal_map=0
25+
compress/channel_pack=0
26+
mipmaps/generate=false
27+
mipmaps/limit=-1
28+
roughness/mode=0
29+
roughness/src_normal=""
30+
process/channel_remap/red=0
31+
process/channel_remap/green=1
32+
process/channel_remap/blue=2
33+
process/channel_remap/alpha=3
34+
process/fix_alpha_border=true
35+
process/premult_alpha=false
36+
process/normal_map_invert_y=false
37+
process/hdr_as_srgb=false
38+
process/hdr_clamp_exposure=false
39+
process/size_limit=0
40+
detect_3d/compress_to=1
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://bbo1nd3usbxnr"
6+
path="res://.godot/imported/powerup_highlight.png-deef463ba3599bc39e64667d2828727c.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://scenes/game_elements/props/powerup/components/powerup_highlight.png"
14+
dest_files=["res://.godot/imported/powerup_highlight.png-deef463ba3599bc39e64667d2828727c.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/uastc_level=0
22+
compress/rdo_quality_loss=0.0
23+
compress/hdr_compression=1
24+
compress/normal_map=0
25+
compress/channel_pack=0
26+
mipmaps/generate=false
27+
mipmaps/limit=-1
28+
roughness/mode=0
29+
roughness/src_normal=""
30+
process/channel_remap/red=0
31+
process/channel_remap/green=1
32+
process/channel_remap/blue=2
33+
process/channel_remap/alpha=3
34+
process/fix_alpha_border=true
35+
process/premult_alpha=false
36+
process/normal_map_invert_y=false
37+
process/hdr_as_srgb=false
38+
process/hdr_clamp_exposure=false
39+
process/size_limit=0
40+
detect_3d/compress_to=1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Ripple effect
3+
*
4+
* This shader expects the CanvasItem to be a gradient asset that goes from white to transparent.
5+
* It adjusts the alpha to create a ripple effect of a certain width.
6+
*
7+
* SPDX-FileCopyrightText: The Threadbare Authors
8+
* SPDX-License-Identifier: MPL-2.0
9+
*/
10+
shader_type canvas_item;
11+
render_mode blend_add;
12+
13+
/**
14+
* How smooth or sharp are the ripples.
15+
*/
16+
uniform float ease: hint_range(0.0, 2.0) = 2.0;
17+
18+
/**
19+
* This is perceived as the amount of ripples.
20+
*/
21+
uniform float modulo_width: hint_range(0.0, 1.0) = 0.2;
22+
23+
/**
24+
* The ripple width.
25+
*/
26+
uniform float width: hint_range(0.0, 1.0) = 0.4;
27+
28+
/**
29+
* The ripple speed.
30+
*/
31+
uniform float speed: hint_range(0.0, 2.0) = 0.2;
32+
33+
void fragment() {
34+
float sdf_alpha = mod(TIME * speed + COLOR.a, modulo_width);
35+
float front_ease = smoothstep(0, ease, sdf_alpha);
36+
float easeAmount = front_ease * modulo_width;
37+
float brightness = COLOR.a - sdf_alpha + easeAmount;
38+
39+
COLOR.a = smoothstep(1.0 - width, width+(1.0 - width), brightness);
40+
}

0 commit comments

Comments
 (0)