Skip to content
Closed
53 changes: 48 additions & 5 deletions scenes/game_elements/props/projectile/components/projectile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ extends RigidBody2D
## root node. When the projectile gets hit, the [member GPUParticles2D.amount_ratio] is set to 1.
@export var trail_fx_scene: PackedScene

@export var blink_animation_player: AnimationPlayer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a documentation comment explaining that this AnimationPlayer needs to have an animation called "dissapear". By the way, I think that the animation can be called "blink". And even better, we can add a warning in the editor when the AnimationPlayer that was set in the Inspector doesn't have one. But I can open a separate ticket for it.

Also please move the @export_group("Dissapear Clue") line above this one, so this export belongs to that group. Would you agree with that?


@export_group("Dissapear Clue")

## The time in seconds to show the disappear animation.
@export_range(0.0, 10.0, 0.5) var blink_duration: float = 3.0
Comment on lines +70 to +71

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"blink duration" reads to me as the duration of one blink. Sorry if I caused this trouble in previous reviews, but this should be named dissapear_duration to match the documentation comment.


## The number of times the projectile blinks before disappearing.
@export_range(1, 10, 1) var blink_times: int = 3

var blink_effect_time: float

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is not needed, it can be calculated when needeed with duration, dissapear_duration and blink_times.

var blink_timer: Timer
var _trail_particles: GPUParticles2D

@onready var visible_things: Node2D = %VisibleThings
Expand All @@ -71,7 +83,7 @@ var _trail_particles: GPUParticles2D

## How long the projectile lives in the scene.
## [br][br]
## This timer is restarted each time the projectile collides with anything.
## This timer is restarted each time the projectile collies with anything.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## This timer is restarted each time the projectile collies with anything.
## This timer is restarted each time the projectile collides with anything.

## So the life of the projectile is extended in each collision.
@onready var duration_timer: Timer = %DurationTimer

Expand Down Expand Up @@ -112,6 +124,19 @@ func _ready() -> void:
var impulse: Vector2 = direction * speed
apply_impulse(impulse)

if blink_animation_player:
#If the blink duration is greater than the duration
#The minimun time the animation will spend is 3 seconds.
var time_to_dissapear: float = max(3.0, duration - blink_duration)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this 3 seconds come from? I think that if the dissapear duration is greater than the duration, it should start blinking immediately. You had this right before.

blink_timer = Timer.new()
blink_timer.wait_time = time_to_dissapear
blink_timer.one_shot = true
blink_timer.timeout.connect(_on_blink_timer_timeout)
add_child(blink_timer)
blink_timer.start()

blink_effect_time = (duration - time_to_dissapear) / blink_times


func _process(_delta: float) -> void:
visible_things.rotation = linear_velocity.angle()
Expand All @@ -135,8 +160,7 @@ func add_small_fx() -> void:


func _on_body_entered(body: Node2D) -> void:
add_small_fx()
duration_timer.start()
_on_projectile_hit()

# Logic for Fragile Barrel
# We must check for the specific subclass first because it inherits from FillingBarrel
Expand All @@ -156,8 +180,7 @@ func _on_body_entered(body: Node2D) -> void:
## Called from the Repel component when this body
## enters the repel area.
func got_repelled(repel_direction: Vector2) -> void:
add_small_fx()
duration_timer.start()
_on_projectile_hit()
var hit_vector: Vector2 = repel_direction * hit_speed
hit_sound.play()
animated_sprite_2d.speed_scale = 2
Expand Down Expand Up @@ -186,3 +209,23 @@ func _on_duration_timer_timeout() -> void:
func remove() -> void:
await get_tree().create_timer(randf_range(0., 3.)).timeout
explode()


func _on_blink_timer_timeout() -> void:
var animation_duration: float = blink_animation_player.get_animation("dissapear").length
blink_animation_player.play("dissapear", -1, animation_duration / blink_effect_time)


func _on_projectile_hit() -> void:
add_small_fx()

# Reset timers and blink animation:
duration_timer.start()

