Implement sprinting

This commit is contained in:
2024-03-29 19:54:55 -07:00
parent ab5fae0ff4
commit 9fbb23aa7a
2 changed files with 29 additions and 1 deletions

View File

@ -1,9 +1,13 @@
extends CharacterBody2D
var speed = 150
var base_speed = 150
var sprint_speed = 300
var exausted_speed = 80
var speed = base_speed
var accel = 10
var immobile = false
var is_sprinting = false
var inventory = {
"points": 0,
@ -14,6 +18,7 @@ var inventory = {
var status = {
"health": 100,
"stamina": 100,
"exausted": false,
"level": 1
}
var current_tool = "none"
@ -47,6 +52,24 @@ func _process(_delta):
inventory[hit_object.resource_type] += 1
inventory.points += 1
hit_object.get_node("animation").play("hit")
is_sprinting = Input.is_action_pressed("move_sprint") && !status.exausted and velocity.distance_to(Vector2.ZERO) > 0
if is_sprinting:
speed = sprint_speed
status.stamina -= 1
if status.stamina <= 0:
is_sprinting = false
status.exausted = true
else:
if status.stamina < 100:
status.stamina += 0.5
if status.exausted:
speed = exausted_speed
else:
speed = base_speed
if status.stamina == 100 and status.exausted:
status.exausted = false
# Update inventory HUD
$hud/inventory/stone_label.text = str(inventory.stone)

View File

@ -50,6 +50,11 @@ game_interact={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(220, 23),"global_position":Vector2(224, 66),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
move_sprint={
"deadzone": 0.5,
"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,"echo":false,"script":null)
]
}
[rendering]