feat: Add stamina system
This commit is contained in:
parent
9013361e29
commit
7cfbfb3a04
24
player.gd
24
player.gd
|
|
@ -1,7 +1,29 @@
|
|||
extends CharacterBody3D
|
||||
const BASE_STAMINA = 50
|
||||
const BASE_SPEED = 4
|
||||
const SPRINT_MULT = 1.6
|
||||
const STAMINA_COST = 15
|
||||
const STAMINA_RECOVER = 10
|
||||
|
||||
|
||||
var stamina: float = BASE_STAMINA
|
||||
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
$StaminaLabel.text = str(int(stamina))
|
||||
|
||||
var dir = Input.get_vector("player_move_left", "player_move_right", "player_move_up", "player_move_down")
|
||||
|
||||
self.velocity = Vector3(dir.x * 5, 0, dir.y * 5)
|
||||
var speed: float = BASE_SPEED
|
||||
|
||||
if Input.is_action_pressed("player_sprint") and stamina > 0:
|
||||
stamina -= STAMINA_COST * delta
|
||||
speed *= SPRINT_MULT
|
||||
elif stamina <= BASE_STAMINA:
|
||||
stamina += STAMINA_RECOVER * delta
|
||||
|
||||
self.velocity = Vector3(dir.x * speed, 0, dir.y * speed)
|
||||
print(str(self.velocity))
|
||||
|
||||
self.move_and_slide()
|
||||
|
|
|
|||
|
|
@ -22,3 +22,8 @@ surface_material_override/0 = SubResource("StandardMaterial3D_4flbx")
|
|||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=271233394]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)
|
||||
shape = SubResource("BoxShape3D_sh265")
|
||||
|
||||
[node name="StaminaLabel" type="Label" parent="." unique_id=762689230]
|
||||
offset_right = 99.0
|
||||
offset_bottom = 46.0
|
||||
theme_override_colors/font_color = Color(0.83137256, 0, 0.18039216, 1)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ player_move_down={
|
|||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
player_sprint={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue