-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.gd
162 lines (136 loc) · 4.9 KB
/
Main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
extends Node2D
onready var shelf = $Shelf
onready var ingredient_holder = $Ingredients
onready var customer_path = $CustomerPath/PathFollow2D
onready var bgmusic = $BGAudio
onready var selectaudio = $ItemSelectAudio
var current_customer = {}
var mixed = false
func _ready():
randomize()
get_new_customer()
func start_round():
pass
func clear_shelves():
for n in ingredient_holder.get_children():
n.queue_free()
func get_new_customer():
mixed = false
$UIAnimations.play("hide_cauldron")
clear_shelves()
clear_cauldron()
for i in customer_path.get_children():
i.queue_free()
customer_path.offset = 0
current_customer = {}
current_customer.request = Globals.requests[randi()%Globals.requests.size()]
current_customer.image = Globals.customer_images[randi()%Globals.customer_images.size()]
current_customer.color = Globals.customer_colors[randi()%Globals.customer_colors.size()]
var customer = load("res://Customer.tscn").instance()
customer.set_image(current_customer.image)
customer.set_light_color(current_customer.color)
customer_path.add_child(customer)
$CustomerAnimations.play("customer_walk")
yield($CustomerAnimations, "animation_finished")
$UIAnimations.play("show_cauldron")
$UI.start_timer()
$UI.set_text(current_customer.request.request_text)
prepare_items(current_customer.request.required)
func prepare_items(required_items):
#get items ready for the round
#this ensures that required items
#are available in the shop
#var required_items = ["stinky", "lucky", "opposite"]
var items_to_display = []
var shelf_count = shelf.get_child_count()
print("REQUIRED ITEMS:" + str(required_items))
#add required items to the shop
for r in range(required_items.size()):
print(required_items[r])
items_to_display.append(find_an_item(required_items[r]))
print("SELECTED ITEMS:" + str(items_to_display))
#fill in the rest of the list with random items
for _i in range(shelf_count-items_to_display.size()):
items_to_display.append(Globals.ingredients[randi()%Globals.ingredients.size()])
#randomize the list once more for good measure
items_to_display.shuffle()
#go over the list of items
#create Ingredient scenes from them
#and add them to the shelves
for ii in range(items_to_display.size()):
var item = items_to_display[ii]
var slot = shelf.get_child(ii)
var ing = load("res://Ingredients/Ingredient.tscn").instance()
ing.ingredient_type = item.type
ing.ingredient_name = item.name
ing.ingredient_hint = item.hint
ing.ingredient_sprite = "res://Ingredients/"+item.image
#make sure the item is centered on the shelf
ing.set_position(Vector2(slot.position.x-8, slot.position.y-8))
ing.connect("ingredient_selected", self, "_ingredient_selected")
ingredient_holder.add_child(ing)
func _ingredient_selected(type, sprite, hint, pos):
#when a user selects an ingredient
#add to the global cauldron array
#and update the UI
$Shopkeeper.move_to = pos
Globals.add_to_cauldron([type, sprite, hint])
$UI.add_to_cauldron_slot(sprite, Globals.cauldron_contents.size()-1)
selectaudio.play()
func clear_cauldron():
Globals.empty_cauldron()
$UI.reset_cauldron_ui()
$Shopkeeper.stop_ritual()
func good_mix(time_left):
var customer = customer_path.get_child(0)
Globals.score += time_left * (Globals.current_day*1000)
var response = Globals.customer_responses_good[randi()%Globals.customer_responses_good.size()]
$UI.set_text(response)
customer.show_happy_emote()
func bad_mix():
var customer = customer_path.get_child(0)
var response = Globals.customer_responses_bad[randi()%Globals.customer_responses_bad.size()]
$UI.set_text(response)
customer.show_sad_emote()
func too_slow():
var customer = customer_path.get_child(0)
var response = Globals.customer_responses_slow[randi()%Globals.customer_responses_slow.size()]
$UI.set_text(response)
customer.show_confused_emote()
clear_cauldron()
yield(get_tree().create_timer(4), "timeout")
Globals.current_round += 1
get_new_customer()
func find_an_item(item_type):
#pull an item out of the global array
#searches by item type
Globals.ingredients.shuffle()
for i in Globals.ingredients:
if i.type == item_type:
return i
func _on_RoundTimer_timeout():
pass
#get_new_customer()
func _on_UI_cauldron_mixed(time_left):
#fully mixed cauldron
mixed = true
print(time_left)
$Shopkeeper.stop_ritual()
$Shopkeeper.move_to = $CashRegister.position
var cauldron_test = []
for c in Globals.cauldron_contents:
cauldron_test.append(c[0])
#test each item in the cauldron against what the customer wants
if (cauldron_test[0] in current_customer.request.required and cauldron_test[1] in current_customer.request.required and cauldron_test[2] in current_customer.request.required):
good_mix(time_left)
else:
bad_mix()
yield(get_tree().create_timer(4), "timeout")
Globals.current_round += 1
get_new_customer()
func _on_UI_ritual_active():
if !mixed:
$Shopkeeper.start_ritual()
mixed = true
func _on_UI_customer_timer_ended():
too_slow()