init
This commit is contained in:
commit
b99855351d
434 changed files with 50357 additions and 0 deletions
93
scripts/player/eyes.gd
Normal file
93
scripts/player/eyes.gd
Normal file
|
@ -0,0 +1,93 @@
|
|||
extends Node2D
|
||||
|
||||
const UP_MAX_POS = -200
|
||||
const UP_MIN_POS = 100
|
||||
const DOWN_MAX_POS = 900
|
||||
const DOWN_MIN_POS = 600
|
||||
|
||||
const MAX_BLINK_VARIATION = 50
|
||||
|
||||
@export var eyeUp: Sprite2D
|
||||
var eyeUpPos = UP_MAX_POS
|
||||
|
||||
@export var eyeDown: Sprite2D
|
||||
var eyeDownPos = DOWN_MIN_POS
|
||||
|
||||
var progress: float
|
||||
|
||||
@export var counter_text: Label
|
||||
const MAX_TIME = 99
|
||||
|
||||
@export var start_time = 50
|
||||
@export var decrease_speed = 0.5
|
||||
var current_time: float
|
||||
|
||||
var timer_going = true
|
||||
|
||||
var enabled = false
|
||||
|
||||
@onready var cutscene = load("res://scenes/ending.tscn")
|
||||
|
||||
func _get_percentage() -> float:
|
||||
return inverse_lerp(MAX_TIME, 0, int(current_time))
|
||||
|
||||
func _quit_dialogue(time_to_add: int):
|
||||
current_time += (time_to_add * 2)
|
||||
current_time = clamp(current_time, 0, MAX_TIME)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
DialogueManager.dialogue_finished.connect(_quit_dialogue)
|
||||
|
||||
current_time = start_time;
|
||||
counter_text.text = ""
|
||||
|
||||
progress = _get_percentage()
|
||||
|
||||
eyeUpPos = lerp(UP_MAX_POS, UP_MIN_POS, progress)
|
||||
eyeDownPos = lerp(DOWN_MAX_POS, DOWN_MIN_POS, progress)
|
||||
|
||||
func enable():
|
||||
counter_text.text = str(int(current_time))
|
||||
enabled = true
|
||||
|
||||
var time = 0.0
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
time += delta
|
||||
|
||||
var pos_offset = _sine_operation(time)
|
||||
|
||||
_eye_pos_up(pos_offset)
|
||||
_eye_pos_down(pos_offset)
|
||||
|
||||
if !enabled:
|
||||
return
|
||||
current_time -= decrease_speed * delta * int(timer_going)
|
||||
counter_text.text = str(int(current_time))
|
||||
progress = _get_percentage()
|
||||
|
||||
eyeUpPos = lerp(UP_MAX_POS, UP_MIN_POS, progress)
|
||||
eyeDownPos = lerp(DOWN_MAX_POS, DOWN_MIN_POS, progress)
|
||||
|
||||
if current_time <= 0.5:
|
||||
SceneTransition.change_scene(cutscene)
|
||||
|
||||
#t: time g: gap o: offset
|
||||
func _sine_function(t: float, g: float, o: float) -> float:
|
||||
return sin(t*g+o)
|
||||
|
||||
func _sine_operation(t: float) -> float:
|
||||
return .25 * (
|
||||
_sine_function(t, 1, 4) +
|
||||
_sine_function(t, 2, 3) +
|
||||
_sine_function(t, 3, 2) +
|
||||
_sine_function(t, 4, 1)
|
||||
)
|
||||
|
||||
func _eye_pos_up(t: float):
|
||||
eyeUp.position.y = int(lerp(eyeUpPos - MAX_BLINK_VARIATION/2, eyeUpPos + MAX_BLINK_VARIATION/2, t) / 4.0) * 4
|
||||
|
||||
func _eye_pos_down(t: float):
|
||||
eyeDown.position.y = int(lerp(eyeDownPos + MAX_BLINK_VARIATION/2, eyeDownPos - MAX_BLINK_VARIATION/2, t) / 4.0) * 4
|
84
scripts/player/player.gd
Normal file
84
scripts/player/player.gd
Normal file
|
@ -0,0 +1,84 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
@export var SPEED = 5.0
|
||||
const MOUSE_SENSITIVITY_X = 0.3
|
||||
const MOUSE_SENSITIVITY_Y = 0.15
|
||||
|
||||
const MAX_ROTATION = 85.0
|
||||
var rotation_x = 0.0
|
||||
|
||||
var in_dialogue = false
|
||||
|
||||
@export var raycast: RayCast3D
|
||||
|
||||
@export var eyes: Node2D
|
||||
|
||||
@export var photo_preview: Control
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
var enabled = false
|
||||
|
||||
func enable():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
enabled = true
|
||||
|
||||
func _input(event):
|
||||
if !enabled || DialogueManager.is_dialog_active:
|
||||
return
|
||||
|
||||
if in_dialogue:
|
||||
photo_preview.hide_picture()
|
||||
eyes.timer_going = true
|
||||
in_dialogue = false
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
rotation_degrees.y -= MOUSE_SENSITIVITY_X * event.relative.x
|
||||
rotation_x -= MOUSE_SENSITIVITY_Y * event.relative.y
|
||||
rotation_x = clamp(rotation_x, -MAX_ROTATION, MAX_ROTATION)
|
||||
$Camera3D.rotation_degrees.x = rotation_x
|
||||
|
||||
var npc: CharacterBody3D
|
||||
func _process(delta):
|
||||
if !enabled:
|
||||
return
|
||||
if raycast.is_colliding():
|
||||
npc = raycast.get_collider()
|
||||
npc.pointing(true)
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
DialogueManager.start_dialog(raycast.get_collider().get_text())
|
||||
|
||||
if raycast.get_collider().is_photo():
|
||||
photo_preview.show_picture(raycast.get_collider().get_photo_index())
|
||||
|
||||
raycast.get_collider().destroy()
|
||||
in_dialogue = true
|
||||
eyes.timer_going = false
|
||||
elif npc != null:
|
||||
npc.pointing(false)
|
||||
npc = null
|
||||
|
||||
func _physics_process(delta):
|
||||
if !enabled:
|
||||
return
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forwards", "move_backwards")
|
||||
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if direction:
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
|
||||
if DialogueManager.is_dialog_active:
|
||||
velocity = Vector3(0, velocity.y, 0)
|
||||
|
||||
move_and_slide()
|
Loading…
Add table
Add a link
Reference in a new issue