Add interactions for hydroponics

This commit is contained in:
Daniel Snider 2022-08-13 21:36:30 -07:00
parent 4c3f01a835
commit 2884c9b096
11 changed files with 167 additions and 13 deletions

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/forceField_004.ogg-7f905408cd821478cd3d449ca9826a1d.oggstr"
[deps]
source_file="res://assets/sound/forceField_004.ogg"
dest_files=[ "res://.import/forceField_004.ogg-7f905408cd821478cd3d449ca9826a1d.oggstr" ]
[params]
loop=false
loop_offset=0

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/handleSmallLeather.ogg-5ff0261d6170c004bb74db95081a5fe6.oggstr"
[deps]
source_file="res://assets/sound/handleSmallLeather.ogg"
dest_files=[ "res://.import/handleSmallLeather.ogg-5ff0261d6170c004bb74db95081a5fe6.oggstr" ]
[params]
loop=false
loop_offset=0

View File

@ -0,0 +1,50 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://scripts/coin_machine.gd" type="Script" id=1]
[ext_resource path="res://scripts/hydroponics_station.gd" type="Script" id=2]
[ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=3]
[sub_resource type="CylinderMesh" id=1]
height = 0.936
radial_segments = 8
[sub_resource type="CubeMesh" id=3]
size = Vector3( 0.4, 1, 0.4 )
[sub_resource type="ConvexPolygonShape" id=2]
points = PoolVector3Array( -0.0608763, 0.449247, 0.974783, -0.0608763, -0.464612, -0.974783, -0.0608763, 0.449247, -0.974783, 0.974783, -0.464612, -0.0608763, -0.974783, -0.464612, 0.0608763, 0.974783, 0.449247, 0.0608763, 0.0606902, -0.464648, 0.97486, -0.974783, 0.449247, -0.0608763, 0.7071, 0.453517, -0.7071, -0.705748, -0.468, -0.705748, -0.7071, 0.453517, 0.7071, 0.7071, 0.453517, 0.7071, 0.705748, -0.468, 0.705748, -0.705748, -0.468, 0.705748, 0.705748, -0.468, -0.705748, -0.7071, 0.453517, -0.7071, 0.0606902, -0.464648, -0.97486, -0.974783, -0.464612, -0.0608763, 0.974783, -0.464612, 0.0608763, -0.0608763, -0.464612, 0.974783, 0.0606902, 0.449283, 0.97486, 0.0606902, 0.449283, -0.97486, 0.974783, 0.449247, -0.0608763, -0.974783, 0.449247, 0.0608763, -0.642208, -0.46642, 0.73398, -0.642208, -0.46642, -0.73398, 0.578116, -0.464071, -0.760529, 0.578116, -0.464071, 0.760529, 0.760589, -0.464107, 0.577971, -0.760589, -0.464107, 0.577971, -0.760589, -0.464107, -0.577971, 0.760589, -0.464107, -0.577971 )
[node name="hydroponics_station" type="Spatial"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 11.4134, 0, -2.96909 )
script = ExtResource( 2 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.372095, 0 )
mesh = SubResource( 1 )
[node name="Yam" type="MeshInstance" parent="MeshInstance"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.886431, 0 )
visible = false
mesh = SubResource( 3 )
skeleton = NodePath("../../..")
[node name="status_label" type="Label3D" parent="MeshInstance"]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.737837, 0 )
billboard = 1
[node name="StaticBody" type="StaticBody" parent="."]
[node name="CollisionShape2" type="CollisionShape" parent="StaticBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.372095, 0 )
shape = SubResource( 2 )
[node name="coin_machine" type="Area" parent="." instance=ExtResource( 3 )]
transform = Transform( 0.540026, 0, 0, 0, 0.571038, 0, 0, 0, 0.497953, 0, 0.418593, 0 )
script = ExtResource( 1 )
[node name="grow_timer" type="Timer" parent="."]
one_shot = true
[connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"]
[connection signal="timeout" from="grow_timer" to="." method="_on_Timer_timeout"]

17
scenes/item_pickup.tscn Normal file
View File

@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://scripts/item_pickup.gd" type="Script" id=1]
[ext_resource path="res://assets/sound/handleSmallLeather.ogg" type="AudioStream" id=2]
[sub_resource type="SphereShape" id=1]
[node name="item_pickup" type="Area"]
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 1 )
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 2 )
[connection signal="finished" from="AudioStreamPlayer" to="." method="_on_AudioStreamPlayer_finished"]

