-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.gd
270 lines (208 loc) · 5.65 KB
/
game.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
extends Node
enum Season { SPRING, SUMMER, FALL, WINTER }
enum DeathReason {
HUNGER,
THIRST,
FREEZE_HOUSE,
FREEZE_FUEL
}
enum Items {
WOOD, STONE, IRON, FOOD
}
const MAX_HUNGER = 10
const HARVEST_AMOUNT = 4
const MAX_THIRST = 25
const THIRST_RATE_SUMMER = 2
const THIRST_RATE_REGULAR = 4
const MAX_TOOLS = 20
const TOOLS_PRICE = 4
const TOOLS_AMOUNT = 10
const THUNDERSTORM_CHANCE = 0.5
const COLD_YEARS_START = 2
var season = Season.SPRING
var year = 0
var hunger_level = MAX_HUNGER
var thirst_level = MAX_THIRST
var house_level = 0
const START_FUEL = 5
var fuel_left = START_FUEL
var tools = 0
var tools_unlocked = false
var thunderstorm = false
var reduced_visuals = false
var Inventory = {
Items.WOOD: 0,
Items.STONE: 0,
Items.IRON: 0,
Items.FOOD: 0,
}
var death_by = null
var stone_info_seen = false
var water_info_seen = false
# Preloaded sprites.
var tree0 = preload("res://assets/Trees and Bushes/Tree_Dark_2.png")
var tree1 = preload("res://assets/Trees and Bushes/Tree_Light_2.png")
var tree2 = preload("res://assets/Trees and Bushes/Tree_Red_2.png")
var tree3 = preload("res://assets/Trees and Bushes/Tree_Snow_2.png")
signal season_changed
signal year_changed
signal fuel_changed
signal hunger_changed
signal thirst_changed
signal tools_changed
signal house_changed
signal inventory_updated
signal notify
func clear_state():
season = Season.SPRING
year = 0
hunger_level = MAX_HUNGER
thirst_level = MAX_THIRST
house_level = 0
fuel_left = START_FUEL
tools = 0
tools_unlocked = false
thunderstorm = false
Inventory = {
Items.WOOD: 0,
Items.STONE: 0,
Items.IRON: 0,
Items.FOOD: 0,
}
death_by = null
stone_info_seen = false
water_info_seen = false
# Called when the node enters the scene tree for the first time.
func _ready():
self.connect("season_changed", _season_changed)
self.connect("fuel_changed", _fuel_changed)
self.connect("year_changed", _year_changed)
self.connect("house_changed", _house_changed)
func dec_thirst():
thirst_level -= 1
thirst_changed.emit(thirst_level)
if thirst_level < 0:
thirst_level = 0
end_game(DeathReason.THIRST)
func inc_thirst():
thirst_level = MAX_THIRST
thirst_changed.emit(thirst_level)
func dec_hunger():
hunger_level -= 1
hunger_changed.emit(hunger_level)
if hunger_level < 0:
hunger_level = 0
end_game(DeathReason.HUNGER)
func inc_hunger(amount):
hunger_level += amount
if hunger_level > MAX_HUNGER:
hunger_level = MAX_HUNGER
hunger_changed.emit(hunger_level)
func _fuel_changed(new_fuel):
if new_fuel == 0 and (season == Game.Season.WINTER or season == Game.Season.FALL):
end_game(DeathReason.FREEZE_FUEL)
func _year_changed(new_year):
match new_year:
COLD_YEARS_START: if house_level < 2: send_notify("Den Winter hab ich so gerade geschafft, ein Haus mit Kamin brauche ich bis zum Herbst auf jeden Fall...")
_: if house_level == 3: win_game()
func _house_changed(new_level):
match new_level:
2: send_notify("Jetzt hab ich einen Kamin, in Herbst und Winter muss ich auf jeden Fall Holz bereit haben")
var summer_info_seen = false
func _season_changed(new_season):
match new_season:
Game.Season.SPRING:
_bump_year()
_check_thunderstorm()
Game.Season.SUMMER:
# Only good weather during summer
thunderstorm = false
if not summer_info_seen:
send_notify("Wahnsinn wie heiß es hier im Sommer ist, da muss ich dran denken immer genug zu trinken")
summer_info_seen = true
Game.Season.WINTER:
if house_level < 1:
end_game(DeathReason.FREEZE_HOUSE)
if year >= COLD_YEARS_START and fuel_left == 0:
end_game(DeathReason.FREEZE_FUEL)
_check_thunderstorm()
Game.Season.FALL:
if house_level < 1:
send_notify("Ich glaube der Winter wird kalt...")
if year >= COLD_YEARS_START and fuel_left == 0:
end_game(DeathReason.FREEZE_FUEL)
_check_thunderstorm()
func _check_thunderstorm():
if randf_range(0, 1) < THUNDERSTORM_CHANCE:
thunderstorm = true
else:
thunderstorm = false
func set_season(s):
if season != s:
season = s
season_changed.emit(season)
func get_item_name(item):
match item:
Items.WOOD: return "Holz"
Items.STONE: return "Steine"
Items.FOOD: return "Essen"
Items.IRON: return "Eisen"
_: return "Unknown"
func get_item_count(item):
return Inventory[item]
func has_item(item, amount):
return Inventory[item] >= amount
# Takes dictionary of items and amounts
func has_items(req_items):
for item in req_items:
if not has_item(item, req_items[item]):
return false
return true
func inc_item(item, amount = 1):
Inventory[item] += amount
inventory_updated.emit(Inventory)
func dec_item(item, amount = 1):
if Inventory[item] >= amount:
Inventory[item] -= amount
inventory_updated.emit(Inventory)
# Takes dictionary of items and amounts
func dec_items(req_items):
for item in req_items:
var amount = req_items[item]
if Inventory[item] >= amount:
Inventory[item] -= amount
inventory_updated.emit(Inventory)
func add_fuel(amount):
fuel_left += amount
fuel_changed.emit(fuel_left)
func burn_fuel():
if fuel_left > 0:
fuel_left -= 1
fuel_changed.emit(fuel_left)
func use_tool():
if tools_unlocked and tools > 0:
tools -= 1
tools_changed.emit(tools)
return true
return false
func add_tools():
tools += TOOLS_AMOUNT
if tools > MAX_TOOLS:
tools = MAX_TOOLS
tools_changed.emit(tools)
func unlock_tools():
tools_unlocked = true
tools_changed.emit(tools)
func send_notify(text):
notify.emit(text)
func _bump_year():
year += 1
year_changed.emit(year)
func _bump_house():
house_level += 1
house_changed.emit(house_level)
func win_game():
get_tree().change_scene_to_file("res://win.tscn")
func end_game(reason):
death_by = reason
get_tree().change_scene_to_file("res://end.tscn")