basic death functionality
This commit is contained in:
parent
60a6df808e
commit
d77ed8a49f
4 changed files with 30 additions and 5 deletions
|
@ -18,6 +18,9 @@ extends CharacterBody2D
|
|||
@export var run_animation: SpritesheetAnimation
|
||||
|
||||
|
||||
@onready var start_position: Vector2 = global_position
|
||||
|
||||
|
||||
var input_dir: Vector2 = Vector2.ZERO:
|
||||
set(value):
|
||||
input_dir = value.sign()
|
||||
|
@ -42,6 +45,10 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
state_chart.send_event(&"jump_pressed")
|
||||
|
||||
|
||||
func kill() -> void:
|
||||
state_chart.send_event(&"killed")
|
||||
|
||||
|
||||
#region Idle
|
||||
func _slow_to_stop(delta: float) -> void:
|
||||
velocity.x = move_toward(velocity.x, 0.0, stopping_force * delta)
|
||||
|
@ -82,3 +89,10 @@ func _face_towards_velocity(_delta: float) -> void:
|
|||
func _restore_graphics_rotation() -> void:
|
||||
graphics.rotation = 0.0
|
||||
#endregion
|
||||
|
||||
|
||||
#region Death
|
||||
func _reset_position() -> void:
|
||||
global_position = start_position
|
||||
velocity = Vector2.ZERO
|
||||
#endregion
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=20 format=3 uid="uid://bwtpsjpe2lf7l"]
|
||||
[gd_scene load_steps=21 format=3 uid="uid://bwtpsjpe2lf7l"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dhyi4yn0xleoy" path="res://objects/player/player.gd" id="1_xs4s5"]
|
||||
[ext_resource type="Texture2D" uid="uid://c71nqfyw4a3v4" path="res://assets/textures/player/capri.png" id="3_trcll"]
|
||||
[ext_resource type="Script" uid="uid://cv55s54clajw5" path="res://scripts/spritesheet_animation/spritesheet_animation.gd" id="4_bsdw5"]
|
||||
[ext_resource type="Script" uid="uid://bhrh1qkv7nlyl" path="res://addons/godot_state_charts/state_chart.gd" id="5_bcjtl"]
|
||||
[ext_resource type="AudioStream" uid="uid://dfa1ev73rsc7g" path="res://assets/audio/vox/capri_die.ogg" id="5_bi5m7"]
|
||||
[ext_resource type="Script" uid="uid://b11v7h3ny6kh1" path="res://addons/godot_state_charts/compound_state.gd" id="6_jnxnd"]
|
||||
[ext_resource type="Script" uid="uid://rrj3six8lu8p" path="res://addons/godot_state_charts/transition.gd" id="7_rgjdc"]
|
||||
[ext_resource type="Script" uid="uid://b6u7unac5srh0" path="res://addons/godot_state_charts/expression_guard.gd" id="8_8i2im"]
|
||||
|
@ -133,6 +134,10 @@ first_frame = Vector2i(2, 2)
|
|||
stream = ExtResource("9_8c74o")
|
||||
bus = &"Capri"
|
||||
|
||||
[node name="Death" type="AudioStreamPlayer" parent="Sounds"]
|
||||
stream = ExtResource("5_bi5m7")
|
||||
bus = &"Capri"
|
||||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
script = ExtResource("5_bcjtl")
|
||||
track_in_editor = true
|
||||
|
@ -146,6 +151,12 @@ initial_expression_properties = {
|
|||
script = ExtResource("6_jnxnd")
|
||||
initial_state = NodePath("Grounded")
|
||||
|
||||
[node name="on Killed" type="Node" parent="StateChart/Root"]
|
||||
script = ExtResource("7_rgjdc")
|
||||
to = NodePath("../Grounded")
|
||||
event = &"killed"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="Grounded" type="Node" parent="StateChart/Root"]
|
||||
editor_description = "Player is standing on a floor."
|
||||
script = ExtResource("6_jnxnd")
|
||||
|
@ -268,6 +279,8 @@ delay_in_seconds = "0.0"
|
|||
editor_description = "Player is hurtling through the air and ricocheting off of surfaces."
|
||||
script = ExtResource("10_mvu25")
|
||||
|
||||
[connection signal="taken" from="StateChart/Root/on Killed" to="." method="_reset_position"]
|
||||
[connection signal="taken" from="StateChart/Root/on Killed" to="Sounds/Death" method="play"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Grounded/Standing/Idle" to="Graphics/Sprite/Idle" method="play"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Grounded/Standing/Stopping" to="Graphics/Sprite/Run" method="play"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Grounded/Standing/Stopping" to="." method="_scale_run_animation"]
|
||||
|
|
|
@ -13,6 +13,4 @@ func _process(delta: float) -> void:
|
|||
|
||||
func _on_area_2d_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
|
||||
if body is Player:
|
||||
body.position = body.start_position
|
||||
body.voice.stream = load("res://assets/audio/vox/capri_die.ogg")
|
||||
body.voice.play()
|
||||
body.kill()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue