Add interactions for hydroponics
This commit is contained in:
1 parent
4c3f01a835
commit
2884c9b096
11 files changed
+167
-13
No files matched your search
+9
-3
@@ -1,5 +1,6 @@
|
||||
extends KinematicBody
|
||||
|
||||
const EPSILON = 0.0001
|
||||
const SPEED = 3.0
|
||||
|
||||
export var inventory = { "ore" : 0 }
|
||||
@@ -11,7 +12,8 @@ func _ready():
|
||||
func _physics_process(delta):
|
||||
var input = Vector3(Input.get_axis("left", "right"), 0.0, Input.get_axis("up", "down"))
|
||||
var motion = Plane.PLANE_XZ.project(get_viewport().get_camera().global_transform.basis.xform(input)).normalized() * SPEED
|
||||
$DungMan.look_at(global_transform.origin - motion, Vector3.UP)
|
||||
if motion.length_squared() > EPSILON:
|
||||
$DungMan.look_at(global_transform.origin - motion, Vector3.UP)
|
||||
move_and_slide(motion)
|
||||
|
||||
func can_afford(item_name, item_amount):
|
||||
@@ -46,7 +48,7 @@ func modify_inventory(item_name, item_amount):
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event.is_action_pressed("action"):
|
||||
for area in $TriggerVolume.get_overlapping_areas():
|
||||
for area in $"%TriggerVolume".get_overlapping_areas():
|
||||
if try_trigger_interact(area):
|
||||
break
|
||||
|
||||
@@ -58,6 +60,10 @@ func try_trigger_interact(area):
|
||||
if not owner.has_method("on_player_interact"):
|
||||
return false
|
||||
|
||||
owner.on_player_interact(self)
|
||||
var result = owner.on_player_interact(self)
|
||||
if not result:
|
||||
print("player failed to interacted with ", owner)
|
||||
return
|
||||
|
||||
print("player interacted with ", owner)
|
||||
return true
|
||||
@@ -1,16 +1,20 @@
|
||||
extends Area
|
||||
|
||||
export var coins_required : int = 1
|
||||
export var enabled: bool = true
|
||||
|
||||
signal coin_requirement_met;
|
||||
signal coin_requirement_met(player)
|
||||
|
||||
func _ready():
|
||||
assert(coins_required >= 0)
|
||||
set_meta("owner", self)
|
||||
|
||||
func on_player_interact(player):
|
||||
func on_player_interact(player) -> bool:
|
||||
assert(player.has_method("modify_inventory"))
|
||||
if not enabled:
|
||||
return false
|
||||
if not player.modify_inventory("coins", -coins_required):
|
||||
return
|
||||
return false
|
||||
|
||||
emit_signal("coin_requirement_met", player)
|
||||
return true
|
||||
@@ -0,0 +1,26 @@
|
||||
extends Spatial
|
||||
|
||||
export var grow_time: float = 2.0
|
||||
|
||||
func _ready():
|
||||
$grow_timer.wait_time = grow_time
|
||||
|
||||
func _on_coin_machine_coin_requirement_met(player):
|
||||
if $grow_timer.is_stopped():
|
||||
$coin_machine.enabled = false
|
||||
$grow_timer.start()
|
||||
|
||||
func _on_Timer_timeout():
|
||||
var yam = preload("res://scenes/item_pickup.tscn").instance()
|
||||
yam.item_name = "yam"
|
||||
yam.item_amount = 1
|
||||
yam.connect("tree_exited", self, "_on_yam_item_tree_exited")
|
||||
$MeshInstance/Yam.visible = true
|
||||
add_child(yam)
|
||||
|
||||
func _on_yam_item_tree_exited():
|
||||
$coin_machine.enabled = true
|
||||
$MeshInstance/Yam.visible = false
|
||||
|
||||
func _process(delta):
|
||||
$"%status_label".text = "%f" % $grow_timer.time_left
|
||||
@@ -0,0 +1,18 @@
|
||||
extends Area
|
||||
|
||||
signal picked_up
|
||||
|
||||
export var item_name: String
|
||||
export var item_amount: int = 1
|
||||
var player: Node
|
||||
|
||||
func on_player_interact(p_player) -> bool:
|
||||
monitorable = false
|
||||
emit_signal("picked_up")
|
||||
player = p_player
|
||||
$AudioStreamPlayer.play()
|
||||
return true
|
||||
|
||||
func _on_AudioStreamPlayer_finished():
|
||||
player.modify_inventory(item_name, item_amount)
|
||||
queue_free()
|
||||
Reference in new issue
Block a user