View File

@ -3,17 +3,25 @@
[ext_resource path="res://scripts/Player.gd" type="Script" id=1] [ext_resource path="res://scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://assets/protodungman/DungMan.glb" type="PackedScene" id=2] [ext_resource path="res://assets/protodungman/DungMan.glb" type="PackedScene" id=2]
[sub_resource type="SphereShape" id=3]
[sub_resource type="CapsuleShape" id=2] [sub_resource type="CapsuleShape" id=2]
radius = 0.210213 radius = 0.210213
height = 0.85525 height = 0.85525
[sub_resource type="SphereShape" id=3]
[node name="Player" type="KinematicBody"] [node name="Player" type="KinematicBody"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="DungMan" parent="." instance=ExtResource( 2 )] [node name="DungMan" parent="." instance=ExtResource( 2 )]
[node name="TriggerVolume" type="Area" parent="DungMan"]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.630386 )
[node name="CollisionShape" type="CollisionShape" parent="DungMan/TriggerVolume"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.168703 )
shape = SubResource( 3 )
[node name="CollisionShape" type="CollisionShape" parent="."] [node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.641703, 0 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.641703, 0 )
shape = SubResource( 2 ) shape = SubResource( 2 )
@ -21,8 +29,3 @@ shape = SubResource( 2 )
[node name="Camera" type="Camera" parent="."] [node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.5, 0.866025, 0, -0.866025, 0.5, 0, 5.44166, 3.39746 ) transform = Transform( 1, 0, 0, 0, 0.5, 0.866025, 0, -0.866025, 0.5, 0, 5.44166, 3.39746 )
fov = 50.0 fov = 50.0
[node name="TriggerVolume" type="Area" parent="."]
[node name="CollisionShape" type="CollisionShape" parent="TriggerVolume"]
shape = SubResource( 3 )

View File

@ -1,5 +1,6 @@
extends KinematicBody extends KinematicBody
const EPSILON = 0.0001
const SPEED = 3.0 const SPEED = 3.0
export var inventory = { "ore" : 0 } export var inventory = { "ore" : 0 }
@ -11,7 +12,8 @@ func _ready():
func _physics_process(delta): func _physics_process(delta):
var input = Vector3(Input.get_axis("left", "right"), 0.0, Input.get_axis("up", "down")) 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 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) move_and_slide(motion)
func can_afford(item_name, item_amount): func can_afford(item_name, item_amount):
@ -46,7 +48,7 @@ func modify_inventory(item_name, item_amount):
func _unhandled_input(event): func _unhandled_input(event):
if event.is_action_pressed("action"): 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): if try_trigger_interact(area):
break break
@ -58,6 +60,10 @@ func try_trigger_interact(area):
if not owner.has_method("on_player_interact"): if not owner.has_method("on_player_interact"):
return false 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) print("player interacted with ", owner)
return true return true

View File

@ -1,16 +1,20 @@
extends Area extends Area
export var coins_required : int = 1 export var coins_required : int = 1
export var enabled: bool = true
signal coin_requirement_met; signal coin_requirement_met(player)
func _ready(): func _ready():
assert(coins_required >= 0) assert(coins_required >= 0)
set_meta("owner", self) set_meta("owner", self)
func on_player_interact(player): func on_player_interact(player) -> bool:
assert(player.has_method("modify_inventory")) assert(player.has_method("modify_inventory"))
if not enabled:
return false
if not player.modify_inventory("coins", -coins_required): if not player.modify_inventory("coins", -coins_required):
return return false
emit_signal("coin_requirement_met", player) emit_signal("coin_requirement_met", player)
return true

View File

@ -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

18
scripts/item_pickup.gd Normal file
View File

@ -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()