Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/player.gd
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-09-29 22:31:03 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-09-29 22:31:03 +0100
commita10570d865106dcaf1037979cad1788da03e989d (patch)
tree7f49d98cbeb8f85e32351a428e2d898cc8dcfd2a /scripts/player.gd
parent0b14efee60765701f439b5174e56c0cf0639d20c (diff)
ui: Add UI to disply ammo and info toasts
Diffstat (limited to 'scripts/player.gd')
-rw-r--r--scripts/player.gd19
1 files changed, 10 insertions, 9 deletions
diff --git a/scripts/player.gd b/scripts/player.gd
index 3b1fb6a..bbcc4f4 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -6,6 +6,8 @@ extends Node3D
@export var fire_rate: float = 0.1
+@export var ui_control: CanvasLayer
+
enum State {
NO_GRAPPLE,
FREE,
@@ -24,7 +26,7 @@ var interactable: Node3D = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
- pass # Replace with function body.
+ assert(ui_control != null)
func do_grapple() -> void:
if Input.is_action_just_pressed("attack") and current_state == State.FREE:
@@ -61,12 +63,9 @@ func fire_weapon(delta: float) -> void:
var end = ending_pos
if result:
- print("Hit! ")
if result.collider.has_method("on_hit"):
result.collider.on_hit(result.position)
end = result.position
- else:
- print("Miss")
var bullet: Node3D = bullet_inst.instantiate()
bullet.position = starting_pos
@@ -78,20 +77,24 @@ func fire_weapon(delta: float) -> void:
bullet.look_at(end, up)
ammo -= 1
- print("Ammo: ", ammo)
fire_timer = 0
else:
fire_timer += delta
func do_interact() -> void:
+ if interactable != null and not ui_control.have_toast():
+ ui_control.set_toast("Press E to interact", 0)
+ elif interactable == null and not ui_control.have_toast():
+ ui_control.set_toast("", 0)
+
if Input.is_action_just_pressed("interact") and interactable != null:
if interactable.has_method("get_contents"):
var contents = interactable.get_contents()
if contents > 0:
ammo += contents
- print("Got ", contents, " ammo!")
+ ui_control.set_toast("Got " + str(contents) + " ammo!", 1)
else:
- print("Empty container")
+ ui_control.set_toast("Empty container", 1)
func _physics_process(delta: float) -> void:
do_grapple()
@@ -102,10 +105,8 @@ func _physics_process(delta: float) -> void:
func _process(_delta: float) -> void:
pass
-
func _on_interactable_enter(body: Node3D) -> void:
interactable = body
- print("Got interactable")
func _on_interactable_exit(body: Node3D) -> void:
if interactable == body: