ficed some issues, continued refactoring
current bugs are the not right connections of the signals. im working on it.
This commit is contained in:
parent
0a764354ba
commit
8c950a1710
14 changed files with 276 additions and 137 deletions
|
|
@ -1,5 +0,0 @@
|
|||
class_name PlayerProperties
|
||||
|
||||
var stamina_component: StaminaComponent = StaminaComponent.new()
|
||||
var flashlight_component: FlashlightComponent = FlashlightComponent.new()
|
||||
var inventory_component: InventoryComponent = InventoryComponent.new()
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://ww58fe1kftaw
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://classes/equippable_item.gd" id="1_mtlx8"]
|
||||
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://scenes/player/player.tscn" id="1_s8b7j"]
|
||||
[ext_resource type="AudioStream" uid="uid://b6wlbiittcu48" path="res://assets/sounds/ambiance/harmonika-paulstretched.mp3" id="2_afrty"]
|
||||
[ext_resource type="AudioStream" uid="uid://b6wlbiittcu48" path="res://assets/sounds/ambiance/harmonika-paulstretched.mp3" id="3_mtlx8"]
|
||||
[ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="4_yb1w3"]
|
||||
|
||||
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_g4v7s"]
|
||||
|
|
@ -100,7 +100,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2949467, -3.755646)
|
|||
|
||||
[node name="SpatialAudio3D" type="AudioStreamPlayer3D" parent="." unique_id=351573539]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.887349, 4.01754, -1.2293816)
|
||||
stream = ExtResource("2_afrty")
|
||||
stream = ExtResource("3_mtlx8")
|
||||
volume_db = -8.235
|
||||
autoplay = true
|
||||
max_distance = 1927.53
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ config/icon="res://icon.svg"
|
|||
[audio]
|
||||
|
||||
buses/default_bus_layout="uid://bfh2c7jnwhac0"
|
||||
driver/output_latency=30
|
||||
|
||||
[autoload]
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ signal select_item(index: int)
|
|||
|
||||
#for ui elements
|
||||
signal add_item(index: int, item: EquippableItem)
|
||||
signal remove_item
|
||||
signal remove_item(index: int)
|
||||
|
||||
func next_item():
|
||||
prev_selected_item = selected_item
|
||||
|
|
|
|||
|
|
@ -2,20 +2,61 @@ class_name MovementComponent extends Node
|
|||
|
||||
@export var camera_pivot: Node3D
|
||||
@export var player_camera: Camera3D
|
||||
@export var player: Player
|
||||
@export var player_hit_box: CollisionShape3D
|
||||
@export var player_state: Node
|
||||
@export var player: Player
|
||||
|
||||
signal jumped
|
||||
signal landed(speed:float)
|
||||
signal running(is_running:bool)
|
||||
signal crouching(is_crouching:bool)
|
||||
signal walking(is_walking:bool)
|
||||
|
||||
var mouse_motion: Vector2 = Vector2.ZERO
|
||||
var mouse_motion_delta: Vector2 = Vector2.ZERO
|
||||
var crouched: bool = false
|
||||
var runs: bool = false
|
||||
var walks: bool = false
|
||||
|
||||
signal jumped
|
||||
var _player_spawned: bool = false
|
||||
|
||||
@onready var global_delta: float
|
||||
@onready var target_speed = PlayerConsts.SPEED
|
||||
|
||||
func jump():
|
||||
player.velocity.y = PlayerConsts.JUMP_VELOCITY
|
||||
player.stamina_component.stamina -= PlayerConsts.JUMP_STAMINA_COST
|
||||
jumped.emit()
|
||||
|
||||
func land(velocity: float):
|
||||
if _player_spawned:
|
||||
landed.emit(velocity)
|
||||
|
||||
func crouch(is_crouched:bool):
|
||||
if is_crouched:
|
||||
target_speed *= PlayerConsts.CROUCH_SPEED_MULTIPLIER
|
||||
|
||||
else:
|
||||
target_speed /= PlayerConsts.CROUCH_SPEED_MULTIPLIER
|
||||
|
||||
crouched = is_crouched
|
||||
crouching.emit(is_crouched)
|
||||
|
||||
func run(is_running:bool):
|
||||
if player.velocity.length() > 0:
|
||||
if is_running:
|
||||
target_speed *= PlayerConsts.SPRINT_MULTIPLIER
|
||||
else:
|
||||
target_speed /= PlayerConsts.SPRINT_MULTIPLIER
|
||||
|
||||
running.emit(is_running)
|
||||
|
||||
func walk(is_walking:bool):
|
||||
if is_walking:
|
||||
walks = true
|
||||
walking.emit(true)
|
||||
else:
|
||||
walks = false
|
||||
walking.emit(false)
|
||||
|
||||
func handle_joypad_movement():
|
||||
var controller_look_vector = Input.get_vector("look_left", "look_right", "look_up", "look_down") * 50
|
||||
|
||||
|
|
@ -36,10 +77,18 @@ func _input(event: InputEvent) -> void:
|
|||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
get_tree().create_timer(0.5).timeout.connect(func(): _player_spawned = true)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
func _process(delta: float) -> void:
|
||||
global_delta = delta
|
||||
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player.stamina_component.stamina > PlayerConsts.JUMP_STAMINA_COST:
|
||||
jump()
|
||||
|
||||
if crouched:
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, .5, delta * 10)
|
||||
else:
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not Console.toggled or not UiManager.in_game_menu.visible:
|
||||
|
|
@ -48,6 +97,9 @@ func _physics_process(delta: float) -> void:
|
|||
player_camera.transform.basis = lerp(player_camera.transform.basis, Basis.from_euler(Vector3(mouse_motion.y * -0.001 * PlayerConsts.LOOK_SENSITIVITY, 0, 0)), delta * 30)
|
||||
handle_joypad_movement()
|
||||
|
||||
var was_on_floor: bool = player.is_on_floor()
|
||||
var fall_velocity: float = player.velocity.y
|
||||
|
||||
if not player.is_on_floor():
|
||||
player.velocity += player.get_gravity() * delta
|
||||
|
||||
|
|
@ -64,29 +116,23 @@ func _physics_process(delta: float) -> void:
|
|||
camera_pivot.rotation.z = lerpf(camera_pivot.rotation.z, 0, delta*10)
|
||||
camera_pivot.position.x = lerpf(camera_pivot.position.x, 0, delta * 7)
|
||||
|
||||
var target_speed = PlayerConsts.SPEED
|
||||
var is_moving = input_dir != Vector2.ZERO
|
||||
|
||||
if Input.is_action_pressed("crouch"):
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, .5, delta * 5)
|
||||
target_speed *= PlayerConsts.CROUCH_SPEED_MULTIPLIER
|
||||
player_state.is_crouched(true)
|
||||
else:
|
||||
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10)
|
||||
player_state.is_crouched(false)
|
||||
if Input.is_action_just_pressed("crouch"):
|
||||
crouch(true)
|
||||
elif Input.is_action_just_released("crouch"):
|
||||
crouch(false)
|
||||
|
||||
if Input.is_action_pressed("sprint") and player.stamina_component.stamina > 0:
|
||||
target_speed *= PlayerConsts.SPRINT_MULTIPLIER
|
||||
player_state.is_running(true)
|
||||
player.stamina_component.stamina -= delta * PlayerConsts.SPRINT_STAMINA_COST
|
||||
GlobalSignals.stamina_recharge_off.emit()
|
||||
else:
|
||||
player_state.is_running(false)
|
||||
if Input.is_action_just_pressed("sprint") and player.stamina_component.stamina > 0:
|
||||
run(true)
|
||||
elif Input.is_action_just_released("sprint") or player.stamina_component.stamina == 0:
|
||||
run(false)
|
||||
|
||||
#apply motion
|
||||
var local_vel = player.transform.basis.inverse() * player.velocity
|
||||
var target_local_vel = Vector3(player_camera.transform.basis * Vector3(input_dir.x, 0, input_dir.y)) * target_speed
|
||||
var accel_rate = 6.0 if is_moving else 9.0
|
||||
|
||||
local_vel.x = lerpf(local_vel.x, target_local_vel.x, delta * accel_rate)
|
||||
local_vel.z = lerpf(local_vel.z, target_local_vel.z, delta * accel_rate)
|
||||
|
||||
|
|
@ -94,16 +140,26 @@ func _physics_process(delta: float) -> void:
|
|||
player.velocity.x = global_horizontal.x
|
||||
player.velocity.z = global_horizontal.z
|
||||
|
||||
if is_moving and not player_state.running and not player_state.crouching:
|
||||
player_state.is_walking(true)
|
||||
else:
|
||||
player_state.is_walking(false)
|
||||
if (Input.is_action_just_pressed("forward") \
|
||||
or Input.is_action_just_pressed("backward") \
|
||||
or Input.is_action_just_pressed("left") \
|
||||
or Input.is_action_just_pressed("right")
|
||||
) and not runs and not crouched and not walks:
|
||||
walk(true)
|
||||
elif walks and not (Input.is_action_pressed("forward") \
|
||||
or Input.is_action_pressed("backward") \
|
||||
or Input.is_action_pressed("left") \
|
||||
or Input.is_action_pressed("right")):
|
||||
walk(false)
|
||||
|
||||
else:
|
||||
player.velocity.x = lerpf(player.velocity.x, 0, delta * 10)
|
||||
player.velocity.z = lerpf(player.velocity.z, 0, delta * 10)
|
||||
|
||||
player.move_and_slide()
|
||||
|
||||
if not was_on_floor and player.is_on_floor():
|
||||
land(fall_velocity)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta: float) -> void:
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ class_name Player extends CharacterBody3D
|
|||
@export var sound_controller: SoundController
|
||||
@export var player_state: PlayerState
|
||||
|
||||
#var player_properties: PlayerProperties = PlayerProperties.new()
|
||||
|
||||
func _ready() -> void:
|
||||
Console.context["player"] = self
|
||||
GameState.player = self
|
||||
|
|
@ -25,12 +23,30 @@ func _ready() -> void:
|
|||
inventory_component.add_item.connect(ui.add_item)
|
||||
inventory_component.remove_item.connect(ui.remove_item)
|
||||
|
||||
SignalSniffer.watch(inventory_component)
|
||||
|
||||
procedural_animator.breath.connect(sound_controller.play_breath_sound)
|
||||
procedural_animator.footstep.connect(sound_controller.play_footstep_sound)
|
||||
|
||||
SignalSniffer.watch(procedural_animator)
|
||||
|
||||
input_controller.stamina_reset.connect(stamina_component.restart_timer)
|
||||
input_controller.toggle_flashlight.connect(flashlight_component.toggle_flashlight)
|
||||
input_controller.toggle_flashlight.connect(sound_controller.play_flashlight_sound)
|
||||
|
||||
movement_component.jumped.connect(func():sound_controller.play_jump_sound(true))
|
||||
player_state.landed.connect(func():sound_controller.play_jump_sound(false))
|
||||
SignalSniffer.watch(input_controller)
|
||||
|
||||
stamina_component.stamina_changed.connect(ui.set_stamina)
|
||||
|
||||
SignalSniffer.watch(stamina_component)
|
||||
|
||||
movement_component.jumped.connect(stamina_component.jump)
|
||||
movement_component.jumped.connect(sound_controller.play_jump_sound)
|
||||
movement_component.jumped.connect(player_state.jump)
|
||||
movement_component.landed.connect(sound_controller.play_land_sound )
|
||||
movement_component.walking.connect(player_state.is_walking)
|
||||
movement_component.running.connect(player_state.is_running)
|
||||
movement_component.running.connect(stamina_component.run)
|
||||
movement_component.crouching.connect(player_state.is_crouched)
|
||||
|
||||
SignalSniffer.watch(movement_component)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
[ext_resource type="Script" uid="uid://dntoi54g4hqce" path="res://scenes/player/flashlight_component.gd" id="11_myrg7"]
|
||||
[ext_resource type="Script" uid="uid://cdfis3askl3gb" path="res://scenes/player/stamina_component.gd" id="12_kvlxm"]
|
||||
[ext_resource type="PackedScene" uid="uid://c02fkimxlbrje" path="res://scenes/player/prompt.tscn" id="13_ugbui"]
|
||||
[ext_resource type="AudioStream" uid="uid://0q6nhlhgnxu2" path="res://assets/sounds/whitenoise.mp3" id="14_ugbui"]
|
||||
[ext_resource type="Script" uid="uid://dr2lwciaohf6f" path="res://scenes/player/movement_component.gd" id="60_s3g0c"]
|
||||
[ext_resource type="Script" uid="uid://cjk6a0da11ge6" path="res://scenes/player/procedural_animator.gd" id="61_hggc2"]
|
||||
[ext_resource type="Script" uid="uid://v8er7yn0hdh8" path="res://scenes/player/sound_controller_component.gd" id="62_b2j0d"]
|
||||
|
|
@ -13,7 +14,6 @@
|
|||
[ext_resource type="Script" uid="uid://7aa26wi66kqq" path="res://scenes/player/prompt_handler.gd" id="63_7l6ig"]
|
||||
[ext_resource type="Script" uid="uid://bvvwwkswavy5x" path="res://scenes/player/input_controller_component.gd" id="64_j3r50"]
|
||||
[ext_resource type="Script" uid="uid://7hmwhf7acwpj" path="res://scenes/player/state_handler_component.gd" id="65_kssj8"]
|
||||
[ext_resource type="AudioStream" uid="uid://0q6nhlhgnxu2" path="res://assets/sounds/whitenoise.mp3" id="204_76ube"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"]
|
||||
|
||||
|
|
@ -37,14 +37,13 @@ player_state = NodePath("Components/PlayerState")
|
|||
|
||||
[node name="Components" type="Node" parent="." unique_id=1652812621]
|
||||
|
||||
[node name="MovementComponent" type="Node" parent="Components" unique_id=1821617467 node_paths=PackedStringArray("camera_pivot", "player_camera", "player", "player_hit_box", "player_state")]
|
||||
[node name="MovementComponent" type="Node" parent="Components" unique_id=1821617467 node_paths=PackedStringArray("camera_pivot", "player_camera", "player_hit_box", "player")]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("60_s3g0c")
|
||||
camera_pivot = NodePath("../../CameraPivot")
|
||||
player_camera = NodePath("../../CameraPivot/PlayerCamera")
|
||||
player = NodePath("../..")
|
||||
player_hit_box = NodePath("../../PlayerHitBox")
|
||||
player_state = NodePath("../PlayerState")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="ProceduralAnimator" type="Node" parent="Components" unique_id=899836528 node_paths=PackedStringArray("player", "camera", "ui", "movement")]
|
||||
unique_name_in_owner = true
|
||||
|
|
@ -54,12 +53,10 @@ camera = NodePath("../../CameraPivot/PlayerCamera")
|
|||
ui = NodePath("../../PlayerUi")
|
||||
movement = NodePath("../MovementComponent")
|
||||
|
||||
[node name="SoundController" type="Node" parent="Components" unique_id=1286506274 node_paths=PackedStringArray("player_state", "player", "movement", "left_foot", "right_foot", "right_foot_texture", "left_foot_texture", "head", "head_texture", "wind")]
|
||||
[node name="SoundController" type="Node" parent="Components" unique_id=1286506274 node_paths=PackedStringArray("player", "left_foot", "right_foot", "right_foot_texture", "left_foot_texture", "head", "head_texture", "wind")]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("62_b2j0d")
|
||||
player_state = NodePath("../PlayerState")
|
||||
player = NodePath("../..")
|
||||
movement = NodePath("../MovementComponent")
|
||||
left_foot = NodePath("../../SoundEmitters/LeftFoot")
|
||||
right_foot = NodePath("../../SoundEmitters/RightFoot")
|
||||
right_foot_texture = NodePath("../../SoundEmitters/RightFoot/RightFootTexture")
|
||||
|
|
@ -82,9 +79,10 @@ prompt = NodePath("../../Prompt")
|
|||
player = NodePath("../..")
|
||||
hold_position = NodePath("../../CameraPivot/PlayerCamera/HoldPosition")
|
||||
|
||||
[node name="PlayerState" type="Node" parent="Components" unique_id=1564123661]
|
||||
[node name="PlayerState" type="Node" parent="Components" unique_id=1564123661 node_paths=PackedStringArray("player")]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("65_kssj8")
|
||||
player = NodePath("../..")
|
||||
|
||||
[node name="InventoryComponent" type="Node" parent="Components" unique_id=1980833408 node_paths=PackedStringArray("equipped_item_mesh", "hold_position", "cursor_raycast")]
|
||||
unique_name_in_owner = true
|
||||
|
|
@ -167,13 +165,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.7621309, 0)
|
|||
doppler_tracking = 2
|
||||
current = true
|
||||
|
||||
[node name="PlayerUi" parent="." unique_id=454848358 instance=ExtResource("2_rkbax")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="Prompt" parent="." unique_id=318901794 instance=ExtResource("13_ugbui")]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
|
||||
[node name="PlayerUi" parent="." unique_id=454848358 instance=ExtResource("2_rkbax")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="StaminaReset" type="Timer" parent="." unique_id=1815815085]
|
||||
unique_name_in_owner = true
|
||||
wait_time = 3.0
|
||||
|
|
@ -218,7 +216,7 @@ metadata/_custom_type_script = "uid://y8x4svl5kej2"
|
|||
[node name="Wind" type="AudioStreamPlayer3D" parent="SoundEmitters" unique_id=1950929206]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.7, 0)
|
||||
stream = ExtResource("204_76ube")
|
||||
stream = ExtResource("14_ugbui")
|
||||
bus = &"wind"
|
||||
|
||||
[connection signal="body_entered" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/PromptHandler" method="_on_action_finder_body_entered"]
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ func _ready():
|
|||
unselected_stylebox.bg_color = UNSELECTED_COLOR
|
||||
Console.add_inventory.connect(add_inventory_slot_console)
|
||||
Console.remove_inventory.connect(remove_inventory_slot_console)
|
||||
pivot_offset = get_viewport_rect().size / 2
|
||||
|
||||
func select_item(index):
|
||||
if index >= 0 and index < inventory_size:
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ func do(delta):
|
|||
var final_pitch = target_rot.x
|
||||
var final_roll = target_rot.z
|
||||
|
||||
#var target_basis = Basis.from_euler(Vector3(final_pitch, 0, final_roll))
|
||||
|
||||
target_rotation = Vector3(final_pitch, 0, final_roll)
|
||||
|
||||
func ui_movement_handling(delta: float):
|
||||
|
|
@ -78,15 +76,16 @@ func ui_movement_handling(delta: float):
|
|||
) * PlayerConsts.CAMERA_VELOCITY_MULTIPLIER
|
||||
|
||||
var target_offset = mouse_offset + inertia_offset
|
||||
ui.position = ui.position.lerp(ui_base_position + target_offset, delta * PlayerConsts.UI_MOVEMENT_SPEED)
|
||||
var weighted_lerp = 1.0 - exp(-PlayerConsts.UI_MOVEMENT_SPEED * delta)
|
||||
ui.position = ui.position.lerp(ui_base_position + target_offset, weighted_lerp)
|
||||
|
||||
_last_camera_global_position = current_camera_global_position
|
||||
|
||||
var ui_scaling_target = Vector2(-cam_local_vel.z * PlayerConsts.UI_MOVEMENT_SENSITIVITY * .002 + 1, -cam_local_vel.z * PlayerConsts.UI_MOVEMENT_SENSITIVITY * .002 + 1)
|
||||
ui.offset_transform_scale = ui.offset_transform_scale.lerp(ui_scaling_target, delta * PlayerConsts.UI_MOVEMENT_SPEED)
|
||||
ui.offset_transform_scale = ui.offset_transform_scale.lerp(ui_scaling_target, weighted_lerp)
|
||||
|
||||
var ui_rotation_target = -inertia_offset.x - mouse_offset.x * 0.25
|
||||
ui.offset_transform_rotation = lerpf(ui.offset_transform_rotation, ui_rotation_target * PlayerConsts.UI_MOVEMENT_SENSITIVITY * 0.003, delta * PlayerConsts.UI_MOVEMENT_SPEED)
|
||||
ui.offset_transform_rotation = lerpf(ui.offset_transform_rotation, ui_rotation_target * PlayerConsts.UI_MOVEMENT_SENSITIVITY * 0.003, weighted_lerp)
|
||||
|
||||
|
||||
func footstep_sound():
|
||||
|
|
|
|||
|
|
@ -40,9 +40,7 @@ var _current_breath_in_sound = null
|
|||
var _current_breath_out_sound = null
|
||||
var _current_leg_is_right = false
|
||||
|
||||
@export var player_state: Node
|
||||
@export var player: CharacterBody3D
|
||||
@export var movement: Node
|
||||
|
||||
@export var left_foot: SpatialAudio3D
|
||||
@export var right_foot: SpatialAudio3D
|
||||
|
|
@ -84,9 +82,6 @@ func _ready() -> void:
|
|||
|
||||
get_tree().create_timer(1).timeout.connect(init_wind)
|
||||
|
||||
player_state.landed.connect(play_jump_sound)
|
||||
player_state.jumped.connect(play_jump_sound)
|
||||
|
||||
GlobalSignals.toggle_flashlight.connect(play_flashlight_sound)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
|
@ -95,9 +90,6 @@ func _process(delta: float) -> void:
|
|||
if audio_cooldowns[i] > 0:
|
||||
audio_cooldowns[i] -= delta
|
||||
|
||||
if not player.is_on_floor():
|
||||
cur_player_in_air_velocity = player.velocity.length()
|
||||
|
||||
play_wind()
|
||||
|
||||
var is_right_leg := func () -> SpatialAudio3D:
|
||||
|
|
@ -146,35 +138,36 @@ func play_breath_sound(breathe_in:bool = true):
|
|||
if breathe_in:
|
||||
play_sound = _current_breath_in_sound
|
||||
while play_sound == _current_breath_in_sound:
|
||||
match player_state.breathing_mode:
|
||||
player_state.breath.calm:
|
||||
print("breathe in")
|
||||
match player.player_state.breathing_mode:
|
||||
player.player_state.breath.calm:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_CALM)
|
||||
player_state.breath.low:
|
||||
player.player_state.breath.low:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_LOW)
|
||||
player_state.breath.mid:
|
||||
player.player_state.breath.mid:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_MID)
|
||||
player_state.breath.heavy:
|
||||
player.player_state.breath.heavy:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_HEAVY)
|
||||
player_state.breath.max:
|
||||
player.player_state.breath.max:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_MAX)
|
||||
player_state.breath.exhausted:
|
||||
player.player_state.breath.exhausted:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_IN_EXHAUSTED)
|
||||
_current_breath_in_sound = play_sound
|
||||
else:
|
||||
play_sound = _current_breath_out_sound
|
||||
while play_sound == _current_breath_out_sound:
|
||||
match player_state.breathing_mode:
|
||||
player_state.breath.calm:
|
||||
match player.player_state.breathing_mode:
|
||||
player.player_state.breath.calm:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_CALM)
|
||||
player_state.breath.low:
|
||||
player.player_state.breath.low:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_LOW)
|
||||
player_state.breath.mid:
|
||||
player.player_state.breath.mid:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_MID)
|
||||
player_state.breath.heavy:
|
||||
player.player_state.breath.heavy:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_HEAVY)
|
||||
player_state.breath.max:
|
||||
player.player_state.breath.max:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_MAX)
|
||||
player_state.breath.exhausted:
|
||||
player.player_state.breath.exhausted:
|
||||
play_sound = Sounds.get_random_sound(Sounds.BREATHE_OUT_EXHAUSTED)
|
||||
_current_breath_out_sound = play_sound
|
||||
|
||||
|
|
@ -184,54 +177,71 @@ func play_flashlight_sound():
|
|||
var play_sound = Sounds.get_random_sound(Sounds.FLASHLIGHT_CLICK_SOUNDS)
|
||||
|
||||
while play_sound == _current_flashlight_sound:
|
||||
print("flashlight sound")
|
||||
play_sound = Sounds.get_random_sound(Sounds.FLASHLIGHT_CLICK_SOUNDS)
|
||||
|
||||
_current_flashlight_sound = play_sound
|
||||
|
||||
play_stream_on_player(head_texture, play_sound)
|
||||
_current_flashlight_sound = play_sound
|
||||
|
||||
var cur_player_in_air_velocity: float = 0
|
||||
|
||||
func play_jump_sound(start:bool = true):
|
||||
func play_land_sound(velocity: float):
|
||||
var sound_to_play_foot: AudioStream = null
|
||||
var sound_to_play_breath: AudioStream = null
|
||||
var volume:float = 1.0
|
||||
|
||||
##TODO: make the landing sound volume scale with the fallen height (the higher you fall from, the bigger the stomp)
|
||||
##TODO: find out why tf is it being called 2x????????
|
||||
|
||||
print("play_jump_sound", start)
|
||||
volume = velocity
|
||||
while sound_to_play_foot == _current_jump_land_sound:
|
||||
print("land foot")
|
||||
sound_to_play_foot = Sounds.get_random_sound(Sounds.JUMP_LANDING_SOUNDS)
|
||||
while sound_to_play_breath == _current_jump_land_breath_sound:
|
||||
print("land breath")
|
||||
sound_to_play_breath = Sounds.get_random_sound(Sounds.JUMP_LANDING_BREATH_SOUNDS)
|
||||
|
||||
_current_jump_land_sound = sound_to_play_foot
|
||||
_current_jump_land_breath_sound = sound_to_play_breath
|
||||
|
||||
play_stream_on_player(head, sound_to_play_breath, randf_range(.8, 1.2), volume)
|
||||
play_stream_on_player(is_right_leg.call(), sound_to_play_foot)
|
||||
|
||||
func play_jump_sound():
|
||||
var sound_to_play_foot: AudioStream = null
|
||||
var sound_to_play_breath: AudioStream = null
|
||||
var volume:float = 1.0
|
||||
|
||||
while sound_to_play_foot == _current_jump_start_sound:
|
||||
print("jump foot")
|
||||
sound_to_play_foot = Sounds.get_random_sound(Sounds.JUMP_STARTING_SOUNDS)
|
||||
while sound_to_play_breath == _current_jump_start_breath_sound:
|
||||
print("jump breath")
|
||||
sound_to_play_breath = Sounds.get_random_sound(Sounds.JUMP_STARTING_BREATH_SOUNDS)
|
||||
|
||||
_current_jump_start_sound = sound_to_play_foot
|
||||
_current_jump_start_breath_sound = sound_to_play_breath
|
||||
|
||||
match start:
|
||||
true:
|
||||
while sound_to_play_foot == _current_jump_start_sound:
|
||||
sound_to_play_foot = Sounds.get_random_sound(Sounds.JUMP_STARTING_SOUNDS)
|
||||
while sound_to_play_breath == _current_jump_start_breath_sound:
|
||||
sound_to_play_breath = Sounds.get_random_sound(Sounds.JUMP_STARTING_BREATH_SOUNDS)
|
||||
false:
|
||||
volume = cur_player_in_air_velocity
|
||||
while sound_to_play_foot == _current_jump_land_sound:
|
||||
sound_to_play_foot = Sounds.get_random_sound(Sounds.JUMP_LANDING_SOUNDS)
|
||||
while sound_to_play_breath == _current_jump_land_breath_sound:
|
||||
sound_to_play_breath = Sounds.get_random_sound(Sounds.JUMP_LANDING_BREATH_SOUNDS)
|
||||
|
||||
play_stream_on_player(head, sound_to_play_breath, randf_range(.8, 1.2), volume)
|
||||
play_stream_on_player(is_right_leg.call(), sound_to_play_foot)
|
||||
|
||||
func play_footstep_sound():
|
||||
var sound_to_play:AudioStream
|
||||
if player_state.walking:
|
||||
if player.player_state.walking:
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.NORMAL_FOOTSTEP_SOUNDS)
|
||||
while sound_to_play == _current_footstep_sound:
|
||||
print("walk")
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.NORMAL_FOOTSTEP_SOUNDS)
|
||||
elif player_state.running:
|
||||
elif player.player_state.running:
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.HEAVY_FOOTSTEP_SOUNDS)
|
||||
while sound_to_play == _current_footstep_sound:
|
||||
print("run")
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.HEAVY_FOOTSTEP_SOUNDS)
|
||||
if randf_range(1, 100) > 100 - PlayerConsts.SHUFFLE_CHANCE:
|
||||
play_stream_on_player(is_right_leg.call().get_child(0), Sounds.get_random_sound(Sounds.SHUFFLE_FOOTSTEP_SOUNDS))
|
||||
elif player_state.crouching:
|
||||
elif player.player_state.crouching:
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.LIGHT_FOOTSTEP_SOUNDS)
|
||||
while sound_to_play == _current_footstep_sound:
|
||||
print("crouch")
|
||||
sound_to_play = Sounds.get_random_sound(Sounds.LIGHT_FOOTSTEP_SOUNDS)
|
||||
|
||||
_current_footstep_sound = sound_to_play
|
||||
|
|
@ -251,7 +261,7 @@ func init_wind():
|
|||
|
||||
func play_wind():
|
||||
var strength = player.velocity.length() * 10 + abs(player.velocity.y) * 15
|
||||
var mouse_strength = movement.mouse_motion_delta.length() * 5
|
||||
var mouse_strength = player.movement_component.mouse_motion_delta.length() * 5
|
||||
|
||||
if wind_filter is AudioEffectFilter:
|
||||
wind_filter.cutoff_hz = strength / 2 + mouse_strength / 10 + wind_strength
|
||||
|
|
|
|||
|
|
@ -2,18 +2,44 @@ class_name StaminaComponent extends Node
|
|||
|
||||
var stamina_recharge: bool = true
|
||||
var stamina: float = 100.0
|
||||
var running: bool = false
|
||||
|
||||
## how many seconds to wait for stamina recharge
|
||||
@export var stamina_recharge_cooldown: float = 3.0
|
||||
|
||||
## emits the current stamina value
|
||||
signal stamina_changed(cur_stamina:float)
|
||||
|
||||
var _timer: Timer = Timer.new()
|
||||
|
||||
func restart_timer():
|
||||
print("restart timer")
|
||||
stamina_recharge = false
|
||||
_timer.start()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if stamina_recharge:
|
||||
stamina = move_toward(stamina, 100, 10 * delta)
|
||||
if stamina <= 100:
|
||||
add_stamina(10 * delta)
|
||||
|
||||
if running:
|
||||
if stamina > 0:
|
||||
remove_stamina(PlayerConsts.SPRINT_STAMINA_COST * delta)
|
||||
|
||||
func remove_stamina(by:float) -> void:
|
||||
stamina = move_toward(stamina, 0, by)
|
||||
stamina_changed.emit(stamina)
|
||||
|
||||
func add_stamina(by:float) -> void:
|
||||
stamina = move_toward(stamina, 100, by)
|
||||
stamina_changed.emit(stamina)
|
||||
|
||||
func jump() -> void:
|
||||
remove_stamina(PlayerConsts.JUMP_STAMINA_COST)
|
||||
|
||||
func run(is_running:bool) -> void:
|
||||
running = is_running
|
||||
stamina_recharge = false
|
||||
|
||||
func _ready() -> void:
|
||||
_timer.wait_time = stamina_recharge_cooldown
|
||||
|
|
|
|||
|
|
@ -23,11 +23,9 @@ enum breath {
|
|||
## 80 -- 100 --> calm
|
||||
var _breath_change_points: Array[float] = [10, 20, 50, 80]
|
||||
|
||||
@onready var player: Player = $"../.."
|
||||
@export var player: Player
|
||||
|
||||
var flying: bool = false
|
||||
signal landed
|
||||
signal jumped
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
var stamina = player.stamina_component.stamina
|
||||
|
|
@ -44,13 +42,19 @@ func _process(_delta: float) -> void:
|
|||
else:
|
||||
breathing_mode = breath.calm
|
||||
|
||||
if !player.is_on_floor() and !flying:
|
||||
jumped.emit()
|
||||
flying = true
|
||||
|
||||
if player.is_on_floor() and flying:
|
||||
landed.emit()
|
||||
flying = false
|
||||
#if !player.is_on_floor() and !flying:
|
||||
#jumped.emit(true)
|
||||
#flying = true
|
||||
#
|
||||
#if player.is_on_floor() and flying:
|
||||
#landed.emit(false)
|
||||
#flying = false
|
||||
|
||||
func jump():
|
||||
flying = true
|
||||
|
||||
func land():
|
||||
flying = false
|
||||
|
||||
func is_crouched(yes:bool):
|
||||
if yes:
|
||||
|
|
|
|||
|
|
@ -31,9 +31,6 @@ extends Node
|
|||
@export var BREATHE_OUT_MAX: Array[AudioStream] = []
|
||||
@export var BREATHE_OUT_EXHAUSTED: Array[AudioStream] = []
|
||||
|
||||
@export_group("Whitenoise")
|
||||
@export var WHITENOISE: AudioStream = preload("res://assets/sounds/whitenoise.mp3")
|
||||
|
||||
var pending_files = {}
|
||||
|
||||
var _steps = [
|
||||
|
|
@ -61,29 +58,57 @@ func get_random_sound(sound_array: Array) -> AudioStream:
|
|||
const sound_dir_path: String = "res://assets/sounds"
|
||||
|
||||
func load_sound_from_directory_to_var(path: String, sound_type: Array[AudioStream]):
|
||||
var streams: Array[AudioStream] = []
|
||||
var dir = DirAccess.open(path)
|
||||
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var filename = dir.get_next()
|
||||
|
||||
while filename != "":
|
||||
if not dir.current_is_dir():
|
||||
var clean_filename = filename.replace(".remap", "")
|
||||
dir.list_dir_begin()
|
||||
var filename = dir.get_next()
|
||||
|
||||
while filename != "":
|
||||
if not dir.current_is_dir():
|
||||
# CRITICAL FIX: We strip .import so your game doesn't break when you export it!
|
||||
var clean_filename = filename.replace(".remap", "").replace(".import", "")
|
||||
|
||||
if clean_filename.ends_with(".mp3") or clean_filename.ends_with(".wav") or clean_filename.ends_with(".ogg"):
|
||||
var full_path = path + "/" + clean_filename
|
||||
|
||||
if clean_filename.ends_with(".mp3") or clean_filename.ends_with(".wav") or clean_filename.ends_with(".ogg"):
|
||||
var full_path = path + "/" + clean_filename
|
||||
# 1. LOAD SYNCHRONOUSLY (Instant, no thread locking)
|
||||
var stream = load(full_path) as AudioStream
|
||||
|
||||
if stream:
|
||||
sound_type.append(stream)
|
||||
print("Loaded: ", full_path)
|
||||
else:
|
||||
push_error("Failed to load valid audio stream from: ", full_path)
|
||||
|
||||
pending_files[full_path] = sound_type
|
||||
|
||||
ResourceLoader.load_threaded_request(full_path)
|
||||
|
||||
print("loading: ", full_path)
|
||||
|
||||
filename = dir.get_next()
|
||||
filename = dir.get_next()
|
||||
else:
|
||||
print_debug("Failed to open directory: ", path)
|
||||
push_error("Failed to open directory: ", path)
|
||||
|
||||
#func load_sound_from_directory_to_var(path: String, sound_type: Array[AudioStream]):
|
||||
#var streams: Array[AudioStream] = []
|
||||
#var dir = DirAccess.open(path)
|
||||
#
|
||||
#if dir:
|
||||
#dir.list_dir_begin()
|
||||
#var filename = dir.get_next()
|
||||
#
|
||||
#while filename != "":
|
||||
#if not dir.current_is_dir():
|
||||
#var clean_filename = filename.replace(".remap", "")
|
||||
#
|
||||
#if clean_filename.ends_with(".mp3") or clean_filename.ends_with(".wav") or clean_filename.ends_with(".ogg"):
|
||||
#var full_path = path + "/" + clean_filename
|
||||
#
|
||||
#pending_files[full_path] = sound_type
|
||||
#
|
||||
#ResourceLoader.load_threaded_request(full_path)
|
||||
#
|
||||
#print("loading: ", full_path)
|
||||
#
|
||||
#filename = dir.get_next()
|
||||
#else:
|
||||
#print_debug("Failed to open directory: ", path)
|
||||
|
||||
func load_step_sounds():
|
||||
var dir_part = sound_dir_path + "/walking/"
|
||||
|
|
@ -146,13 +171,13 @@ func load_jumping_sounds():
|
|||
load_sound_from_directory_to_var(foot_dir_path_part + type, JUMP_LANDING_SOUNDS)
|
||||
|
||||
|
||||
func start_loading():
|
||||
emit_signal("loading_sounds")
|
||||
is_loading = true
|
||||
load_breath_sounds()
|
||||
load_flashlight_sounds()
|
||||
load_jumping_sounds()
|
||||
load_step_sounds()
|
||||
#func start_loading():
|
||||
#emit_signal("loading_sounds")
|
||||
#is_loading = true
|
||||
#load_breath_sounds()
|
||||
#load_flashlight_sounds()
|
||||
#load_jumping_sounds()
|
||||
#load_step_sounds()
|
||||
|
||||
signal loading_sounds
|
||||
signal loading_sounds_done
|
||||
|
|
@ -195,5 +220,14 @@ func _process(delta: float) -> void:
|
|||
emit_signal("loading_sounds_done")
|
||||
|
||||
func _ready() -> void:
|
||||
start_loading()
|
||||
emit_signal("loading_sounds")
|
||||
|
||||
load_breath_sounds()
|
||||
load_flashlight_sounds()
|
||||
load_jumping_sounds()
|
||||
load_step_sounds()
|
||||
|
||||
# Because load() is synchronous, by the time the code reaches this line,
|
||||
# every single audio file is guaranteed to be 100% loaded.
|
||||
emit_signal("loading_sounds_done")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue