Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/player.gd
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-09-29 14:28:57 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-09-29 14:28:57 +0100
commit0b14efee60765701f439b5174e56c0cf0639d20c (patch)
treeba319069e4f0a8d1377f34c5254246b65cff1765 /scripts/player.gd
parent688a0418fd24c9ffff7dca43dd027ccb3784a373 (diff)
player,bsp_level_generator: Add lockers and interaction
Diffstat (limited to 'scripts/player.gd')
-rw-r--r--scripts/player.gd23
1 files changed, 22 insertions, 1 deletions
diff --git a/scripts/player.gd b/scripts/player.gd
index 275100a..3b1fb6a 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -20,6 +20,8 @@ var bullet_inst = preload("res://prefabs/bullet.tscn")
var ammo: int = 100
var fire_timer: float = fire_rate
+var interactable: Node3D = null
+
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@@ -80,12 +82,31 @@ func fire_weapon(delta: float) -> void:
fire_timer = 0
else:
fire_timer += delta
-
+
+func do_interact() -> void:
+ 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!")
+ else:
+ print("Empty container")
func _physics_process(delta: float) -> void:
do_grapple()
+ do_interact()
fire_weapon(delta)
# Called every frame. 'delta' is the elapsed time since the previous frame.
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:
+ interactable = null