Updated dinner table to allow player to consume valid food

This commit is contained in:
akshay 2022-08-16 20:31:51 -04:00
parent c6da4e0aa2
commit 8d313b8a71
4 changed files with 55 additions and 3 deletions

View File

@ -73,6 +73,7 @@ ssao_enabled = true
[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.27448 )
hunger_tick_time = 10.0
[node name="cameras" type="Spatial" parent="."]
script = ExtResource( 10 )

View File

@ -1,6 +1,10 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/dinner_table.gd" type="Script" id=2]
[ext_resource path="res://item_types/cooked_yam.tres" type="Resource" id=3]
[sub_resource type="SphereShape" id=4]
[sub_resource type="CylinderMesh" id=1]
height = 0.1
@ -15,7 +19,15 @@ radial_segments = 16
[sub_resource type="CylinderShape" id=3]
height = 0.87498
[node name="dinner_table" type="Spatial"]
[node name="dinner_table" type="Area"]
collision_layer = 8
collision_mask = 4
script = ExtResource( 2 )
all_food = [ ExtResource( 3 ) ]
[node name="TriggerVolume" type="CollisionShape" parent="."]
transform = Transform( 1.2, 0, 0, 0, 1.2, 0, 0, 0, 1.2, 0, 0, 0 )
shape = SubResource( 4 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.648164, 0 )
@ -44,4 +56,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.439889, 0 )
shape = SubResource( 3 )
[node name="item_holder" parent="." instance=ExtResource( 1 )]
unique_name_in_owner = true
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.776869, 0 )
[connection signal="item_changed" from="item_holder" to="." method="_on_item_holder_item_changed"]

View File

@ -4,6 +4,7 @@ signal starved_to_death
const EPSILON = 0.0001
const SPEED = 10.0
const MAX_HEALTH = 4
export var hunger_tick_time = 30.0
export var inventory = {}
@ -39,12 +40,16 @@ func _on_hunger_timer_timeout():
print("player: lost health to hunger tick")
func set_health(new_value):
health = min(new_value, 4)
health = min(new_value, MAX_HEALTH)
for child in $"%stomachs".get_children():
child.visible = child.get_index() < health
if health <= 0:
emit_signal("starved_to_death")
func consume_food(item : Resource):
set_health(MAX_HEALTH)
print("player: Hunger Satisfied! Ate %s" % item.name)
func can_afford(item_name, item_amount):
assert(item_amount > 0)
var current_amount : int = 0

31
scripts/dinner_table.gd Normal file
View File

@ -0,0 +1,31 @@
extends Spatial
export(Array, Resource) var all_food
var food_to_consume = null
onready var item_holder = $"%item_holder"
func _ready():
assert(!all_food.empty())
item_holder.add_enabled = true
item_holder.remove_enabled = true
func on_player_interact(player) -> bool:
if food_to_consume == null:
return false
player.consume_food(food_to_consume)
item_holder.destroy_item()
item_holder.remove_enabled = true
return true
func _on_item_holder_item_changed(item):
if item != null:
for food in all_food:
if item.item_type == food:
item_holder.remove_enabled = false
food_to_consume = food
return
food_to_consume = null
item_holder.remove_enabled = true