added a dloading screen, currently only used to load sounds in automatically (you can cahnge the sounds in the assets and it will work automatically since this autoload will load it in on game start ready)
115 lines
4 KiB
GDScript
115 lines
4 KiB
GDScript
extends Node
|
|
|
|
@onready var ui_handler: Node = %UiHandler
|
|
@onready var player_state: Node = %PlayerState
|
|
@onready var flashlight: SpotLight3D = %Flashlight
|
|
@onready var sound_controller: Node = %SoundController
|
|
@onready var cursor_raycast: RayCast3D = %CursorRaycast
|
|
@onready var popup_panels: Control = %PopupPanels
|
|
@onready var stamina_reset: Timer = %StaminaReset
|
|
@onready var player: CharacterBody3D = $"../.."
|
|
@onready var procedural_camera_mover: Node = %ProceduralCameraMover
|
|
@onready var camera: Camera3D = %PlayerCamera
|
|
@onready var hold_position: Marker3D = %HoldPosition
|
|
@onready var player_manager: Node = %PlayerManager
|
|
@onready var ui: Control = %PlayerUi
|
|
|
|
|
|
var sensitivity: float = 0.002
|
|
|
|
var mouse_motion: Vector2 = Vector2.ZERO
|
|
var mouse_motion_delta: Vector2 = Vector2.ZERO
|
|
|
|
var held_object: RigidBody3D = null
|
|
|
|
func toggle_flashlight():
|
|
flashlight.visible = !flashlight.visible
|
|
sound_controller.play_flashlight_sound()
|
|
|
|
func _input(event):
|
|
if not Console.toggled:
|
|
if Input.is_action_just_pressed("open_menu"):
|
|
ui_handler.toggle_menu()
|
|
|
|
if Input.is_action_just_pressed("select_item_1"):
|
|
player_manager.select_item(0)
|
|
|
|
if Input.is_action_just_pressed("select_item_2"):
|
|
player_manager.select_item(1)
|
|
|
|
if Input.is_action_just_pressed("select_item_3"):
|
|
player_manager.select_item(2)
|
|
|
|
if Input.is_action_just_pressed("select_item_4"):
|
|
player_manager.select_item(3)
|
|
|
|
if Input.is_action_just_pressed("select_item_5"):
|
|
player_manager.select_item(4)
|
|
|
|
if not player_state.in_menu:
|
|
if event is InputEventMouseMotion:
|
|
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
|
mouse_motion += event.relative
|
|
mouse_motion_delta = event.relative
|
|
|
|
if Input.is_action_just_pressed("flashlight"):
|
|
toggle_flashlight()
|
|
|
|
if Input.is_action_just_released("jump") or Input.is_action_just_released("sprint"):
|
|
stamina_reset.start()
|
|
|
|
if Input.is_action_just_pressed("grab"):
|
|
if cursor_raycast.is_colliding():
|
|
var hit_object = cursor_raycast.get_collider()
|
|
|
|
if hit_object is RigidBody3D and hit_object.is_in_group("grabbable"):
|
|
held_object = hit_object
|
|
held_object.gravity_scale = 0.0
|
|
held_object.angular_damp = 5.0
|
|
popup_panels.visible = false
|
|
|
|
if Input.is_action_just_released("grab") and held_object != null:
|
|
held_object.gravity_scale = 1.0
|
|
held_object.angular_damp = 0.0
|
|
held_object = null
|
|
popup_panels.visible = true
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
#handle grabbed object
|
|
if held_object != null:
|
|
var target_pos = hold_position.global_position
|
|
var current_pos = held_object.global_position
|
|
var direction = target_pos - current_pos
|
|
|
|
held_object.linear_velocity = direction * PlayerConsts.GRAB_POWER
|
|
|
|
var current_quat = held_object.global_transform.basis.get_rotation_quaternion()
|
|
var target_quat = hold_position.global_transform.basis.get_rotation_quaternion()
|
|
|
|
var delta_quat = target_quat * current_quat.inverse()
|
|
var angle = delta_quat.get_angle()
|
|
var axis = delta_quat.get_axis()
|
|
|
|
if angle > PI:
|
|
angle -= TAU
|
|
|
|
held_object.angular_velocity = axis * angle * PlayerConsts.GRAB_ROTATION_POWER
|
|
|
|
func _process(delta: float) -> void:
|
|
mouse_motion.y = clamp(mouse_motion.y, -1560, 1560)
|
|
player.transform.basis = Basis.from_euler(Vector3(0, mouse_motion.x * -0.001 * PlayerConsts.LOOK_SENSITIVITY, 0))
|
|
camera.transform.basis = lerp(camera.transform.basis, Basis.from_euler(Vector3(mouse_motion.y * -0.001 * PlayerConsts.LOOK_SENSITIVITY, 0, 0)), delta * 10)
|
|
|
|
if not Console.toggled:
|
|
if Input.is_action_just_pressed("next_item"):
|
|
player_manager.next_item()
|
|
|
|
if Input.is_action_just_pressed("prev_item"):
|
|
player_manager.prev_item()
|
|
|
|
#func _unhandled_input(event: InputEvent) -> void:
|
|
#if event is InputEventMouseMotion:
|
|
#player_camera.rotate_y(-event.relative.x * sensitivity)
|
|
#player_camera.rotate_x(-event.relative.y * sensitivity)
|
|
#player_camera.rotation.x = clamp(player_camera.rotation.x, deg_to_rad(-90), deg_to_rad(90))
|
|
#player_camera.rotation.z = 0
|