diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2023-09-24 20:24:28 -0400 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2023-09-24 20:24:28 -0400 |
commit | 98dcf44062b92bf4f17b5e705257154413159880 (patch) | |
tree | a189e3b4bf184eddab9e2f34e9f80f60887c1d3f | |
parent | a16c3354383f476602b25b079636c9c89b95cd9c (diff) |
Add stamina bar
-rw-r--r-- | project.godot | 5 | ||||
-rw-r--r-- | scenes/main.tscn | 9 | ||||
-rw-r--r-- | scripts/player.gd | 24 |
3 files changed, 35 insertions, 3 deletions
diff --git a/project.godot b/project.godot index b8e7658..07bd64d 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ config/icon="res://icon.svg" MarchingCubes="*res://scripts/marching_cubes.gd" +[filesystem] + +import/blender/enabled=false +import/fbx/enabled=false + [input] forward={ diff --git a/scenes/main.tscn b/scenes/main.tscn index fba8f18..f7c295f 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -52,8 +52,9 @@ shape = SubResource("BoxShape3D_gtg8d") mesh = SubResource("PlaneMesh_ypd0i") skeleton = NodePath("../..") -[node name="Player" parent="." instance=ExtResource("3_8dect")] +[node name="Player" parent="." node_paths=PackedStringArray("stam_bar") instance=ExtResource("3_8dect")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 18.7109, 0, 0) +stam_bar = NodePath("../StaminaBar") [node name="StaticBody3D" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.7194, 5, -6.35033) @@ -63,3 +64,9 @@ shape = SubResource("BoxShape3D_kjqqf") [node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D"] mesh = SubResource("BoxMesh_f2n6h") + +[node name="StaminaBar" type="ProgressBar" parent="."] +offset_left = 32.0 +offset_top = 7.0 +offset_right = 1103.0 +offset_bottom = 34.0 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) |