Compare commits
No commits in common. "42de0ed122bfe4ed87c57e7d5cdcab397bc0cb86" and "e616fc4cbbae40a8c70aca11db6128882b5d234f" have entirely different histories.
42de0ed122
...
e616fc4cbb
3 changed files with 35 additions and 64 deletions
|
|
@ -10,57 +10,37 @@ 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 bpui_h = 200
|
||||||
var size = get_viewport().get_visible_rect().size
|
var size = get_viewport().get_visible_rect().size
|
||||||
$Message.size.x = size.x
|
$Message.size.x = size.x
|
||||||
$HUD.size.x = size.x
|
$BackpackUI.size.x = size.x
|
||||||
$HUD.size.y = hud_h
|
$BackpackUI.size.y = bpui_h
|
||||||
$HUD.position.x = 0
|
$BackpackUI.position.x = 0
|
||||||
$HUD.position.y = size.y - hud_h
|
$BackpackUI.position.y = size.y - bpui_h
|
||||||
|
|
||||||
func make_hud():
|
func make_backpack_ui():
|
||||||
var text = ""
|
var text = "Holding " + $Pivot/Container/Gear.gear_name()
|
||||||
for node in $Backpack.get_children():
|
for node in $Backpack.get_children():
|
||||||
if not node is Gear:
|
if not node is Gear:
|
||||||
continue
|
continue
|
||||||
text += "%s (%s)\n" % [node.gear_name(), node.name]
|
text += "\n%s (%s)" % [node.gear_name(), node.name]
|
||||||
text += "Holding " + $Pivot/Container/Gear.gear_name() + "\n"
|
$BackpackUI.text = text
|
||||||
text += str(health()) + " hp"
|
|
||||||
$HUD.text = text
|
|
||||||
|
|
||||||
func message(string):
|
func message(string):
|
||||||
$Message.text = string
|
$Message.text = 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
|
||||||
$HUD.visible = false
|
$BackpackUI.visible = false
|
||||||
|
|
||||||
# strip gears
|
# strip gears
|
||||||
for gear in $Backpack.get_children():
|
for gear in $Backpack.get_children():
|
||||||
|
|
@ -73,7 +53,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
|
||||||
|
|
||||||
|
|
@ -81,8 +61,8 @@ func respawn():
|
||||||
var gear = starting_gear.instantiate()
|
var gear = starting_gear.instantiate()
|
||||||
$Pivot/Container.add_child(gear)
|
$Pivot/Container.add_child(gear)
|
||||||
|
|
||||||
make_hud()
|
make_backpack_ui()
|
||||||
$HUD.visible = true
|
$BackpackUI.visible = true
|
||||||
|
|
||||||
# Backpack functions
|
# Backpack functions
|
||||||
|
|
||||||
|
|
@ -107,7 +87,7 @@ func use_backpack_slot(n):
|
||||||
old.reparent($Backpack, false)
|
old.reparent($Backpack, false)
|
||||||
get_node(gear_node).reparent($Pivot/Container, false)
|
get_node(gear_node).reparent($Pivot/Container, false)
|
||||||
get_node("Pivot/Container/" + n).name = "Gear"
|
get_node("Pivot/Container/" + n).name = "Gear"
|
||||||
make_hud()
|
make_backpack_ui()
|
||||||
return
|
return
|
||||||
# couldn't find a free slot, so replace
|
# couldn't find a free slot, so replace
|
||||||
# the new slot with the current gear
|
# the new slot with the current gear
|
||||||
|
|
@ -115,7 +95,7 @@ func use_backpack_slot(n):
|
||||||
old.reparent($Backpack, false)
|
old.reparent($Backpack, false)
|
||||||
old.name = n
|
old.name = n
|
||||||
get_node("Pivot/Container/" + n).name = "Gear"
|
get_node("Pivot/Container/" + n).name = "Gear"
|
||||||
make_hud()
|
make_backpack_ui()
|
||||||
return
|
return
|
||||||
|
|
||||||
func equip(gear: Gear):
|
func equip(gear: Gear):
|
||||||
|
|
@ -140,14 +120,14 @@ func equip(gear: Gear):
|
||||||
new_gear = gear.duplicate()
|
new_gear = gear.duplicate()
|
||||||
new_gear.name = "Gear"
|
new_gear.name = "Gear"
|
||||||
$Pivot/Container.add_child(new_gear)
|
$Pivot/Container.add_child(new_gear)
|
||||||
make_hud()
|
make_backpack_ui()
|
||||||
message("You picked up a " + gear_name + "!")
|
message("You picked up a " + gear_name + "!")
|
||||||
return true
|
return true
|
||||||
# if no slots are free
|
# if no slots are free
|
||||||
message("Backpack full")
|
message("Backpack full")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# Player mechanics
|
# Player movement and engine callbacks
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -168,7 +148,19 @@ func move_player(x, z):
|
||||||
if x != 0:
|
if x != 0:
|
||||||
direction += camera_basis.x * x
|
direction += camera_basis.x * x
|
||||||
|
|
||||||
func do_backpack_keys():
|
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
|
||||||
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"):
|
||||||
|
|
@ -176,7 +168,7 @@ func do_backpack_keys():
|
||||||
if Input.is_action_just_pressed("backpack_3"):
|
if Input.is_action_just_pressed("backpack_3"):
|
||||||
use_backpack_slot("3")
|
use_backpack_slot("3")
|
||||||
|
|
||||||
func do_movement(delta):
|
# Movement keys
|
||||||
var mx = 0
|
var mx = 0
|
||||||
var mz = 0
|
var mz = 0
|
||||||
|
|
||||||
|
|
@ -204,7 +196,7 @@ func do_movement(delta):
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
func do_gears():
|
# Gear uses
|
||||||
var gear = $Pivot/Container/Gear
|
var gear = $Pivot/Container/Gear
|
||||||
assert(gear is Gear)
|
assert(gear is Gear)
|
||||||
if gear.continuous():
|
if gear.continuous():
|
||||||
|
|
@ -214,27 +206,6 @@ func do_gears():
|
||||||
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():
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ vertical_alignment = 1
|
||||||
wait_time = 4.0
|
wait_time = 4.0
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
|
||||||
[node name="HUD" type="Label" parent="."]
|
[node name="BackpackUI" type="Label" parent="."]
|
||||||
offset_right = 200.0
|
offset_right = 200.0
|
||||||
offset_bottom = 200.0
|
offset_bottom = 200.0
|
||||||
text = "Pictures of you"
|
text = "Pictures of you"
|
||||||
|
|
|
||||||
|
|
@ -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.die()
|
body.health = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue