Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

visual invulnerability #104

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion addons/top_down/scenes/actors/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=51 format=3 uid="uid://bmp0g88dtijqw"]
[gd_scene load_steps=55 format=3 uid="uid://bmp0g88dtijqw"]

[ext_resource type="PackedScene" uid="uid://botai66n8rwt3" path="res://addons/top_down/scenes/actors/actor.tscn" id="1_mvls6"]
[ext_resource type="Script" path="res://addons/great_games_library/nodes/ResourceNode/ResourceNodeItem.gd" id="2_20qkb"]
Expand Down Expand Up @@ -31,6 +31,7 @@
[ext_resource type="Script" path="res://addons/top_down/scripts/actor/Player/SafeTileTracker.gd" id="28_ww0nn"]
[ext_resource type="Resource" uid="uid://ct82cq803r2si" path="res://addons/top_down/resources/RoomResources/obstacle_reference.tres" id="29_4dv8f"]
[ext_resource type="Script" path="res://addons/top_down/scripts/actor/Player/HoleRecovery.gd" id="30_n8poo"]
[ext_resource type="Script" path="res://addons/top_down/scripts/actor/VisualInvulnerability.gd" id="32_82fau"]

[sub_resource type="Resource" id="Resource_u7p0r"]
resource_name = "movement properties"
Expand Down Expand Up @@ -222,6 +223,43 @@ value = Array[String]([])
version = 0
not_saved = false

[sub_resource type="Animation" id="Animation_67stq"]
resource_name = "invulnerable"
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("../Body/Stretch/Sprite2D:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(2, 1),
"update": 0,
"values": [Color(0.99, 0.99, 0.99, 1), Color(0.99, 0.99, 0.99, 0.690196)]
}

[sub_resource type="Animation" id="Animation_3p56v"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("../Body/Stretch/Sprite2D:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0.99, 0.99, 0.99, 1)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_f0s3r"]
_data = {
"RESET": SubResource("Animation_3p56v"),
"invulnerable": SubResource("Animation_67stq")
}

[node name="Player" instance=ExtResource("1_mvls6")]
disable_mode = 2
collision_layer = 2
Expand All @@ -234,6 +272,7 @@ list = Array[ExtResource("2_20qkb")]([SubResource("Resource_y1d7o"), SubResource
collision_layer = 2

[node name="Sprite2D" parent="Body/Stretch" index="0"]
modulate = Color(0.99, 0.99, 0.99, 1)
material = SubResource("ShaderMaterial_gfelk")

[node name="CharacterAnimator" parent="Body/Stretch/Sprite2D" index="0"]
Expand Down Expand Up @@ -311,3 +350,15 @@ script = ExtResource("30_n8poo")
safe_tile_tracker = NodePath("../SafeTileTracker")
resource_node = NodePath("../ResourceNode")
hole_trigger = NodePath("../HoleTrigger")

[node name="VisualInvulnerability" type="Node" parent="." index="22" node_paths=PackedStringArray("resource_node", "animation_player")]
script = ExtResource("32_82fau")
resource_node = NodePath("../ResourceNode")
animation_player = NodePath("AnimationPlayer")
animation_invulnerable = &"invulnerable"
animation_normal = &"RESET"

[node name="AnimationPlayer" type="AnimationPlayer" parent="VisualInvulnerability" index="0"]
libraries = {
"": SubResource("AnimationLibrary_f0s3r")
}
19 changes: 19 additions & 0 deletions addons/top_down/scripts/actor/VisualInvulnerability.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class_name VisualInvulnerability
extends Node

@export var resource_node:ResourceNode
@export var animation_player:AnimationPlayer
@export var animation_invulnerable:StringName
@export var animation_normal:StringName

func _ready()->void:
var _receive_damage_bool:BoolResource = resource_node.get_resource("receive_damage")
assert(_receive_damage_bool != null)
_receive_damage_bool.set_false.connect(set_invulnerability_animation.bind(true))
_receive_damage_bool.set_true.connect(set_invulnerability_animation.bind(false))

func set_invulnerability_animation(value:bool)->void:
if value:
animation_player.play(animation_invulnerable)
else:
animation_player.play(animation_normal)
4 changes: 2 additions & 2 deletions addons/top_down/scripts/damage/DamageCooldown.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func start_cooldown()->void:
return
receive_damage_bool.set_value(false)
var _tween:Tween = create_tween()
_tween.tween_callback(receive_damage_bool.set_value.bind(true)).set_delay(cooldown_time)
_tween.tween_callback(on_cooldown_finish)
_tween.tween_callback(on_cooldown_finish).set_delay(cooldown_time)

## Called from tween
func on_cooldown_finish()->void:
receive_damage_bool.set_value(true)
cooldown_finished.emit()
8 changes: 8 additions & 0 deletions addons/top_down/scripts/shaders/color_flash.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ shader_type canvas_item;
uniform vec3 overlay:source_color = vec3(1.0);
uniform float blend:hint_range(0.0, 1.0);

// Modulate color
varying vec4 tint;

void vertex(){
tint = COLOR;
}

void fragment(){
COLOR.rgb = mix(COLOR.rgb, overlay, blend);
COLOR = COLOR * tint;
}