if blink_animation_player:
#If the projectile collides with another object or is repelled the animation and timer will reset
if blink_timer.is_stopped():
blink_animation_player.play("RESET")
blink_timer.start()
else:
blink_timer.start()
Comment on lines +229 to +231

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If and else have the same content, is better to do:

Suggested change
blink_timer.start()
else:
blink_timer.start()
blink_timer.start()

45 changes: 44 additions & 1 deletion scenes/game_elements/props/projectile/ink_blob_projectile.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,45 @@ bounce = 1.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o6xl0"]
size = Vector2(44, 44)

[node name="InkBlobProjectile" type="RigidBody2D" unique_id=1611529190 groups=["projectiles"]]
[sub_resource type="Animation" id="Animation_inmjt"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1.0]
}

[sub_resource type="Animation" id="Animation_41322"]
resource_name = "disappear"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [0.8, 0.25, 0.8]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_3lot6"]
_data = {
&"RESET": SubResource("Animation_inmjt"),
&"dissapear": SubResource("Animation_41322")
}

[node name="InkBlobProjectile" type="RigidBody2D" unique_id=1611529190 node_paths=PackedStringArray("blink_animation_player") groups=["projectiles"]]
collision_layer = 256
collision_mask = 80
mass = 0.3
Expand All @@ -28,6 +66,8 @@ script = ExtResource("1_gkhfg")
small_fx_scene = ExtResource("3_inmjt")
big_fx_scene = ExtResource("4_41322")
trail_fx_scene = ExtResource("5_3lot6")
blink_animation_player = NodePath("AnimationPlayer")
blink_times = 5

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested before, let's reset this to the default.


[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1499726276]
shape = SubResource("RectangleShape2D_o6xl0")
Expand All @@ -53,5 +93,8 @@ unique_name_in_owner = true
stream = ExtResource("3_faii4")
bus = &"SFX"

[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=304068808]
libraries/ = SubResource("AnimationLibrary_3lot6")

[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="timeout" from="DurationTimer" to="." method="_on_duration_timer_timeout"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you changed this level by accident, while testing. Please revert it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still the case.

Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ metadata/_custom_type_script = "uid://du8wfijr35r35"
[node name="CollisionShape2D" type="CollisionShape2D" parent="OnTheGround/Helper/InteractArea" unique_id=498179141]
position = Vector2(0, -23.5)
shape = SubResource("RectangleShape2D_0kgrx")
debug_color = Color(0.6, 0.545, 0, 0.42)
debug_color = Color(0.600391, 0.54335, 0, 0.42)

[node name="HelperCharacter" type="Node" parent="OnTheGround/Helper" unique_id=660836413]
script = ExtResource("27_6bwsk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,45 @@ bounce = 1.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o6xl0"]
size = Vector2(44, 44)

[node name="NoEditProjectile" type="RigidBody2D" unique_id=1611529190 groups=["projectiles"]]
[sub_resource type="Animation" id="Animation_w1dj1"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1.0]
}

[sub_resource type="Animation" id="Animation_lrx48"]
resource_name = "dissapear"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:modulate:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [0.8, 0.25, 0.8]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_us7pj"]
_data = {
&"RESET": SubResource("Animation_w1dj1"),
&"dissapear": SubResource("Animation_lrx48")
}

[node name="NoEditProjectile" type="RigidBody2D" unique_id=1611529190 node_paths=PackedStringArray("blink_animation_player") groups=["projectiles"]]
collision_layer = 256
collision_mask = 80
mass = 0.3
Expand All @@ -21,6 +59,7 @@ continuous_cd = 2
contact_monitor = true
max_contacts_reported = 1
script = ExtResource("1_kxdg3")
blink_animation_player = NodePath("AnimationPlayer")

[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1499726276]
shape = SubResource("RectangleShape2D_o6xl0")
Expand All @@ -45,5 +84,8 @@ unique_name_in_owner = true
unique_name_in_owner = true
bus = &"SFX"

[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=902059992]
libraries/ = SubResource("AnimationLibrary_us7pj")

[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="timeout" from="DurationTimer" to="." method="_on_duration_timer_timeout"]
Loading