End sequence

master
Wynd 2024-09-22 18:12:16 +03:00
parent 23b26d0f35
commit 6e20d982c3
4 changed files with 86 additions and 24 deletions

View File

@ -4,6 +4,7 @@ extends CharacterBody2D
@onready var death_sfx = preload("res://scenes/assets/jingles/fail.wav") @onready var death_sfx = preload("res://scenes/assets/jingles/fail.wav")
@onready var raycast: RayCast2D = $RayCast2D @onready var raycast: RayCast2D = $RayCast2D
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D @onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var map: MainLevel = get_tree().root.get_child(0).get_node("TileMap") @onready var map: MainLevel = get_tree().root.get_child(0).get_node("TileMap")
@onready var tile_map: TileMapLayer = get_tree().root.get_child(0).get_node("TileMap/TileMapLayer") @onready var tile_map: TileMapLayer = get_tree().root.get_child(0).get_node("TileMap/TileMapLayer")
@onready var camera: Camera2D = $AnimatedSprite2D/Camera2D @onready var camera: Camera2D = $AnimatedSprite2D/Camera2D
@ -26,6 +27,8 @@ var rng := RandomNumberGenerator.new()
var camera_shake: float = 0.0 var camera_shake: float = 0.0
var camera_shake_fade: float = 0.0 var camera_shake_fade: float = 0.0
var attack_frame := 0 var attack_frame := 0
var lock_for_end := false
var end_tick := 0
func _ready(): func _ready():
_respawn() _respawn()
@ -59,18 +62,26 @@ func _respawn():
func _try_get_input(): func _try_get_input():
should_move = false should_move = false
if Input.is_action_pressed("move_up"): if not lock_for_end:
if Input.is_action_pressed("move_up"):
input_dir = Vector2.UP
should_move = true
elif Input.is_action_pressed("move_right"):
input_dir = Vector2.RIGHT
should_move = true
elif Input.is_action_pressed("move_down"):
input_dir = Vector2.DOWN
should_move = true
elif Input.is_action_pressed("move_left"):
input_dir = Vector2.LEFT
should_move = true
else:
input_dir = Vector2.UP input_dir = Vector2.UP
should_move = true should_move = true
elif Input.is_action_pressed("move_right"): end_tick += 1
input_dir = Vector2.RIGHT
should_move = true if end_tick > 250:
elif Input.is_action_pressed("move_down"): animation_player.play(&"end")
input_dir = Vector2.DOWN
should_move = true
elif Input.is_action_pressed("move_left"):
input_dir = Vector2.LEFT
should_move = true
_change_sprite() _change_sprite()
@ -141,6 +152,9 @@ func apply_camera_shake(strength: float = 10.0, fade: float = 5.0):
camera_shake_fade = fade camera_shake_fade = fade
func _try_interact(): func _try_interact():
if lock_for_end:
return
raycast.target_position = input_dir * 8 raycast.target_position = input_dir * 8
raycast.force_raycast_update() raycast.force_raycast_update()
@ -163,3 +177,7 @@ func _shake_camera(delta):
func _on_area_entered(area: Area2D): func _on_area_entered(area: Area2D):
if area.is_in_group("death"): if area.is_in_group("death"):
die() die()
func _on_animation_player_animation_finished(anim_name: String):
if anim_name == &"end":
get_tree().quit()

View File

@ -98,7 +98,7 @@ animations = [{
"duration": 1.0, "duration": 1.0,
"texture": SubResource("AtlasTexture_okcjq") "texture": SubResource("AtlasTexture_okcjq")
}], }],
"loop": false, "loop": true,
"name": &"move_down", "name": &"move_down",
"speed": 10.0 "speed": 10.0
}, { }, {
@ -115,7 +115,7 @@ animations = [{
"duration": 1.0, "duration": 1.0,
"texture": SubResource("AtlasTexture_580lu") "texture": SubResource("AtlasTexture_580lu")
}], }],
"loop": false, "loop": true,
"name": &"move_right", "name": &"move_right",
"speed": 10.0 "speed": 10.0
}, { }, {
@ -132,7 +132,7 @@ animations = [{
"duration": 1.0, "duration": 1.0,
"texture": SubResource("AtlasTexture_xuq2e") "texture": SubResource("AtlasTexture_xuq2e")
}], }],
"loop": false, "loop": true,
"name": &"move_up", "name": &"move_up",
"speed": 10.0 "speed": 10.0
}, { }, {
@ -188,16 +188,39 @@ animations = [{
[sub_resource type="Animation" id="Animation_ve5nf"] [sub_resource type="Animation" id="Animation_ve5nf"]
resource_name = "RESET" resource_name = "RESET"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("CanvasModulate:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="Animation" id="Animation_ab576"] [sub_resource type="Animation" id="Animation_jmi7y"]
resource_name = "move" resource_name = "fade_out"
length = 0.5 length = 10.0
loop_mode = 1 tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("CanvasModulate:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 10),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1), Color(0, 0, 0, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_dx4e7"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_dx4e7"]
_data = { _data = {
"RESET": SubResource("Animation_ve5nf"), "RESET": SubResource("Animation_ve5nf"),
"move": SubResource("Animation_ab576") "end": SubResource("Animation_jmi7y")
} }
[sub_resource type="RectangleShape2D" id="RectangleShape2D_l7fhd"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_l7fhd"]
@ -213,7 +236,7 @@ script = ExtResource("1_jrd75")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_icodh") sprite_frames = SubResource("SpriteFrames_icodh")
animation = &"move_down" animation = &"move_right"
[node name="Camera2D" type="Camera2D" parent="AnimatedSprite2D"] [node name="Camera2D" type="Camera2D" parent="AnimatedSprite2D"]
@ -239,4 +262,7 @@ shape = SubResource("RectangleShape2D_x0fgp")
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."] [node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
[node name="CanvasModulate" type="CanvasModulate" parent="."]
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
[connection signal="area_entered" from="Area2D" to="." method="_on_area_entered"] [connection signal="area_entered" from="Area2D" to="." method="_on_area_entered"]

5
scenes/end.gd 100644
View File

@ -0,0 +1,5 @@
extends Area2D
func _on_body_entered(body):
if body is Player:
(body as Player).lock_for_end = true

File diff suppressed because one or more lines are too long