Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/player.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/player.gd')
-rw-r--r--scripts/player.gd24
1 files changed, 22 insertions, 2 deletions
diff --git a/scripts/player.gd b/scripts/player.gd
index 375d700..95878d0 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -5,6 +5,13 @@ const SPEED = 5.0
const RUN_SPEED = 1.5 * SPEED
const JUMP_VELOCITY = 4.5
const THROW_FORCE = 10.0
+const RUN_CONSUMPTION = 20.0
+const STAM_REGEN = 10.0
+
+#@export_node_path("ProgressBar") var stam_bar_path = null
+@export var stam_bar: ProgressBar = null;
+
+var stamina: float = 100
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@@ -45,17 +52,24 @@ func throw():
holding = null
func _ready():
+ assert(stam_bar != null, "Stamina bar is null")
+
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$ThirdPersonCamera.mouse_follow = true
$Picker.connect("body_entered", got_body)
$Picker.connect("body_exited", leave_body)
+
+func _process(_delta):
+ stam_bar.value = stamina
func _physics_process(delta):
var speed = SPEED
+ var stam_consumption = 0
- if Input.is_action_pressed("run"):
+ if Input.is_action_pressed("run") and stamina > 0:
speed = RUN_SPEED
+ stam_consumption += RUN_CONSUMPTION
if Input.is_action_just_pressed("pickup"):
if holding == null and current_node != null:
@@ -72,9 +86,10 @@ func _physics_process(delta):
var climb_direction_fwd = Vector3()
var climb_direction_right = Vector3()
- if is_on_wall():
+ if is_on_wall() and stamina > 0:
last_wall_direction = get_wall_normal()
climbing = true
+ stam_consumption += RUN_CONSUMPTION
print("Climbing now")
elif climbing:
climbing = false
@@ -108,3 +123,8 @@ func _physics_process(delta):
velocity.z = move_toward(velocity.z, 0, speed)
move_and_slide()
+
+ if stam_consumption == 0 and not Input.is_action_pressed("run") and is_on_floor():
+ stam_consumption = -STAM_REGEN
+
+ stamina = clamp(stamina - stam_consumption * delta, 0, 100)