Compare commits
2 commits
5b8d7fdcce
...
27613b766f
| Author | SHA1 | Date | |
|---|---|---|---|
| 27613b766f | |||
| 7e1847942b |
2 changed files with 47 additions and 20 deletions
|
|
@ -10,11 +10,14 @@ const gear_slots = ["1", "2", "3"]
|
||||||
|
|
||||||
var starting_gear = preload("res://gears/ball.tscn")
|
var starting_gear = preload("res://gears/ball.tscn")
|
||||||
|
|
||||||
var health = 100
|
|
||||||
var suspended = false
|
var suspended = false
|
||||||
var direction = Vector3.ZERO
|
var direction = Vector3.ZERO
|
||||||
var target_velocity = Vector3.ZERO
|
var target_velocity = Vector3.ZERO
|
||||||
|
|
||||||
|
var _health = 100
|
||||||
|
|
||||||
|
# Player UI
|
||||||
|
|
||||||
func resize_ui():
|
func resize_ui():
|
||||||
var hud_h = 200
|
var hud_h = 200
|
||||||
var size = get_viewport().get_visible_rect().size
|
var size = get_viewport().get_visible_rect().size
|
||||||
|
|
@ -31,7 +34,7 @@ func make_hud():
|
||||||
continue
|
continue
|
||||||
text += "%s (%s)\n" % [node.gear_name(), node.name]
|
text += "%s (%s)\n" % [node.gear_name(), node.name]
|
||||||
text += "Holding " + $Pivot/Container/Gear.gear_name() + "\n"
|
text += "Holding " + $Pivot/Container/Gear.gear_name() + "\n"
|
||||||
text += str(health) + " hp"
|
text += str(health()) + " hp"
|
||||||
$HUD.text = text
|
$HUD.text = text
|
||||||
|
|
||||||
func message(string):
|
func message(string):
|
||||||
|
|
@ -39,6 +42,21 @@ func message(string):
|
||||||
$Message.visible = true
|
$Message.visible = true
|
||||||
$Message/VanishTimer.start()
|
$Message/VanishTimer.start()
|
||||||
|
|
||||||
|
# State functions
|
||||||
|
|
||||||
|
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():
|
func die():
|
||||||
suspended = true
|
suspended = true
|
||||||
visible = false
|
visible = false
|
||||||
|
|
@ -55,7 +73,7 @@ func die():
|
||||||
func respawn():
|
func respawn():
|
||||||
position = Vector3(spawn)
|
position = Vector3(spawn)
|
||||||
$CameraGimbal.reset()
|
$CameraGimbal.reset()
|
||||||
health = 100
|
_health = 100
|
||||||
visible = true
|
visible = true
|
||||||
suspended = false
|
suspended = false
|
||||||
|
|
||||||
|
|
@ -129,7 +147,7 @@ func equip(gear: Gear):
|
||||||
message("Backpack full")
|
message("Backpack full")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# Player movement and engine callbacks
|
# Player mechanics
|
||||||
|
|
||||||
func move_player(x, z):
|
func move_player(x, z):
|
||||||
var camera_basis = $CameraGimbal.get_global_transform().basis
|
var camera_basis = $CameraGimbal.get_global_transform().basis
|
||||||
|
|
@ -150,19 +168,7 @@ func move_player(x, z):
|
||||||
if x != 0:
|
if x != 0:
|
||||||
direction += camera_basis.x * x
|
direction += camera_basis.x * x
|
||||||
|
|
||||||
func _ready():
|
func do_backpack_keys():
|
||||||
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
|
|
||||||
if Input.is_action_just_pressed("backpack_1"):
|
if Input.is_action_just_pressed("backpack_1"):
|
||||||
use_backpack_slot("1")
|
use_backpack_slot("1")
|
||||||
if Input.is_action_just_pressed("backpack_2"):
|
if Input.is_action_just_pressed("backpack_2"):
|
||||||
|
|
@ -170,7 +176,7 @@ func _physics_process(delta):
|
||||||
if Input.is_action_just_pressed("backpack_3"):
|
if Input.is_action_just_pressed("backpack_3"):
|
||||||
use_backpack_slot("3")
|
use_backpack_slot("3")
|
||||||
|
|
||||||
# Movement keys
|
func do_movement(delta):
|
||||||
var mx = 0
|
var mx = 0
|
||||||
var mz = 0
|
var mz = 0
|
||||||
|
|
||||||
|
|
@ -198,7 +204,7 @@ func _physics_process(delta):
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
# Gear uses
|
func do_gears():
|
||||||
var gear = $Pivot/Container/Gear
|
var gear = $Pivot/Container/Gear
|
||||||
assert(gear is Gear)
|
assert(gear is Gear)
|
||||||
if gear.continuous():
|
if gear.continuous():
|
||||||
|
|
@ -208,6 +214,27 @@ func _physics_process(delta):
|
||||||
if Input.is_action_just_pressed("gear_use"):
|
if Input.is_action_just_pressed("gear_use"):
|
||||||
gear.use(self)
|
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
|
# Signals
|
||||||
|
|
||||||
func _on_vanish_timer_timeout():
|
func _on_vanish_timer_timeout():
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@ extends Area3D
|
||||||
|
|
||||||
func _on_body_entered(body: Node3D):
|
func _on_body_entered(body: Node3D):
|
||||||
if body is Player:
|
if body is Player:
|
||||||
body.health = 0
|
body.die()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue