-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
402 lines (373 loc) · 14.3 KB
/
main.lua
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
require "TEsound"
require "Money"
local anim = require"anim"
local JSON = require "JSON"
--Initialize save file components
aa=love.filesystem.createDirectory("../KJS")
contents, size = love.filesystem.read("save.sav",5000)
money = Money:new({balance = 0})
--Initialize animation components
local grandma_anims = {}
local tv_anims = {}
local can_anims = {}
local industry_anims = {}
local global_anims = {}
local ocean_anims = {}
local satellite_anims = {}
--Default item values
init_grandmotherPrice=30
init_junkyardPrice=100000
init_usedcollectorPrice=1000
init_apartmentPrice=45000
init_factoryPrice=100000
init_importPrice=3000000
init_oceanPrice=100000000
init_spacePrice=1800000000
--Data loading source
if type(size)=='number' then
print("load successful!")
loadData=JSON:decode(contents)
reset_bonus=loadData['reset_bonus']
print(loadData['money']['balance'])
money:set(14574534464756)
grandmother=loadData['grandmother']
grandmotherPrice=loadData['grandmotherPrice']
earning=tonumber(loadData['earning'])
junkyardScale=loadData['junkyardScale']
junkyardPrice=loadData['junkyardPrice']
usedcollector=loadData['usedcollector']
usedcollectorPrice=loadData['usedcollectorPrice']
apartment=loadData['apartment']
apartmentPrice=loadData['apartmentPrice']
factory=loadData['factory']
factoryPrice=loadData['factoryPrice']
import=loadData['import']
importPrice=loadData['importPrice']
ocean=loadData['ocean']
oceanPrice=loadData['oceanPrice']
space=loadData['space']
spacePrice=loadData['spacePrice']
--[[
grandma_anims = loadData['grandma_anims']
tv_anims = loadData['tv_anims']
can_anims = loadData['can_anims']
industry_anims = loadData['industry_anims']
global_anims = loadData['global_anims']
ocean_anims = loadData['ocean_anims']
satellite_anims = loadData['satellite_anims']
]]--
else
print("load failed!")
reset_bonus=0
grandmother=0
init_grandmotherPrice=30
grandmotherPrice=init_grandmotherPrice
earning=1
junkyardScale=0
junkyardPrice=init_junkyardPrice
usedcollector=0
usedcollectorPrice=init_usedcollectorPrice
apartment=0
apartmentPrice=init_apartmentPrice
factory=0
factoryPrice=init_factoryPrice
import=0
importPrice=init_importPrice
ocean=0
oceanPrice=init_oceanPrice
space=0
spacePrice=init_spacePrice
end
toggleBGM=true
--Load game resources
function love.load()
TEsound.playLooping("resource/bgm/bgm.mp3", "bgm")
bgmOn = love.graphics.newImage("resource/image/bgm_on.png")
bgmOff = love.graphics.newImage("resource/image/bgm_off.png")
trash = love.graphics.newImage("resource/image/trash1.png")
title = love.graphics.newImage("resource/image/title.png")
btn_save = love.graphics.newImage("resource/image/save.png")
btn_reset = love.graphics.newImage("resource/image/reset.png")
moneyImg=love.graphics.newImage("/resource/image/money_image.png")
grandma1=love.graphics.newImage("/resource/image/grandma1.png")
grandma2=love.graphics.newImage("/resource/image/grandma2.png")
tv1=love.graphics.newImage("/resource/image/tv1.png")
tv2=love.graphics.newImage("/resource/image/tv2.png")
can1=love.graphics.newImage("/resource/image/can1.png")
can2=love.graphics.newImage("/resource/image/can2.png")
industry1=love.graphics.newImage("/resource/image/industry1.png")
industry2=love.graphics.newImage("/resource/image/industry2.png")
global1=love.graphics.newImage("/resource/image/global1.png")
global2=love.graphics.newImage("/resource/image/global2.png")
ocean1=love.graphics.newImage("/resource/image/ocean1.png")
ocean2=love.graphics.newImage("/resource/image/ocean2.png")
satellite1=love.graphics.newImage("/resource/image/satellite1.png")
satellite2=love.graphics.newImage("/resource/image/satellite2.png")
love.graphics.setBackgroundColor(0,0,0)
love.graphics.setNewFont("/resource/font/SeoulHangangB.ttf",20)
end
--Drawing game resources
function love.draw()
--Drawing BGM toggles
if toggleBGM then
love.graphics.draw(bgmOn,750,10)
else
love.graphics.draw(bgmOff,750,10)
end
--Drawing buttons
love.graphics.draw(title,105,10)
love.graphics.draw(moneyImg,75,425)
love.graphics.draw(trash,75,125)
love.graphics.print(math.floor(money:get()),135,437)
love.graphics.draw(btn_save,100,500)
love.graphics.draw(btn_reset,100,550)
love.graphics.print("고물상 크기: "..junkyardScale,400,125)
love.graphics.print("₩ "..math.pow(10,junkyardScale+5),400,150)
love.graphics.print("폐지줍는 할머니: "..grandmother,600,125)
love.graphics.print("₩ "..math.floor(grandmotherPrice),600,150)
love.graphics.print("안쓰는 가전 삽니다: "..usedcollector,400,190)
love.graphics.print("₩ "..math.floor(usedcollectorPrice),400,215)
love.graphics.print("아파트 폐품 수거: "..apartment,600,190)
love.graphics.print("₩ "..math.floor(apartmentPrice),600,215)
love.graphics.print("공업단지 고철 수거: "..factory,400,255)
love.graphics.print("₩ "..math.floor(factoryPrice),400,280)
love.graphics.print("해외 고철 수입: "..import,600,255)
love.graphics.print("₩ "..math.floor(importPrice),600,280)
love.graphics.print("해양 쓰레기 수거: "..ocean,400,320)
love.graphics.print("₩ "..math.floor(oceanPrice),400,345)
love.graphics.print("우주 쓰레기 수거: "..space,600,320)
love.graphics.print("₩ "..math.floor(spacePrice),600,345)
--Drawing animations
for key,value in pairs(grandma_anims) do
grandma_anims[key]:draw(400,584)
end
for key,value in pairs(tv_anims) do
tv_anims[key]:draw(400,584)
end
for key,value in pairs(can_anims) do
can_anims[key]:draw(400,584)
end
for key,value in pairs(industry_anims) do
industry_anims[key]:draw(400,584)
end
for key,value in pairs(global_anims) do
global_anims[key]:draw(400,584)
end
for key,value in pairs(ocean_anims) do
ocean_anims[key]:draw(400,584)
end
for key,value in pairs(satellite_anims) do
satellite_anims[key]:draw(400,584)
end
end
--Mouse press actions
function love.mousepressed(x, y, button, istouch)
--BGM toggles
if button == 1 then
if x >= 750 and x <= 790 and y >= 10 and y <= 50 and toggleBGM then
toggleBGM=false
TEsound.stop("bgm")
elseif x >= 750 and x <= 790 and y >= 10 and y <= 50 and not toggleBGM then
toggleBGM=true
TEsound.playLooping("resource/bgm/bgm.mp3", "bgm")
end
--Junkyard scale item part
if x>=400 and x<=520 and y>=125 and y<=170 and money:get()>=junkyardPrice and junkyardScale < 5 then
money:set(money:get() - junkyardPrice)
earning=earning*1.5
junkyardScale=junkyardScale+1
junkyardPrice=math.pow(10,junkyardScale+5)
end
--Grandma item part
if x>=600 and x<=750 and y>=125 and y<=170 and money:get()>=grandmotherPrice then
money:set(money:get() - grandmotherPrice)
earning=earning+10
grandmotherPrice=grandmotherPrice*1.1
grandmother=grandmother+1
grandma_anim = anim.newAnimation(0.1,true,grandma1,grandma2)
table.insert(grandma_anims,grandma_anim)
end
--Usedcollector item part
if x>=400 and x<=570 and y>=190 and y<=235 and money:get()>=usedcollectorPrice then
money:set(money:get() - usedcollectorPrice)
earning=earning+200
usedcollectorPrice=usedcollectorPrice*1.1
usedcollector=usedcollector+1
tv_anim = anim.newAnimation(0.1,true,tv1,tv2)
table.insert(tv_anims,tv_anim)
end
--Apartment item part
if x>=600 and x<=760 and y>=190 and y<=235 and money:get()>=apartmentPrice then
money:set(money:get() - apartmentPrice)
earning = earning + 9000
apartmentPrice = apartmentPrice * 1.1
apartment = apartment + 1
can_anim = anim.newAnimation(0.1,true,can1,can2)
table.insert(can_anims,can_anim)
end
--Factory item part
if x>=400 and x<=570 and y>=255 and y<=300 and money:get()>=factoryPrice then
money:set(money:get() - factoryPrice)
earning = earning + 20000
factoryPrice = factoryPrice * 1.1
factory = factory + 1
industry_anim = anim.newAnimation(0.1,true,industry1,industry2)
table.insert(industry_anims,industry_anim)
end
--Import item part
if x>=600 and x<=735 and y>=255 and y<=300 and money:get()>=importPrice then
money:set(money:get() - importPrice)
earning = earning + 600000
importPrice = importPrice * 1.1
import = import + 1
global_anim = anim.newAnimation(0.1,true,global1,global2)
table.insert(global_anims,global_anim)
end
--Ocean item part
if x>=400 and x<=550 and y>=320 and y<=365 and money:get()>=oceanPrice then
money:set(money:get() - oceanPrice)
earning = earning + 20000000
oceanPrice = oceanPrice * 1.1
ocean = ocean + 1
ocean_anim = anim.newAnimation(0.1,true,ocean1,ocean2)
table.insert(ocean_anims,ocean_anim)
end
--Space item part
if x>=600 and x<=760 and y>=320 and y<=365 and money:get()>=spacePrice then
money:set(money:get() - spacePrice)
earning = earning + 360000000
spacePrice = spacePrice * 1.1
space = space + 1
satellite_anim = anim.newAnimation(0.1,true,satellite1,satellite2)
table.insert(satellite_anims,satellite_anim)
end
--Game save part
if x>=100 and x<=200 and y>=500 and y<=530 then
saveData = {}
saveData['reset_bonus']=reset_bonus
saveData['money']=money
saveData['prev_earning']=prev_earning
saveData['earning']=earning
saveData['junkyardScale']=junkyardScale
saveData['junkyardPrice']=junkyardPrice
saveData['grandmother']=grandmother
saveData['grandmotherPrice']=grandmotherPrice
saveData['usedcollector']=usedcollector
saveData['usedcollectorPrice']=usedcollectorPrice
saveData['apartment']=apartment
saveData['apartmentPrice']=apartmentPrice
saveData['factory']=factory
saveData['factoryPrice']=factoryPrice
saveData['import']=import
saveData['importPrice']=importPrice
saveData['ocean']=ocean
saveData['oceanPrice']=oceanPrice
saveData['space']=space
saveData['spacePrice']=spacePrice
--[[
saveData['grandma_anims']=grandma_anims
saveData['tv_anims']=tv_anims
saveData['can_anims']=can_anims
saveData['industry_anims']=industry_anims
saveData['global_anims']=global_anims
saveData['ocean_anims']=ocean_anims
saveData['satellite_anims']=satellite_anims
]]--
saveString = JSON:encode(saveData)
success = love.filesystem.write("save.sav",saveString)
end
--Game reset part
if x>=100 and x<=200 and y>=550 and y<=580 then
reset_bonus=reset_bonus+math.floor(money:get()/10000000000000)
money:set(money:get()-money:get())
prev_earning=earning
earning=1
junkyardScale=0
junkyardPrice=init_junkyardPrice
grandmother=0
grandmotherPrice=init_grandmotherPrice
usedcollector=0
usedcollectorPrice=init_usedcollectorPrice
apartment=0
apartmentPrice=init_apartmentPrice
factory=0
factoryPrice=init_factoryPrice
import=0
importPrice=init_importPrice
ocean=0
oceanPrice=init_oceanPrice
space=0
spacePrice=init_spacePrice
for key,value in pairs(grandma_anims) do
grandma_anims[key]=nil
end
for key,value in pairs(tv_anims) do
tv_anims[key]=nil
end
for key,value in pairs(can_anims) do
can_anims[key]=nil
end
for key,value in pairs(industry_anims) do
industry_anims[key]=nil
end
for key,value in pairs(global_anims) do
global_anims[key]=nil
end
for key,value in pairs(ocean_anims) do
ocean_anims[key]=nil
end
for key,value in pairs(satellite_anims) do
satellite_anims[key]=nil
end
saveData = {}
saveData['reset_bonus']=reset_bonus
saveData['money']=money
saveData['prev_earning']=prev_earning
saveData['earning']=earning
saveData['junkyardScale']=junkyardScale
saveData['junkyardPrice']=junkyardPrice
saveData['grandmother']=grandmother
saveData['grandmotherPrice']=grandmotherPrice
saveData['usedcollector']=usedcollector
saveData['usedcollectorPrice']=usedcollectorPrice
saveData['apartment']=apartment
saveData['apartmentPrice']=apartmentPrice
saveData['factory']=factory
saveData['factoryPrice']=factoryPrice
saveData['import']=import
saveData['importPrice']=importPrice
saveData['ocean']=ocean
saveData['oceanPrice']=oceanPrice
saveData['space']=space
saveData['spacePrice']=spacePrice
saveString = JSON:encode(saveData)
success = love.filesystem.write("save.sav",saveString)
end
end
end
--Update frame at each second
function love.update(dt)
money:set(money:get()+(earning*dt)+(earning*reset_bonus*0.01))
TEsound.cleanup()
for key,value in pairs(grandma_anims) do
grandma_anims[key]:update(dt)
end
for key,value in pairs(tv_anims) do
tv_anims[key]:update(dt)
end
for key,value in pairs(can_anims) do
can_anims[key]:update(dt)
end
for key,value in pairs(industry_anims) do
industry_anims[key]:update(dt)
end
for key,value in pairs(global_anims) do
global_anims[key]:update(dt)
end
for key,value in pairs(ocean_anims) do
ocean_anims[key]:update(dt)
end
for key,value in pairs(satellite_anims) do
satellite_anims[key]:update(dt)
end
end