player: revamp health system #4
2 changed files with 19 additions and 5 deletions
|
|
@ -10,11 +10,12 @@ const gear_slots = ["1", "2", "3"]
|
|||
|
||||
var starting_gear = preload("res://gears/ball.tscn")
|
||||
|
||||
var health = 100
|
||||
var suspended = false
|
||||
var direction = Vector3.ZERO
|
||||
var target_velocity = Vector3.ZERO
|
||||
|
||||
var _health = 100
|
||||
|
||||
func resize_ui():
|
||||
var hud_h = 200
|
||||
var size = get_viewport().get_visible_rect().size
|
||||
|
|
@ -31,7 +32,7 @@ func make_hud():
|
|||
continue
|
||||
text += "%s (%s)\n" % [node.gear_name(), node.name]
|
||||
text += "Holding " + $Pivot/Container/Gear.gear_name() + "\n"
|
||||
text += str(health) + " hp"
|
||||
text += str(health()) + " hp"
|
||||
$HUD.text = text
|
||||
|
||||
func message(string):
|
||||
|
|
@ -39,6 +40,19 @@ func message(string):
|
|||
$Message.visible = true
|
||||
$Message/VanishTimer.start()
|
||||
|
||||
func harm(hp):
|
||||
assert(hp >= 0)
|
||||
_health -= hp
|
||||
make_hud()
|
||||
|
||||
func heal(hp):
|
||||
assert(hp >= 0)
|
||||
_health += hp
|
||||
make_hud()
|
||||
|
||||
func health():
|
||||
return _health
|
||||
|
||||
func die():
|
||||
suspended = true
|
||||
visible = false
|
||||
|
|
@ -55,7 +69,7 @@ func die():
|
|||
func respawn():
|
||||
position = Vector3(spawn)
|
||||
$CameraGimbal.reset()
|
||||
health = 100
|
||||
_health = 100
|
||||
visible = true
|
||||
suspended = false
|
||||
|
||||
|
|
@ -159,7 +173,7 @@ func _physics_process(delta):
|
|||
if suspended:
|
||||
return
|
||||
|
||||
if health < 1 or position.y <= -1000:
|
||||
if health() < 1 or position.y <= -1000:
|
||||
die()
|
||||
|
||||
# UI and backpack keys
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ extends Area3D
|
|||
|
||||
func _on_body_entered(body: Node3D):
|
||||
if body is Player:
|
||||
body.health = 0
|
||||
body.die()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue