diff --git a/objects/new_player/new_player.gd b/objects/new_player/new_player.gd index 96d4167..44afe71 100644 --- a/objects/new_player/new_player.gd +++ b/objects/new_player/new_player.gd @@ -33,6 +33,8 @@ func _physics_process(delta: float) -> void: state_chart.set_expression_property(&"on_floor", is_on_floor()) input_dir = Input.get_vector(&"move_left", &"move_right", &"move_up", &"move_down") + + state_chart.send_event(&"tick") func _unhandled_input(event: InputEvent) -> void: @@ -74,4 +76,9 @@ func _start_jump() -> void: #region Missile +func _face_towards_velocity(_delta: float) -> void: + graphics.rotation = Vector2(graphics.scale.x, 0.0).angle_to(velocity) + +func _restore_graphics_rotation() -> void: + graphics.rotation = 0.0 #endregion diff --git a/objects/new_player/new_player.tscn b/objects/new_player/new_player.tscn index 582d1f7..97a277e 100644 --- a/objects/new_player/new_player.tscn +++ b/objects/new_player/new_player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://bwtpsjpe2lf7l"] +[gd_scene load_steps=20 format=3 uid="uid://bwtpsjpe2lf7l"] [ext_resource type="Script" uid="uid://dhyi4yn0xleoy" path="res://objects/new_player/new_player.gd" id="1_xs4s5"] [ext_resource type="Texture2D" uid="uid://c71nqfyw4a3v4" path="res://assets/textures/player/capri.png" id="3_trcll"] @@ -7,6 +7,7 @@ [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"] +[ext_resource type="AudioStream" uid="uid://7be7ts3rdegh" path="res://assets/audio/vox/capri_jump.ogg" id="9_8c74o"] [ext_resource type="Script" uid="uid://cyvphy8py4ntr" path="res://addons/godot_state_charts/atomic_state.gd" id="10_mvu25"] [sub_resource type="CircleShape2D" id="CircleShape2D_tvyy1"] @@ -124,6 +125,12 @@ first_frame = Vector2i(1, 2) script = ExtResource("4_bsdw5") first_frame = Vector2i(2, 2) +[node name="Sounds" type="Node" parent="."] + +[node name="Voice" type="AudioStreamPlayer" parent="Sounds"] +stream = ExtResource("9_8c74o") +bus = &"Capri" + [node name="StateChart" type="Node" parent="."] script = ExtResource("5_bcjtl") track_in_editor = true @@ -142,19 +149,20 @@ editor_description = "Player is standing on a floor." script = ExtResource("6_jnxnd") initial_state = NodePath("Standing") -[node name="if NotOnFloor" type="Node" parent="StateChart/Root/Grounded"] -editor_description = "Transition to falling state if not touching a floor." -script = ExtResource("7_rgjdc") -to = NodePath("../../Airborne/Falling") -guard = SubResource("Resource_sfpnl") -delay_in_seconds = "0.0" - [node name="on JumpPressed" type="Node" parent="StateChart/Root/Grounded"] script = ExtResource("7_rgjdc") to = NodePath("../../Airborne/Jumping") event = &"jump_pressed" delay_in_seconds = "0.0" +[node name="if NotOnFloor" type="Node" parent="StateChart/Root/Grounded"] +editor_description = "Transition to falling state if not touching a floor." +script = ExtResource("7_rgjdc") +to = NodePath("../../Airborne/Falling") +event = &"tick" +guard = SubResource("Resource_sfpnl") +delay_in_seconds = "0.0" + [node name="Standing" type="Node" parent="StateChart/Root/Grounded"] editor_description = "Player is standing still or coming to a stop." script = ExtResource("6_jnxnd") @@ -235,6 +243,7 @@ initial_state = NodePath("Falling") editor_description = "Transition to grounded state if touching a floor." script = ExtResource("7_rgjdc") to = NodePath("../../Grounded") +event = &"tick" guard = SubResource("Resource_163ft") delay_in_seconds = "0.0" @@ -257,9 +266,6 @@ delay_in_seconds = "0.0" editor_description = "Player is hurtling through the air and ricocheting off of surfaces." script = ExtResource("10_mvu25") -[node name="Voice" type="AudioStreamPlayer" parent="."] -bus = &"Capri" - [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"] @@ -273,4 +279,7 @@ bus = &"Capri" [connection signal="state_entered" from="StateChart/Root/Airborne/Falling" to="Graphics/Sprite/Fall" method="play"] [connection signal="state_entered" from="StateChart/Root/Airborne/Jumping" to="." method="_start_jump"] [connection signal="state_entered" from="StateChart/Root/Airborne/Jumping" to="Graphics/Sprite/Jump" method="play"] +[connection signal="state_entered" from="StateChart/Root/Airborne/Jumping" to="Sounds/Voice" method="play"] [connection signal="state_entered" from="StateChart/Root/Airborne/Missile" to="Graphics/Sprite/Missile" method="play"] +[connection signal="state_exited" from="StateChart/Root/Airborne/Missile" to="." method="_restore_graphics_rotation"] +[connection signal="state_physics_processing" from="StateChart/Root/Airborne/Missile" to="." method="_face_towards_velocity"]