-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.lua
160 lines (121 loc) · 4.71 KB
/
play.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
local composer = require( "composer" )
local scene = composer.newScene()
local widget = require("widget")
local lm = require("ogt_levelmanager")
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------
-- local forward references should go here
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local screenLeft = display.safeScreenOriginX
local screenWidth = display.viewableContentWidth -- screenLeft * 2
local screenRight = screenLeft + screenWidth
local screenTop = display.screenOriginY
local screenHeight = display.viewableContentHeight - screenTop * 2
local screenBottom = screenTop + screenHeight
print (screenLeft)
print (screenWidth)
local title
local slider
local scoreText
local function backToLevels(event)
composer.gotoScene ( "chooselevel", {effect="fade"} )
return true
end
local function numStarsTapped(event)
local numStars = event.target.numStars
lm.updateStars(numStars)
lm.updateScore(tonumber(scoreText.text))
if numStars > 0 then
lm.unlockNextLevel()
end
backToLevels(event)
return true
end
local function sliderListener(event)
scoreText.text = event.value * 10
return true
end
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
local eforest02 = display.newImage( "images/eforest02.jpg" )
eforest02.width = 1024
eforest02.height = 768
eforest02.x = centerX
eforest02.y = centerY
sceneGroup:insert( eforest02 )
title = display.newEmbossedText( sceneGroup, "Level 0", centerX, 40, "Helvetica", 68 )
local stars = display.newEmbossedText( sceneGroup, "How Many Stars Did You Earn?", centerX, 100, "Helvetica", 32 )
local zero = display.newText( sceneGroup, "0", screenWidth/5 * 1, 180, "Helvetica", 44 )
zero.numStars = 0
zero:addEventListener("tap", numStarsTapped)
local one = display.newText( sceneGroup, "1", screenWidth/5 * 2, 180, "Helvetica", 44 )
one.numStars = 1
one:addEventListener("tap", numStarsTapped)
local two = display.newText( sceneGroup, "2", screenWidth/5 * 3, 180, "Helvetica", 44 )
two.numStars = 2
two:addEventListener("tap", numStarsTapped)
local three = display.newText( sceneGroup, "3", screenWidth/5 * 4, 180, "Helvetica", 44 )
three.numStars = 3
three:addEventListener("tap", numStarsTapped)
-- Create a slider widget
slider = widget.newSlider ({
left = 150,
top = 250,
width = 200,
height = 200,
value = 0,
orientation = "horizontal",
listener = sliderListener
})
sceneGroup:insert(slider)
local score = display.newText( sceneGroup, "Score:", slider.x-90, slider.y, "Helvetica", 40 )
scoreText = display.newText( sceneGroup, "0", slider.x+slider.width+40, slider.y, "Helvetica", 40 )
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen).
title.text = "Level " .. lm.currentLevel
slider:setValue(lm.getLevelScore()/10)
scoreText.text = lm.getLevelScore()
elseif ( phase == "did" ) then
-- Called when the scene is now on screen.
-- Insert code here to make the scene come alive.
-- Example: start timers, begin animation, play audio, etc.
composer.removeScene( "chooselevel" )
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen).
-- Insert code here to "pause" the scene.
-- Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == "did" ) then
-- Called immediately after scene goes off screen.
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's view ("sceneGroup").
-- Insert code here to clean up the scene.
-- Example: remove display objects, save state, etc.
end
-- -------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -------------------------------------------------------------------------------
return scene