-
Notifications
You must be signed in to change notification settings - Fork 0
/
stasis.lua
70 lines (55 loc) · 1.88 KB
/
stasis.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
-----------------------------------------------------------------------------------------
--
-- stasis.lua
--
-- The stasis activity for the Mars app.
-- The user is forced to wait while water is generated.
-----------------------------------------------------------------------------------------
-- Get local reference to the game globals
local game = globalGame
-- Load Corona modules
local widget = require( "widget" )
-- Create the act object
local act = game.newAct()
-- File local variables
local progressBar -- the progress bar widget
local waterGoal = 20 -- goal for water generation (liters)
-- Init the act
function act:init()
-- background image
local bg = act:newImage( "background.jpg", { width = act.width } )
-- make a white box around progress bar to make it easier to see
local progressBox = display.newRect( act.group, act.xCenter, act.yMax - 110, 250, 40 )
progressBox.alpha = 0.7
-- The progress bar
progressBar = widget.newProgressView{
x = act.xCenter,
y = act.yMax - 100,
width = act.width * 0.75,
}
act.group:insert( progressBar )
-- Progress bar label
display.newText( act.group, "Water generation progress:", act.xCenter, progressBar.y - 20,
native.systemFont, 16 ):setFillColor( 0 )
end
-- Prepare the act
function act:prepare()
-- Make sure we are starting with 0 water
game.addWater( -game.water() )
progressBar:setProgress( 0 )
end
-- Handle enterFrame events
function act:enterFrame()
-- Add a little water
game.addWater( 0.1 ) -- TODO: make slower
progressBar:setProgress( game.water() / waterGoal )
-- Automatically exit when we reach the goal
if game.water() >= waterGoal then
game.saveState.stasis = false
game.updateState()
game.sendMessage( "regenerated", 2000 )
game.gotoAct( "mainAct", { effect = "slideRight", time = 500 } )
end
end
-- Corona needs the scene object returned from the act file
return act.scene