Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/player.gd
diff options
context:
space:
mode:
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: