Updated dinner table to allow player to consume valid food

This commit is contained in:
akshay committed 2022-08-16 20:31:51 -04:00
1 parent c6da4e0aa2
commit 8d313b8a71
4 files changed
+55 -3

No files matched your search

+6 -1
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
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