player: revamp health system #4
1 changed files with 29 additions and 16 deletions
|
|
@ -16,6 +16,8 @@ var target_velocity = Vector3.ZERO
|
|||
|
||||
var _health = 100
|
||||
|
||||
# Player UI
|
||||
|
||||
func resize_ui():
|
||||
var hud_h = 200
|
||||
var size = get_viewport().get_visible_rect().size
|
||||
|
|
@ -40,6 +42,8 @@ func message(string):
|
|||
$Message.visible = true
|
||||
$Message/VanishTimer.start()
|
||||
|
||||
# State functions
|
||||
|
||||
func harm(hp):
|
||||
assert(hp >= 0)
|
||||
_health -= hp
|
||||
|
|
@ -143,7 +147,7 @@ func equip(gear: Gear):
|
|||
message("Backpack full")
|
||||
return false
|
||||
|
||||
# Player movement and engine callbacks
|
||||
# Player mechanics
|
||||
|
||||
func move_player(x, z):
|
||||
var camera_basis = $CameraGimbal.get_global_transform().basis
|
||||
|
|
@ -164,19 +168,7 @@ func move_player(x, z):
|
|||
if x != 0:
|
||||
direction += camera_basis.x * x
|
||||
|
||||
func _ready():
|
||||
get_viewport().size_changed.connect(resize_ui)
|
||||
resize_ui()
|
||||
respawn()
|
||||
|
||||
func _physics_process(delta):
|
||||
if suspended:
|
||||
return
|
||||
|
||||
if health() < 1 or position.y <= -1000:
|
||||
die()
|
||||
|
||||
# UI and backpack keys
|
||||
func do_backpack_keys():
|
||||
if Input.is_action_just_pressed("backpack_1"):
|
||||
use_backpack_slot("1")
|
||||
if Input.is_action_just_pressed("backpack_2"):
|
||||
|
|
@ -184,7 +176,7 @@ func _physics_process(delta):
|
|||
if Input.is_action_just_pressed("backpack_3"):
|
||||
use_backpack_slot("3")
|
||||
|
||||
# Movement keys
|
||||
func do_movement(delta):
|
||||
var mx = 0
|
||||
var mz = 0
|
||||
|
||||
|
|
@ -212,7 +204,7 @@ func _physics_process(delta):
|
|||
|
||||
move_and_slide()
|
||||
|
||||
# Gear uses
|
||||
func do_gears():
|
||||
var gear = $Pivot/Container/Gear
|
||||
assert(gear is Gear)
|
||||
if gear.continuous():
|
||||
|
|
@ -222,6 +214,27 @@ func _physics_process(delta):
|
|||
if Input.is_action_just_pressed("gear_use"):
|
||||
gear.use(self)
|
||||
|
||||
# Engine callbacks
|
||||
|
||||
func _ready():
|
||||
get_viewport().size_changed.connect(resize_ui)
|
||||
resize_ui()
|
||||
respawn()
|
||||
|
||||
func _physics_process(delta):
|
||||
if health() < 1 or position.y <= -1000:
|
||||
die()
|
||||
|
||||
if suspended:
|
||||
return
|
||||
|
||||
# Backpack keys
|
||||
do_backpack_keys()
|
||||
# Movement
|
||||
do_movement(delta)
|
||||
# Use gears
|
||||
do_gears()
|
||||
|
||||
# Signals
|
||||
|
||||
func _on_vanish_timer_timeout():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue