-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene2.lua
More file actions
214 lines (156 loc) · 5.35 KB
/
Copy pathscene2.lua
File metadata and controls
214 lines (156 loc) · 5.35 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
---------------------------------------------------------------------------------
--
-- scene.lua
--
---------------------------------------------------------------------------------
local sceneName = ...
local composer = require( "composer" )
-- Load scene with same root filename as this file
local scene = composer.newScene( sceneName )
---------------------------------------------------------------------------------
gameTimers = {}
gameTimers.frame = 0
gameTimers.totalTime = 0
gameTimers.spawnTime = 0
gameTimers.gameStarted = false
playerFrog = {}
startPad = {}
pad = {}
spawned= false
local nextSceneButton
function scene:create( event )
local sceneGroup = self.view
-- Called when the scene's view does not exist
--
-- INSERT code here to initialize the scene
-- e.g. add display objects to 'sceneGroup', add touch listeners, etc
gameTimers = {}
gameTimers.frame = 0
gameTimers.totalTime = 0
gameTimers.spawnTime = 0
playerFrog = {}
startPad = {}
terrainObjects = {}
end
local onUpdate = function( event )
-- print ("something")
if gameTimers.gameStarted then
if startPad then
startPad.x = startPad.x -1
-- if startPad.x > -20 then
-- startPad:removeSelf( )
-- startPad= nil
-- end
-- print ("There is a start pad!!!!")
end
if playerFrog.isOnSomething then
playerFrog.x = playerFrog.x - 1
end
gameTimers.frame = gameTimers.frame + 1
gameTimers.spawnTime = gameTimers.spawnTime +1
if pad then
-- print ("There is a pad!")
end
if gameTimers.frame == 31 then
gameTimers.frame= 0
print ("frame 30")
end
-- padsmall.x = 320
-- padsmall.y = 350
if gameTimers.spawnTime == 50 and spawned== false then
print ("makePad")
--numberOfPads = numberOfPads +1
gameTimers.spawnTime =0
spawnPad = padsmall -- display.newImage("images/pad1.png")
spawnPad.x = 330
spawnPad.y = 340
spawned= true
end
if spawned == true then
print ("but hey, spawned =- true!")
-- spawnPad.x = spawnPad.x -1
--spawnPad.y = spawnPad.y +1
spawnPad.x = spawnPad.x -1
if spawnPad.x < -20 then
spawnPad:removeSelf( )
spawnPad = nil
end
end
end
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
-- local goToScene3Btn = self:getObjectByName( "GoToScene3Btn" )''
local touchObject
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers, begin animation, play audio, etc
Runtime:addEventListener( "enterFrame", onUpdate )
playerFrog = self:getObjectByName( "PlayerFrog" )
startPad = self:getObjectByName( "StartPad" )
padsmall = self:getObjectByName("Padsmall")
startPad.myName = "startpad"
padsmall.myName = "padsmall"
local function onLocalCollision( self, event )
if ( event.phase == "began" ) then
print ("Hit started")
gameTimers.gameStarted = true
playerFrog.isOnSomething = true
-- print( self.myName .. ": collision began with " .. event.other.myName )
end
return
end
playerFrog.collision = onLocalCollision
playerFrog:addEventListener( "collision", playerFrog )
padsmall.collision = onLocalCollision
padsmall:addEventListener( "collision", padsmall )
-- padsmall.x = 320
-- padsmall.y = 350
if nextSceneButton then
-- touch listener for the button
function nextSceneButton:touch ( event )
local phase = event.phase
if "ended" == phase then
composer.gotoScene( "scene3", { effect = "fade", time = 300 } )
end
end
-- add the touch event listener to the button
nextSceneButton:addEventListener( "touch", nextSceneButton )
end
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
-- Called when the scene is now off screen
if nextSceneButton then
nextSceneButton:removeEventListener( "touch", nextSceneButton )
end
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
---------------------------------------------------------------------------------
return scene