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"
|
||||
@ -48,6 +53,24 @@ func _process(_delta):
|
||||
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)
|
||||
$hud/inventory/wood_label.text = str(inventory.wood)
|
||||
|
@ -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]
|
||||
|
||||
|
Reference in New Issue
Block a user