Implement sprinting
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user