Added the item balloons to show on broken machines
This commit is contained in:
1 parent
5e857e478e
commit
002ffef1e8
16 files changed
+1240
-52
No files matched your search
@@ -0,0 +1,35 @@
|
||||
extends Spatial
|
||||
|
||||
class_name ItemBalloon
|
||||
|
||||
const ItemScene = preload("res://scenes/item.tscn")
|
||||
|
||||
onready var anim_tree : AnimationTree = $"%AnimationTree"
|
||||
onready var bounce_timer : Timer = $"%bounce_timer"
|
||||
onready var attached_item = $"%attached_item"
|
||||
|
||||
var anim_playback : AnimationNodeStateMachinePlayback = null
|
||||
var is_bouncing : bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
anim_playback = anim_tree["parameters/playback"]
|
||||
anim_playback.travel("idle")
|
||||
bounce_timer.one_shot = true
|
||||
|
||||
func attach_item(item : Resource):
|
||||
attached_item.set_item_type(item)
|
||||
|
||||
func bounce():
|
||||
if is_bouncing:
|
||||
return
|
||||
is_bouncing = true
|
||||
anim_playback.travel("bounce")
|
||||
bounce_timer.start(anim_playback.get_current_length())
|
||||
|
||||
func _on_bounce_timer_timeout():
|
||||
pass
|
||||
# assert(is_bouncing)
|
||||
# anim_playback.start("Balloon Reset")
|
||||
# anim_playback.travel("Ballon Idle")
|
||||
# is_bouncing = false
|
||||
+35
-24
@@ -2,51 +2,62 @@ extends Spatial
|
||||
signal item_dump_completed
|
||||
signal item_dumped
|
||||
|
||||
# Godot is not configurable enough (without great pains)
|
||||
# to make this look less dumb
|
||||
export var item_type_0: Resource
|
||||
export var item_count_0: int
|
||||
export var item_type_1: Resource
|
||||
export var item_count_1: int
|
||||
export var item_type_2: Resource
|
||||
export var item_count_2: int
|
||||
|
||||
var remaining := {}
|
||||
export var enabled = true
|
||||
export (Array,Resource) var items_required
|
||||
|
||||
onready var one_item_node : Spatial = $"%one_item"
|
||||
onready var two_item_node : Spatial = $"%two_item"
|
||||
|
||||
onready var one_item_balloon : ItemBalloon = $"%one_item_balloon"
|
||||
onready var two_item_balloon1 : ItemBalloon = $"%two_item_balloon1"
|
||||
onready var two_item_balloon2 : ItemBalloon = $"%two_item_balloon2"
|
||||
|
||||
var items_remaining = []
|
||||
|
||||
func _ready():
|
||||
assert(items_required.size() <= 2)
|
||||
reset()
|
||||
update_item_balloons()
|
||||
|
||||
func reset():
|
||||
remaining.clear()
|
||||
if item_type_0 and item_count_0 > 0:
|
||||
remaining[item_type_0] = item_count_0
|
||||
if item_type_1 and item_count_1 > 0:
|
||||
remaining[item_type_1] = item_count_1
|
||||
if item_type_2 and item_count_2 > 0:
|
||||
remaining[item_type_2] = item_count_2
|
||||
items_remaining.clear()
|
||||
for item in items_required:
|
||||
assert(item != null)
|
||||
items_remaining.push_back(item)
|
||||
|
||||
func on_player_interact(player) -> bool:
|
||||
if not enabled:
|
||||
return false
|
||||
if remaining.empty():
|
||||
if items_remaining.empty():
|
||||
return false
|
||||
if not player.has_item():
|
||||
return false
|
||||
if not remaining.has(player.item_in_hand.item_type):
|
||||
if not items_remaining.has(player.item_in_hand.item_type):
|
||||
return false
|
||||
assert(remaining[player.item_in_hand.item_type] > 0, "remaining dictionary should always erase keys with a value of 0")
|
||||
|
||||
# Remove the player's item and mark off the item on the remaining list
|
||||
var item = player.drop_item_in_hand()
|
||||
remaining[item.item_type] -= 1
|
||||
if remaining[item.item_type] <= 0:
|
||||
remaining.erase(item.item_type)
|
||||
items_remaining.erase(item.item_type)
|
||||
item.queue_free()
|
||||
emit_signal("item_dumped")
|
||||
update_item_balloons()
|
||||
|
||||
# Check if everything's been checked off
|
||||
if remaining.empty():
|
||||
if items_remaining.empty():
|
||||
emit_signal("item_dump_completed")
|
||||
|
||||
return true
|
||||
|
||||
func update_item_balloons():
|
||||
if items_remaining.size() == 0:
|
||||
one_item_node.visible = false
|
||||
two_item_node.visible = false
|
||||
elif items_remaining.size() == 1:
|
||||
one_item_node.visible = true
|
||||
two_item_node.visible = false
|
||||
one_item_balloon.attach_item(items_remaining[0])
|
||||
else:
|
||||
one_item_node.visible = false
|
||||
two_item_node.visible = true
|
||||
two_item_balloon1.attach_item(items_remaining[0])
|
||||
two_item_balloon2.attach_item(items_remaining[1])
|
||||
Reference in new issue
Block a user