ld52_olive_harvest/scenery/facilities/OliveTree.gd

62 lines
1.5 KiB
GDScript

extends StaticBody2D
var has_been_munched: bool = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func interact(_player):
# drop the olives!
for child in self.get_children():
if child.has_method("drop_olive"):
if child.drop_olive():
$FallSfx.pitch_scale = rand_range(0.9, 1.5)
$FallSfx.play()
break
# Calculate some measure of food that makes this tree attractive to pests.
# Calculate it in a given time.
func calculate_food(in_time: float) -> float:
var food = 0
if not has_been_munched:
# munching a tree is worth 2 foods
food += 2
for child in self.get_children():
if child.has_method("drop_olive"):
food += child.calculate_food_on_bud(in_time)
return food
func eat_food() -> float:
if not has_been_munched:
# TODO sfx
# TODO show munched sprite... colour will do for now
$Sprite.modulate = Color(0.6, 0.4, 0.4)
has_been_munched = true
for child in self.get_children():
# curse all buds
# TODO they will recover when next harvested, so this isn't as bad
# as it sounds..
if child.has_method("drop_olive"):
child.grow_rate *= 0.5
return 2.0
var limit = 1.0
var eaten = 0
for child in self.get_children():
if child.has_method("drop_olive"):
eaten += child.eat_food_from_bud(limit - eaten)
if limit - eaten < 0.01:
break
return eaten