diff --git a/HUD/fart_gauge.gd b/HUD/fart_gauge.gd index 0742f8d..a30b2ae 100644 --- a/HUD/fart_gauge.gd +++ b/HUD/fart_gauge.gd @@ -24,6 +24,7 @@ func dash_fart() -> bool: func reset(): animationPlayer.play("RESET") loaded = false + loading = false func _on_animation_player_animation_finished(anim_name: StringName) -> void: if anim_name == "reload": diff --git a/HUD/hud.gd b/HUD/hud.gd index aba51bd..9fc701c 100644 --- a/HUD/hud.gd +++ b/HUD/hud.gd @@ -4,7 +4,11 @@ class_name HUD extends CanvasLayer @onready var gauge2 := $FartGauge2 as FartGauge @onready var gauge3 := $FartGauge3 as FartGauge +@onready var shader := $TransitionShader + signal fart_reloaded() +signal screen_is_black() +signal screen_is_ready() var cheese_number = 0 var gauges = [] @@ -15,7 +19,6 @@ func _ready() -> void: gauge3.connect("reload_done", cheese_loaded) gauges = [gauge1, gauge2, gauge3] - func reset(): cheese_number = 0 for gauge in gauges: @@ -34,3 +37,17 @@ func dash_fart(): func cheese_loaded(): fart_reloaded.emit() + +func begin_scene_transition(): + print("start scene transition") + shader.fade_out() + +func end_scene_transition(): + print("end scene transition") + shader.fade_in() + +func _on_transition_shader_fade_in_done() -> void: + screen_is_ready.emit() + +func _on_transition_shader_fade_out_done() -> void: + screen_is_black.emit() diff --git a/HUD/hud.tscn b/HUD/hud.tscn index f881090..ab6f805 100644 --- a/HUD/hud.tscn +++ b/HUD/hud.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=2 format=3 uid="uid://dvlb4thqhqke"] +[gd_scene load_steps=4 format=3 uid="uid://dvlb4thqhqke"] [ext_resource type="PackedScene" uid="uid://dsgt6b1bqi6ui" path="res://HUD/fart_gauge.tscn" id="1_4e2i3"] +[ext_resource type="Script" path="res://HUD/hud.gd" id="1_e1sc7"] +[ext_resource type="PackedScene" uid="uid://17macg0q4k8l" path="res://shaders/transition_shader.tscn" id="2_gh8iu"] [node name="HUD" type="CanvasLayer"] +script = ExtResource("1_e1sc7") [node name="FartGauge3" parent="." instance=ExtResource("1_4e2i3")] position = Vector2(242, 6) @@ -18,3 +21,10 @@ scale = Vector2(0.7, 0.7) position = Vector2(51, 6) rotation = -1.5708 scale = Vector2(0.7, 0.7) + +[node name="TransitionShader" parent="." instance=ExtResource("2_gh8iu")] +offset_right = 0.0 +offset_bottom = 0.0 + +[connection signal="fade_in_done" from="TransitionShader" to="." method="_on_transition_shader_fade_in_done"] +[connection signal="fade_out_done" from="TransitionShader" to="." method="_on_transition_shader_fade_out_done"] diff --git a/game.gd b/game.gd index aa58fa5..a10f3ea 100644 --- a/game.gd +++ b/game.gd @@ -13,6 +13,9 @@ var last_spawn_point = null var princesse : Princess = null +var goto_destination +var goto_spawn_point + # Called when the node enters the scene tree for the first time. func _ready() -> void: go_to(scene_name, null) @@ -25,11 +28,20 @@ func enter_door(destination : String, other_side_position : Vector2): call_deferred("go_to", destination, other_side_position) func go_to(destination : String, spawn_point): + goto_destination = destination + goto_spawn_point = spawn_point + hud.begin_scene_transition() + +func _on_hud_screen_is_black() -> void: + var destination = goto_destination + var spawn_point = goto_spawn_point + var old_princesse :Princess = null if current_scence: old_princesse = current_scence.find_child("Princesse") old_princesse.disconnect("cheese_collected", hud_load_cheese) old_princesse.disconnect("dash_fart", hud_unload_cheese) + #old_princesse.disconnect("princess_is_dead", princess_death) remove_child(current_scence) if destination == "level_1": @@ -54,6 +66,9 @@ func go_to(destination : String, spawn_point): princesse.copy_from(old_princesse) princesse.connect("cheese_collected", hud_load_cheese) princesse.connect("dash_fart", hud_unload_cheese) + #princesse.connect("princess_is_dead", princess_death) + hud.end_scene_transition() + # vient de la princesse quand elle a ramassé un fromage func hud_load_cheese(): @@ -67,3 +82,6 @@ func hud_unload_cheese(): # quand le fromage est chargé, le jeu le signale à la princesse func _on_hud_fart_reloaded() -> void: princesse.reload_fart() + +func _on_hud_screen_is_ready() -> void: + princesse.go_out_and_play() diff --git a/game.tscn b/game.tscn index 322114b..637611e 100644 --- a/game.tscn +++ b/game.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=4 format=3 uid="uid://dn0b30kvaeasf"] +[gd_scene load_steps=3 format=3 uid="uid://dn0b30kvaeasf"] [ext_resource type="Script" path="res://game.gd" id="1_yny56"] [ext_resource type="PackedScene" uid="uid://dvlb4thqhqke" path="res://HUD/hud.tscn" id="2_0fnfe"] -[ext_resource type="Script" path="res://HUD/hud.gd" id="3_x1wcj"] [node name="game" type="Node"] script = ExtResource("1_yny56") [node name="HUD" parent="." instance=ExtResource("2_0fnfe")] -script = ExtResource("3_x1wcj") [connection signal="fart_reloaded" from="HUD" to="." method="_on_hud_fart_reloaded"] +[connection signal="screen_is_black" from="HUD" to="." method="_on_hud_screen_is_black"] +[connection signal="screen_is_ready" from="HUD" to="." method="_on_hud_screen_is_ready"] diff --git a/princesse.gd b/princesse.gd index 6b6997b..1586983 100644 --- a/princesse.gd +++ b/princesse.gd @@ -512,7 +512,7 @@ func get_new_animation() -> String: return animation_new func _physics_process(_delta: float) -> void: - if dead: + if dead or locked: return compute_state() read_input() @@ -540,7 +540,7 @@ func death() -> void: dead = true death_animation.play(&"death") -func _ready(): +func go_out_and_play(): locked = false dead = false diff --git a/shaders/masks/curtain.png b/shaders/masks/curtain.png new file mode 100644 index 0000000..befa82a Binary files /dev/null and b/shaders/masks/curtain.png differ diff --git a/shaders/masks/curtain.png.import b/shaders/masks/curtain.png.import new file mode 100644 index 0000000..dab45e7 --- /dev/null +++ b/shaders/masks/curtain.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b5mne7k2hxq4m" +path.s3tc="res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://shaders/masks/curtain.png" +dest_files=["res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/shaders/masks/shards.png b/shaders/masks/shards.png new file mode 100644 index 0000000..1d62b47 Binary files /dev/null and b/shaders/masks/shards.png differ diff --git a/shaders/masks/shards.png.import b/shaders/masks/shards.png.import new file mode 100644 index 0000000..8b06b0d --- /dev/null +++ b/shaders/masks/shards.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dwn3g5smhhcb0" +path.s3tc="res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex" +metadata={ +"imported_formats": ["s3tc_bptc"], +"vram_texture": true +} + +[deps] + +source_file="res://shaders/masks/shards.png" +dest_files=["res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex"] + +[params] + +compress/mode=2 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/shaders/transition_shader.gd b/shaders/transition_shader.gd new file mode 100644 index 0000000..c3b50aa --- /dev/null +++ b/shaders/transition_shader.gd @@ -0,0 +1,11 @@ +extends ColorRect + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/shaders/transition_shader.gdshader b/shaders/transition_shader.gdshader new file mode 100644 index 0000000..f1eb889 --- /dev/null +++ b/shaders/transition_shader.gdshader @@ -0,0 +1,16 @@ +shader_type canvas_item; +render_mode unshaded; + +uniform float cutoff: hint_range(0.0, 1.0); +uniform float smooth_size: hint_range(0.0, 0.1); +uniform sampler2D mask: hint_default_black; + +void fragment() { + float value = texture(mask, UV).r; + float alpha = smoothstep( + cutoff, + cutoff + smooth_size, + value * (1.0 - smooth_size) + smooth_size + ); + COLOR = vec4(COLOR.rgb, alpha); +} diff --git a/shaders/transition_shader.tscn b/shaders/transition_shader.tscn new file mode 100644 index 0000000..7c6557c --- /dev/null +++ b/shaders/transition_shader.tscn @@ -0,0 +1,90 @@ +[gd_scene load_steps=8 format=3 uid="uid://17macg0q4k8l"] + +[ext_resource type="Shader" path="res://shaders/transition_shader.gdshader" id="1_kyfmm"] +[ext_resource type="Texture2D" uid="uid://b5mne7k2hxq4m" path="res://shaders/masks/curtain.png" id="2_pg1r4"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_g48os"] +shader = ExtResource("1_kyfmm") +shader_parameter/cutoff = 0.0 +shader_parameter/smooth_size = 0.1 +shader_parameter/mask = ExtResource("2_pg1r4") + +[sub_resource type="GDScript" id="GDScript_rrd13"] +script/source = "class_name FadeShader extends ColorRect + +signal fade_in_done() +signal fade_out_done() + +@onready var player := $\"AnimationPlayer\" as AnimationPlayer + +func fade_in(): + player.play(&\"fade_in\") + +func fade_out(): + player.play(&\"fade_out\") + +func _on_animation_player_animation_finished(anim_name: StringName) -> void: + if anim_name == \"fade_in\": + fade_in_done.emit() + elif anim_name == \"fade_out\": + fade_out_done.emit() +" + +[sub_resource type="Animation" id="Animation_yg4ht"] +resource_name = "fade_in" +length = 0.5 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:material:shader_parameter/cutoff") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0.2, 0.4), +"transitions": PackedFloat32Array(1, 0.450625), +"update": 0, +"values": [0.0, 1.0] +} + +[sub_resource type="Animation" id="Animation_mavdc"] +resource_name = "fade_out" +length = 0.25 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:material:shader_parameter/cutoff") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.2), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [1.0, 0.0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_kedvi"] +_data = { +"fade_in": SubResource("Animation_yg4ht"), +"fade_out": SubResource("Animation_mavdc") +} + +[node name="TransitionShader" type="ColorRect"] +material = SubResource("ShaderMaterial_g48os") +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1680.0 +offset_bottom = -945.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +color = Color(0, 0, 0, 1) +script = SubResource("GDScript_rrd13") + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_kedvi") +} + +[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]