progress
This commit is contained in:
parent
648f0d0106
commit
ba37c23904
8 changed files with 286 additions and 20 deletions
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://bw0tk6ml7gayq"]
|
[gd_scene load_steps=7 format=3 uid="uid://bw0tk6ml7gayq"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/DynamicMap.gd" id="1_mytgt"]
|
[ext_resource type="Script" path="res://src/DynamicMap.gd" id="1_mytgt"]
|
||||||
[ext_resource type="Script" path="res://src/TempDebugCamera.gd" id="2_co6fy"]
|
[ext_resource type="Script" path="res://src/TempDebugCamera.gd" id="2_co6fy"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dm33ofcbh8sht" path="res://scenes/world/Player.tscn" id="3_43xjf"]
|
||||||
|
|
||||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_tvhkv"]
|
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_tvhkv"]
|
||||||
|
|
||||||
|
@ -12,11 +13,6 @@ sky_material = SubResource("ProceduralSkyMaterial_tvhkv")
|
||||||
background_mode = 2
|
background_mode = 2
|
||||||
sky = SubResource("Sky_qyldw")
|
sky = SubResource("Sky_qyldw")
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4n34s"]
|
|
||||||
|
|
||||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_e2e2m"]
|
|
||||||
material = SubResource("StandardMaterial3D_4n34s")
|
|
||||||
|
|
||||||
[node name="DynamicMap" type="Node3D"]
|
[node name="DynamicMap" type="Node3D"]
|
||||||
script = ExtResource("1_mytgt")
|
script = ExtResource("1_mytgt")
|
||||||
|
|
||||||
|
@ -24,13 +20,10 @@ script = ExtResource("1_mytgt")
|
||||||
environment = SubResource("Environment_d5g72")
|
environment = SubResource("Environment_d5g72")
|
||||||
|
|
||||||
[node name="CameraPivot" type="Node3D" parent="."]
|
[node name="CameraPivot" type="Node3D" parent="."]
|
||||||
|
visible = false
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="CameraPivot"]
|
[node name="Camera3D" type="Camera3D" parent="CameraPivot"]
|
||||||
script = ExtResource("2_co6fy")
|
script = ExtResource("2_co6fy")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
[node name="Player" parent="." instance=ExtResource("3_43xjf")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.49283, 0, -4.85357)
|
transform = Transform3D(0.999178, 0, 0.0405503, 0, 1, 0, -0.0405503, 0, 0.999178, 0, 0, 0)
|
||||||
mesh = SubResource("CapsuleMesh_e2e2m")
|
|
||||||
|
|
||||||
[node name="OmniLight3D" type="OmniLight3D" parent="."]
|
|
||||||
visible = false
|
|
||||||
|
|
16
scenes/world/Player.tscn
Normal file
16
scenes/world/Player.tscn
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://dm33ofcbh8sht"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://src/Player.gd" id="1_n772d"]
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_7hapa"]
|
||||||
|
size = Vector3(1, 2, 1)
|
||||||
|
|
||||||
|
[node name="Player" type="CharacterBody3D"]
|
||||||
|
script = ExtResource("1_n772d")
|
||||||
|
|
||||||
|
[node name="Camera" type="Camera3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
|
||||||
|
|
||||||
|
[node name="Collision" type="CollisionShape3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
|
shape = SubResource("BoxShape3D_7hapa")
|
|
@ -6,6 +6,8 @@ var textureCache: Dictionary
|
||||||
var videoToPlay: String
|
var videoToPlay: String
|
||||||
var clickSound: AudioStreamPlayer
|
var clickSound: AudioStreamPlayer
|
||||||
|
|
||||||
|
var FPSfactor: float
|
||||||
|
|
||||||
func GetTextureFromCache(name:String):
|
func GetTextureFromCache(name:String):
|
||||||
var fixedName = name.replace("\\", "/")
|
var fixedName = name.replace("\\", "/")
|
||||||
if textureCache.has(fixedName):
|
if textureCache.has(fixedName):
|
||||||
|
@ -21,9 +23,6 @@ func _ready():
|
||||||
clickSound.stream = load("res://SFX/Interact/Button.ogg")
|
clickSound.stream = load("res://SFX/Interact/Button.ogg")
|
||||||
clickSound.max_polyphony = 5
|
clickSound.max_polyphony = 5
|
||||||
add_child(clickSound)
|
add_child(clickSound)
|
||||||
#displaySize = DisplayServer.screen_get_size()
|
|
||||||
#menuScale = (displaySize.y / 1024.0)
|
|
||||||
|
|
||||||
#func _process(delta):
|
func _process(delta):
|
||||||
#displaySize = DisplayServer.screen_get_size()
|
FPSfactor = delta
|
||||||
#menuScale = (displaySize.y / 1024.0)
|
|
||||||
|
|
226
src/Player.gd
Normal file
226
src/Player.gd
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
extends CharacterBody3D
|
||||||
|
|
||||||
|
var camera: Camera3D
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
camera = $Camera
|
||||||
|
|
||||||
|
var CurrSpeed: float
|
||||||
|
var CrouchState: float
|
||||||
|
var Crouch: float
|
||||||
|
var NoClip: bool
|
||||||
|
var Playable: bool = true
|
||||||
|
var UnableToMove: bool
|
||||||
|
var ForceMove: float
|
||||||
|
|
||||||
|
var Stamina: float
|
||||||
|
var StaminaEffect:float = 1.0
|
||||||
|
var StaminaEffectTimer: float
|
||||||
|
|
||||||
|
var IsZombie : bool
|
||||||
|
var Shake: float
|
||||||
|
|
||||||
|
var KillTimer: float
|
||||||
|
|
||||||
|
var PlayerFallingPickDistance: float
|
||||||
|
var NoClipSpeed: float
|
||||||
|
var ForceAngle: float
|
||||||
|
var DropSpeed: float
|
||||||
|
var ShouldEntitiesFall: bool
|
||||||
|
|
||||||
|
var Injuries: float
|
||||||
|
|
||||||
|
var Rotation: Vector3 = Vector3()
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
var Sprint = 1.0
|
||||||
|
var Speed = 0.018
|
||||||
|
|
||||||
|
if abs(CrouchState - Crouch) < 0.001:
|
||||||
|
CrouchState = Crouch
|
||||||
|
else:
|
||||||
|
CrouchState = Utils.CurveValue(Crouch, CrouchState, 10.0)
|
||||||
|
|
||||||
|
if not NoClip:
|
||||||
|
if ((Input.is_action_pressed("player_backwards") or Input.is_action_pressed("player_forwards")) or (Input.is_action_pressed("player_right") or Input.is_action_pressed("player_left")) and Playable) or ForceMove > 0:
|
||||||
|
if Crouch == 0 and (Input.is_action_pressed("player_sprint")) and Stamina > 0.0 and (not IsZombie):
|
||||||
|
Sprint = 2.5
|
||||||
|
Stamina = Stamina - Global.FPSfactor * 0.4 * StaminaEffect
|
||||||
|
if Stamina <= 0:
|
||||||
|
Stamina = -20.0
|
||||||
|
|
||||||
|
#If PlayerRoom\RoomTemplate\Name = "pocketdimension" Then
|
||||||
|
#If EntityY(Collider)<2000*RoomScale Or EntityY(Collider)>2608*RoomScale Then
|
||||||
|
#Stamina = 0
|
||||||
|
#Speed = 0.015
|
||||||
|
#Sprint = 1.0
|
||||||
|
#EndIf
|
||||||
|
#EndIf
|
||||||
|
|
||||||
|
if ForceMove > 0:
|
||||||
|
Speed = Speed * ForceMove
|
||||||
|
|
||||||
|
#if SelectedItem != null:
|
||||||
|
#If SelectedItem\itemtemplate\tempname = "firstaid" Or SelectedItem\itemtemplate\tempname = "finefirstaid" Or SelectedItem\itemtemplate\tempname = "firstaid2" Then
|
||||||
|
#Sprint = 0
|
||||||
|
#EndIf
|
||||||
|
#EndIf
|
||||||
|
|
||||||
|
var shake = fmod(Shake, 360)
|
||||||
|
#Local tempchn%
|
||||||
|
if not UnableToMove:
|
||||||
|
Shake = fmod((Shake + Global.FPSfactor * min(Sprint, 1.5) * 7), 720)
|
||||||
|
if shake < 180 and fmod(Shake, 360) >= 180 and KillTimer >= 0:
|
||||||
|
print("step sound")
|
||||||
|
#if CurrStepSFX == 0:
|
||||||
|
#temp = GetStepSound(Collider)
|
||||||
|
#
|
||||||
|
#If Sprint = 1.0 Then
|
||||||
|
#PlayerSoundVolume = Max(4.0,PlayerSoundVolume)
|
||||||
|
#tempchn% = PlaySound_Strict(StepSFX(temp, 0, Rand(0, 7)))
|
||||||
|
#ChannelVolume tempchn, (1.0-(Crouch*0.6))*SFXVolume#
|
||||||
|
#Else
|
||||||
|
#PlayerSoundVolume = Max(2.5-(Crouch*0.6),PlayerSoundVolume)
|
||||||
|
#tempchn% = PlaySound_Strict(StepSFX(temp, 1, Rand(0, 7)))
|
||||||
|
#ChannelVolume tempchn, (1.0-(Crouch*0.6))*SFXVolume#
|
||||||
|
#End If
|
||||||
|
#ElseIf CurrStepSFX=1
|
||||||
|
#tempchn% = PlaySound_Strict(Step2SFX(Rand(0, 2)))
|
||||||
|
#ChannelVolume tempchn, (1.0-(Crouch*0.4))*SFXVolume#
|
||||||
|
#ElseIf CurrStepSFX=2
|
||||||
|
#tempchn% = PlaySound_Strict(Step2SFX(Rand(3,5)))
|
||||||
|
#ChannelVolume tempchn, (1.0-(Crouch*0.4))*SFXVolume#
|
||||||
|
#ElseIf CurrStepSFX=3
|
||||||
|
#If Sprint = 1.0 Then
|
||||||
|
#PlayerSoundVolume = Max(4.0,PlayerSoundVolume)
|
||||||
|
#tempchn% = PlaySound_Strict(StepSFX(0, 0, Rand(0, 7)))
|
||||||
|
#ChannelVolume tempchn, (1.0-(Crouch*0.6))*SFXVolume#
|
||||||
|
#Else
|
||||||
|
#PlayerSoundVolume = Max(2.5-(Crouch*0.6),PlayerSoundVolume)
|
||||||
|
#tempchn% = PlaySound_Strict(StepSFX(0, 1, Rand(0, 7)))
|
||||||
|
#ChannelVolume tempchn, (1.0-(Crouch*0.6))*SFXVolume#
|
||||||
|
#End If
|
||||||
|
else: # noclip on
|
||||||
|
if Input.is_action_pressed("player_sprint"):
|
||||||
|
Sprint = 2.5
|
||||||
|
elif Input.is_action_pressed("player_crouch"):
|
||||||
|
Sprint = 0.5
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("player_crouch") and Playable:
|
||||||
|
Crouch = not Crouch
|
||||||
|
|
||||||
|
var movementSpeed = (Speed * Sprint) / (1.0 + CrouchState)
|
||||||
|
|
||||||
|
if NoClip:
|
||||||
|
Shake = 0
|
||||||
|
CurrSpeed = 0
|
||||||
|
CrouchState = 0
|
||||||
|
Crouch = 0
|
||||||
|
|
||||||
|
#RotateEntity Collider, WrapAngle(EntityPitch(Camera)), WrapAngle(EntityYaw(Camera)), 0
|
||||||
|
camera.rotation.x = deg_to_rad(Rotation.x)
|
||||||
|
rotation.y = deg_to_rad(Rotation.y)
|
||||||
|
|
||||||
|
movementSpeed = movementSpeed * NoClipSpeed
|
||||||
|
|
||||||
|
if Input.is_action_pressed("player_backwards"):
|
||||||
|
position.z += -movementSpeed * Global.FPSfactor
|
||||||
|
if Input.is_action_pressed("player_forwards"):
|
||||||
|
position.z += movementSpeed * Global.FPSfactor
|
||||||
|
|
||||||
|
if Input.is_action_pressed("player_left"):
|
||||||
|
position.x += -movementSpeed * Global.FPSfactor
|
||||||
|
if Input.is_action_pressed("ui_right"):
|
||||||
|
position.x += movementSpeed * Global.FPSfactor
|
||||||
|
else:
|
||||||
|
movementSpeed = movementSpeed / max((Injuries + 3.0) / 3.0, 1.0)
|
||||||
|
if Injuries > 0.5:
|
||||||
|
movementSpeed = movementSpeed * min((sin(Shake / 2) + 1.2), 1.0)
|
||||||
|
|
||||||
|
var temp = false
|
||||||
|
var angle: float = 0
|
||||||
|
if not IsZombie:
|
||||||
|
if Input.is_action_pressed("player_backwards") and Playable:
|
||||||
|
temp = true
|
||||||
|
angle = 180
|
||||||
|
if Input.is_action_pressed("player_left"):
|
||||||
|
angle = 135
|
||||||
|
if Input.is_action_pressed("player_right"):
|
||||||
|
angle = -135
|
||||||
|
elif Input.is_action_pressed("player_forwards") and Playable: # Or ForceMove>0
|
||||||
|
temp = true
|
||||||
|
angle = 0
|
||||||
|
if Input.is_action_pressed("player_left"):
|
||||||
|
angle = 45
|
||||||
|
if Input.is_action_pressed("player_right"):
|
||||||
|
angle = -45
|
||||||
|
elif ForceMove > 0:
|
||||||
|
temp = true
|
||||||
|
angle = ForceAngle
|
||||||
|
elif Playable:
|
||||||
|
if Input.is_action_pressed("player_left"):
|
||||||
|
angle = 90
|
||||||
|
temp = true
|
||||||
|
if Input.is_action_pressed("player_right"):
|
||||||
|
angle = -90
|
||||||
|
temp = true
|
||||||
|
else:
|
||||||
|
temp = true
|
||||||
|
angle = ForceAngle
|
||||||
|
|
||||||
|
angle = Utils.WrapAngle(Rotation.y + angle + 90.0)
|
||||||
|
|
||||||
|
if temp:
|
||||||
|
CurrSpeed = Utils.CurveValue(movementSpeed, CurrSpeed, 20.0)
|
||||||
|
else:
|
||||||
|
CurrSpeed = max(Utils.CurveValue(0.0, CurrSpeed - 0.1, 1.0), 0.0)
|
||||||
|
|
||||||
|
#print(str("movementSpeed:", movementSpeed, " angle:", angle, " CurrSpeed:", CurrSpeed))
|
||||||
|
|
||||||
|
if not UnableToMove:
|
||||||
|
#TranslateEntity Collider, Cos(angle)*CurrSpeed * FPSfactor, 0, Sin(angle)*CurrSpeed * FPSfactor, True
|
||||||
|
position.x += cos(angle) * CurrSpeed * 1000 * Global.FPSfactor
|
||||||
|
position.z += sin(angle) * CurrSpeed * 1000 * Global.FPSfactor
|
||||||
|
|
||||||
|
var CollidedFloor = false
|
||||||
|
#For i = 1 To CountCollisions(Collider)
|
||||||
|
#If CollisionY(Collider, i) < EntityY(Collider) - 0.25 Then CollidedFloor = True
|
||||||
|
#Next
|
||||||
|
|
||||||
|
if CollidedFloor:
|
||||||
|
#If DropSpeed# < - 0.07 Then
|
||||||
|
#If CurrStepSFX=0 Then
|
||||||
|
#PlaySound_Strict(StepSFX(GetStepSound(Collider), 0, Rand(0, 7)))
|
||||||
|
#ElseIf CurrStepSFX=1
|
||||||
|
#PlaySound_Strict(Step2SFX(Rand(0, 2)))
|
||||||
|
#ElseIf CurrStepSFX=2
|
||||||
|
#PlaySound_Strict(Step2SFX(Rand(3, 5)))
|
||||||
|
#ElseIf CurrStepSFX=3
|
||||||
|
#PlaySound_Strict(StepSFX(0, 0, Rand(0, 7)))
|
||||||
|
#EndIf
|
||||||
|
#PlayerSoundVolume = Max(3.0,PlayerSoundVolume)
|
||||||
|
#EndIf
|
||||||
|
DropSpeed = 0
|
||||||
|
else:
|
||||||
|
DropSpeed = min(max(DropSpeed - 0.006 * Global.FPSfactor, -2.0), 0.0)
|
||||||
|
if PlayerFallingPickDistance != 0:
|
||||||
|
var pick = true#LinePick(EntityX(Collider),EntityY(Collider),EntityZ(Collider),0,-PlayerFallingPickDistance,0)
|
||||||
|
if pick:
|
||||||
|
DropSpeed = min(max(DropSpeed - 0.006 * Global.FPSfactor, -2.0), 0.0)
|
||||||
|
else:
|
||||||
|
DropSpeed = 0
|
||||||
|
else:
|
||||||
|
DropSpeed = min(max(DropSpeed - 0.006 * Global.FPSfactor, -2.0), 0.0)
|
||||||
|
PlayerFallingPickDistance = 10.0
|
||||||
|
|
||||||
|
if not UnableToMove and ShouldEntitiesFall:
|
||||||
|
#TranslateEntity Collider, 0, DropSpeed * FPSfactor, 0
|
||||||
|
position.y += DropSpeed * Global.FPSfactor
|
||||||
|
|
||||||
|
ForceMove = false
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventMouseMotion:
|
||||||
|
Rotation.y += event.relative.x
|
||||||
|
Rotation.x += event.relative.y
|
||||||
|
#event.velocity
|
|
@ -1,6 +1,6 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
var skipIntro = true
|
var skipIntro = false
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if skipIntro:
|
if skipIntro:
|
||||||
|
|
|
@ -3,10 +3,17 @@ extends Camera3D
|
||||||
var cameraPivot: Node3D
|
var cameraPivot: Node3D
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
||||||
cameraPivot = get_parent()
|
cameraPivot = get_parent()
|
||||||
|
|
||||||
|
if not cameraPivot.visible:
|
||||||
|
cameraPivot.queue_free()
|
||||||
|
|
||||||
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
if not cameraPivot.visible:
|
||||||
|
return
|
||||||
|
|
||||||
if Input.is_action_just_pressed("pause"):
|
if Input.is_action_just_pressed("pause"):
|
||||||
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||||
|
@ -15,6 +22,9 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
if not cameraPivot.visible:
|
||||||
|
return
|
||||||
|
|
||||||
var input_dir = Input.get_vector("player_left", "player_right", "player_forwards", "player_backwards")
|
var input_dir = Input.get_vector("player_left", "player_right", "player_forwards", "player_backwards")
|
||||||
var direction = (cameraPivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
var direction = (cameraPivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||||
|
|
||||||
|
@ -28,6 +38,9 @@ func _physics_process(delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
|
if not cameraPivot.visible:
|
||||||
|
return
|
||||||
|
|
||||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||||
rotation.x -= event.relative.y / 360
|
rotation.x -= event.relative.y / 360
|
||||||
cameraPivot.rotation.y -= event.relative.x / 360
|
cameraPivot.rotation.y -= event.relative.x / 360
|
||||||
|
|
19
src/Utils.gd
Normal file
19
src/Utils.gd
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
class_name Utils
|
||||||
|
|
||||||
|
static func CurveValue(number, old, smooth):
|
||||||
|
if Global.FPSfactor == 0:
|
||||||
|
return old
|
||||||
|
|
||||||
|
if number < old:
|
||||||
|
return max(old + (number - old) * (1.0 / smooth * Global.FPSfactor), number)
|
||||||
|
else:
|
||||||
|
return min(old + (number - old) * (1.0 / smooth * Global.FPSfactor), number)
|
||||||
|
|
||||||
|
static func WrapAngle(angle):
|
||||||
|
if angle == INF:
|
||||||
|
return 0.0
|
||||||
|
while angle < 0:
|
||||||
|
angle = angle + 360
|
||||||
|
while angle >= 360:
|
||||||
|
angle = angle - 360
|
||||||
|
return angle
|
Loading…
Add table
Reference in a new issue