-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIdleScene.lua
More file actions
262 lines (216 loc) · 11.4 KB
/
IdleScene.lua
File metadata and controls
262 lines (216 loc) · 11.4 KB
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
local composer = require( "composer" )
require('database')
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
--id, lastAddTime, allPerSec, parkPerSec, naturePerSec, trailPerSec, touristPerSec, graveyardPerSec, allTotal, parkTotal, natureTotal, trailTotal, touristTotal, graveyardTotal, wins
currentValues = {}
--placeholders for UI elements
local emptyLabel = ''
local parkLabel = ''
local natureReserveLabel = ''
local trailLabel = ''
local tourismLabel = ''
local graveyardLabel = ''
local buyParkLabel = ''
local buyNatureReserverLabel = ''
local buyTrailLabel = ''
local buyTourismLabel = ''
local buyGraveyardLabel = ''
local buyWinLabel = ''
local function GetAllValues()
local sql = 'SELECT * FROM IdleStats'
currentValues = Query(sql)[1]
end
local function GoToSceneSelect()
local options = {effect = "flip", time = 125}
composer.gotoScene("SceneSelect", options)
end
local function GetUpgradeCost(currentCount)
return math.modf(currentCount ^ 2.1 + 1)
end
local function updateTotals()
GetAllValues()
--add per second values for each second that's passed since the last check
local timeCheck = os.time()
local timeShift = (timeCheck - currentValues[2])
sql = "UPDATE IdleStats SET allTotal = allTotal + " .. (currentValues[3] * timeShift) .. ", "
sql = sql .. "parkTotal = parkTotal + " .. (currentValues[4] * timeShift) .. ", "
sql = sql .. "natureTotal = natureTotal + " .. (currentValues[5] * timeShift) .. ", "
sql = sql .. "trailTotal = trailTotal + " .. (currentValues[6] * timeShift) .. ", "
sql = sql .. "touristTotal = touristTotal + " .. (currentValues[7] * timeShift) .. ", "
sql = sql .. "graveyardTotal = graveyardTotal + " .. (currentValues[8] * timeShift) .. ", "
sql = sql .. "lastAddTime = " .. timeCheck
Exec(sql)
updateText()
end
function updateText()
GetAllValues()
emptyLabel.text = "All Points: " .. math.modf(currentValues[9])
parkLabel.text = "Park Points: " .. math.modf(currentValues[10])
natureReserveLabel.text = "Nature Reserve Points: " .. math.modf(currentValues[11])
trailLabel.text ="Trail Points: " .. math.modf(currentValues[12])
tourismLabel.text = "Tourism Points: " .. math.modf(currentValues[13])
graveyardLabel.text ="Graveyard Points: " .. math.modf(currentValues[14])
buyParkLabel.text = "Buy " .. (currentValues[4] + 1) .. " Park points per second for " .. GetUpgradeCost(currentValues[4]) .. ' All points'
buyNatureReserverLabel.text = "Buy " .. (currentValues[5] + 1) .. " Nature Reserve points per second for " .. GetUpgradeCost(currentValues[5]) .. ' Park points'
buyTrailLabel.text ="Buy " .. (currentValues[6] + 1) .. " Trail points per second for " .. GetUpgradeCost(currentValues[6]) .. ' Nature Reserve points'
buyTourismLabel.text = "Buy " .. (currentValues[7] + 1) .. " Tourism points per second for " .. GetUpgradeCost(currentValues[7]) .. ' Trail points'
buyGraveyardLabel.text ="Buy " .. (currentValues[8] + 1) .. " Graveyard points per second for " .. GetUpgradeCost(currentValues[8]) .. ' Tourism points'
buyWinLabel.text = "Confirm your victory with " .. (1000000 * (10 ^ currentValues[15])) .. " of each terrain type"
end
local function WinIdle()
--Should do some fancy effects to indicate victory has been acheived
--sound, particles, screen filters?
--first, check if the player actually won
--currentvalues needs all 6 totals over 1 million.
--its 86k per day if you have 1 per second of each type.
--so its 12 days to win if you get 1 of each space for the first time
local totalRequired = 1000000 * (10 ^ currentValues[15])
if (currentValues[9] > totalRequired and currentValues[10] > totalRequired and currentValues[11] > totalRequired and currentValues[12] > totalRequired and currentValues[13] > totalRequired and currentValues[14] > totalRequired) then
--VICTORY.
--TODO: flashy effects
local sql = "UPDATE IdleStats SET wins = wins + 1, allPerSec = 0, parkPerSec = 0, naturePerSec = 0, trailPerSec = 0, touristPerSec = 0, graveyardPerSec = 0, allTotal = 0, parkTotal = 0, natureTotal = 0, trailTotal = 0, touristTotal = 0, graveyardTotal = 0"
Exec(sql)
GetAllValues()
else
native.showAlert("Not Yet...", "You do not yet have enough points in all terrain types to ascend.")
end
end
local function buyPark()
local cost = GetUpgradeCost(currentValues[4])
if (currentValues[9] > cost) then
local sql = "UPDATE IdleStats SET parkPerSec = parkPerSec + 1, allTotal = " .. (currentValues[9] - cost)
Exec(sql)
updateText()
end
end
local function buyNatureReserve()
local cost = GetUpgradeCost(currentValues[5])
if (currentValues[10] > cost) then
local sql = "UPDATE IdleStats SET naturePerSec = naturePerSec + 1, parkTotal = " .. (currentValues[10] - cost)
Exec(sql)
updateText()
end
end
local function buyTrail()
local cost = GetUpgradeCost(currentValues[6])
if (currentValues[11] > cost) then
local sql = "UPDATE IdleStats SET trailPerSec = trailPerSec + 1, natureTotal = " .. (currentValues[11] - cost)
Exec(sql)
updateText()
end
end
local function buyTourism()
local cost = GetUpgradeCost(currentValues[7])
if (currentValues[12] > cost) then
local sql = "UPDATE IdleStats SET touristPerSec = touristPerSec + 1, trailTotal = " .. (currentValues[12] - cost)
Exec(sql)
updateText()
end
end
local function buyGraveyard()
local cost = GetUpgradeCost(currentValues[8])
if (currentValues[13] > cost) then
local sql = "UPDATE IdleStats SET graveyardPerSec = graveyardPerSec + 1, touristTotal = " .. (currentValues[13] - cost)
Exec(sql)
updateText()
end
end
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
header = display.newImageRect(sceneGroup, "themables/idleGame.png", 300, 100)
header.x = display.contentCenterX
header.y = 80
header:addEventListener("tap", GoToSceneSelect)
header:toFront()
-- 6 types of space tracked
-- empty, park, nature reserve, trail, graveyard, tourism
emptyLabel = display.newText(sceneGroup, "All Points: ", display.contentCenterX, 160, native.systemFont, 20)
parkLabel = display.newText(sceneGroup, "Park Points: ", display.contentCenterX, 320, native.systemFont, 20)
natureReserveLabel = display.newText(sceneGroup, "Nature Reserve Points: ", display.contentCenterX, 480, native.systemFont, 20)
trailLabel = display.newText(sceneGroup, "Trail Points: ", display.contentCenterX, 640, native.systemFont, 20)
tourismLabel = display.newText(sceneGroup, "Tourism Points: ", display.contentCenterX, 800, native.systemFont, 20)
graveyardLabel = display.newText(sceneGroup, "Graveyard Points: ", display.contentCenterX, 960, native.systemFont, 20)
--Need buttons and labels to buy types with other types
--purchasing order
--Anywhere will get you to a park
--parks level up to nature reservers
--nature reserves are full of trails
--travelling on trails makes you a tourist
--all travels have the same final destination
buyParkLabel = display.newText(sceneGroup, "Buy 1 Park per second for ", display.contentCenterX, 340, native.systemFont, 20)
buyNatureReserverLabel = display.newText(sceneGroup, "Buy 1 Nature Reserve per second for ", display.contentCenterX, 500, native.systemFont, 20)
buyTrailLabel = display.newText(sceneGroup, "Buy 1 Trail per second for ", display.contentCenterX, 660, native.systemFont, 20)
buyTourismLabel = display.newText(sceneGroup, "Buy 1 tourism per second for ", display.contentCenterX, 820, native.systemFont, 20)
buyGraveyardLabel = display.newText(sceneGroup, "Buy 1 Graveyard per second for ", display.contentCenterX, 980, native.systemFont, 20)
--buttons for buying
buyParkImg = display.newImageRect(sceneGroup, "themables/idlePark.png", 300, 100)
buyParkImg.x = display.contentCenterX
buyParkImg.y = 240
buyParkImg:addEventListener("tap", buyPark)
buyNatResImg = display.newImageRect(sceneGroup, "themables/idleNatRes.png", 300, 100)
buyNatResImg.x = display.contentCenterX
buyNatResImg.y = 400
buyNatResImg:addEventListener("tap", buyNatureReserve)
buyTrailImg = display.newImageRect(sceneGroup, "themables/idleTrail.png", 300, 100)
buyTrailImg.x = display.contentCenterX
buyTrailImg.y = 560
buyTrailImg:addEventListener("tap", buyTrail)
buyTourismImg = display.newImageRect(sceneGroup, "themables/idleTourism.png", 300, 100)
buyTourismImg.x = display.contentCenterX
buyTourismImg.y = 740
buyTourismImg:addEventListener("tap", buyTourism)
buyGraveyardImg = display.newImageRect(sceneGroup, "themables/idleGraveyard.png", 300, 100)
buyGraveyardImg.x = display.contentCenterX
buyGraveyardImg.y = 880
buyGraveyardImg:addEventListener("tap", buyGraveyard)
buyWinLabel = display.newText(sceneGroup, "Confirm your victory with 1,000,000 of each terrain type", display.contentCenterX, 1080, native.systemFont, 20)
local buyWinButton = display.newImageRect(sceneGroup, "themables/idleWin.png", 300, 100)
buyWinButton.x = display.contentCenterX
buyWinButton.y = 1150
buyWinButton:addEventListener("tap", WinIdle)
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
print("starting idle game")
timer.performWithDelay(1000, updateTotals, -1)
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
-- hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
end
end
-- destroy()
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene