94 lines
3.1 KiB
GDScript
Executable File
94 lines
3.1 KiB
GDScript
Executable File
extends CharacterBody3D
|
|
|
|
|
|
const SPEED = 5.0
|
|
|
|
var camrot_x = 0.0
|
|
var camrot_y = 0.0
|
|
|
|
var sensitivity = 0.25
|
|
|
|
|
|
|
|
var flickerWait = 0
|
|
var flickerWaited = 0
|
|
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|
|
|
func _ready():
|
|
$emptyPlace.play()
|
|
$catchingUp.play()
|
|
Globals.makePlayerControlled()
|
|
Globals.playerInitPos = position
|
|
Globals.playerInitRotation = rotation
|
|
camrot_x = $camera/UpDown.rotation_degrees.x
|
|
camrot_y = rotation_degrees.y
|
|
|
|
func _process(delta):
|
|
var x = (Globals.shrekPos.x-position.x)
|
|
var z = (Globals.shrekPos.z-position.z)
|
|
var distance = sqrt(x*x + z*z)
|
|
if Globals.huntMode == -1 && distance > 100:
|
|
Globals.huntMode = 0
|
|
if Globals.huntMode == -1: distance = 1000
|
|
$emptyPlace.volume_db = clamp(-65 + (distance - 40), -80, -65)
|
|
$catchingUp.volume_db = clamp(-80*(distance/30), -80, 0)
|
|
|
|
$camera/UpDown/Camera3D.environment.fog_light_energy = clamp(((4-Globals.difficulty)/2)*((distance-10)/30), 0, (4-Globals.difficulty)/2)
|
|
$camera/UpDown/Camera3D.environment.fog_density = 0.01 + (0.02*(Globals.difficulty/2))
|
|
$camera/UpDown/torch/main.light_energy = clamp((3-(Globals.difficulty))*(distance/30), 0, (3-(Globals.difficulty)))
|
|
$camera/UpDown/torch/outer.light_energy = clamp(0.1*(distance/30), 0, 0.1)
|
|
$camera/UpDown/torch/main.spot_range = clamp(distance, 0, 40-(10*Globals.difficulty))
|
|
$camera/UpDown/torch/main.light_color = Color(1.0,(185*clamp(distance/30, 0.0,1.0))/255,(122*clamp(distance/30, 0.0,1.0))/255,1)
|
|
$camera/UpDown/torch/outer.light_color = $camera/UpDown/torch/main.light_color
|
|
|
|
if distance <= 30:
|
|
flickerWaited += delta*1000
|
|
if flickerWaited >= flickerWait:
|
|
flickerWaited = 0
|
|
$camera/UpDown.visible = !$camera/UpDown.visible
|
|
flickerWait = randf_range(50, (75+((distance/30)*500)) if $camera/UpDown.visible else 75)
|
|
else:
|
|
$camera/UpDown.visible = true
|
|
|
|
func _input(event):
|
|
if !Globals.playerControlled: return
|
|
if event is InputEventMouseMotion:
|
|
camrot_x -= float(event.relative.y)*sensitivity
|
|
camrot_y -= float(event.relative.x)*sensitivity
|
|
camrot_x = float(clamp(camrot_x, -70, 45))
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
# Add the gravity.
|
|
if not is_on_floor():
|
|
velocity.y -= gravity * delta
|
|
|
|
if Globals.playerControlled:
|
|
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
|
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)
|
|
|
|
# Adjust the speed when moving backward
|
|
if input_dir.y > 0:
|
|
velocity.x *= 0.75
|
|
velocity.z *= 0.75
|
|
|
|
$camera/UpDown.rotation_degrees.x = camrot_x
|
|
|
|
var look_dir = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
|
var look_direction = Vector3(look_dir.x, 0, look_dir.y)
|
|
camrot_x -= float(look_direction.z)*delta*sensitivity*1000
|
|
camrot_y -= float(look_direction.x)*delta*sensitivity*1000
|
|
camrot_x = float(clamp(camrot_x, -70, 45))
|
|
rotation_degrees.y = camrot_y
|
|
move_and_slide()
|
|
Globals.playerPos = position
|