-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchicagoCutlass.lua
executable file
·290 lines (243 loc) · 9.73 KB
/
chicagoCutlass.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
----------------------------------
-- THE BIG 3 VIDEO GAME ---
-- [email protected] ---
----------------------------------
-- Script controls the behavior of the car (and resulting smog)
-- for the Chicago endless runner level
local cutlass = {
putterSound = nil
}
local function update(mainScene, car, frontTire, frontHubcap, rearTire, rearHubcap, tailpipe, smog, mask)
local x,y = mainScene.city.displayGroup:contentToLocal( mainScene.rightEdge, mainScene.foldY )
local x2,y2 = mainScene.city.displayGroup:contentToLocal( mainScene.leftEdge, mainScene.foldY )
if( not car.bInitialized ) then
local x,y = mainScene.city.displayGroup:contentToLocal( mainScene.rightEdge, mainScene.foldY )
car.x = x + car.width
frontTire.x = car.x - 69
frontHubcap.x = frontTire.x
rearTire.x = car.x + 55
rearHubcap.x = rearTire.x
if( table.getn( mainScene.obstacles.activeObstacleGroups ) <= 1 ) then
local putterSound = mainScene.sound:load( "cutlass.wav", true )
mainScene.sound:play( putterSound, true, true )
local dispose = function()
audio.dispose( putterSound )
putterSound = nil
end
timer.performWithDelay( 4000, dispose )
car.bInitialized = true
smog.isVisible = true
end
return
end
local speed = ( 4 * ( 60 / display.fps ) )
if( car.x and not car.bCollidedWithPlayer ) then
car.x = car.x - speed
tailpipe.x = car.x + 150
tailpipe.y = car.y - 110
end
if( frontTire.x ) then
if( not frontTire.bCollidedWithPlayer ) then
frontTire.x = frontTire.x - speed
if( frontHubcap ) then
frontHubcap.x = frontTire.x
frontHubcap.rotation = frontHubcap.rotation - 20
end
else
if( frontHubcap ) then
frontHubcap.x = frontTire.x
frontHubcap.y = frontTire.y
frontHubcap.rotation = frontTire.rotation
end
end
end
if( rearTire.x ) then
if( not rearTire.bCollidedWithPlayer ) then
rearTire.x = rearTire.x - speed
if( rearHubcap ) then
rearHubcap.x = rearTire.x
rearHubcap.rotation = rearHubcap.rotation - 20
end
else
if( rearHubcap ) then
rearHubcap.x = rearTire.x
rearHubcap.y = rearTire.y
rearHubcap.rotation = rearTire.rotation
end
end
end
if( smog.maskX ) then
smog.maskX = smog.maskX + speed
if( smog.maskX > 100 ) then
smog:setMask( nil )
mask = nil
end
end
if ( tailpipe.x ) then
mainScene.bSmoggy = true
if( tailpipe.x <= x ) then
elseif( tailpipe.x < x2 ) then
tailpipe:removeSelf()
tailpipe = nil
end
end
if( not smog.fadeTime ) then
smog.fadeTime = system.getTimer() + 7000
smog.counter = 0
end
if( mainScene.bRemoveSmog ) then -- If Mole is blowing the smog away
smog.alpha = smog.alpha - ( 0.0125 * ( 60 / display.fps ) )
if( tailpipe.x ) then -- Force removal of tailpipe
tailpipe.x = -1000
end
end
if( system.getTimer() >= smog.fadeTime ) then
smog.counter = smog.counter + 1
if( smog.counter > 5 ) then
smog.counter = 0
smog.alpha = smog.alpha - ( 0.001 * ( 60 / display.fps ) )
end
if( smog.alpha <= 0.35 ) then
mainScene.bSmoggy = false
end
if( smog.alpha <= 0 ) then
smog:removeSelf()
smog = nil
end
end
end
function cutlass:spawn(scene)
mainScene = scene
mainScene.bSmoggy = false
mainScene.bRemoveSmog = false
local obstacleGroup = {}
obstacleGroup.name = "cutlass"
obstacleGroup.bodies = {}
display.setDefault( "magTextureFilter", "nearest" )
display.setDefault( "minTextureFilter", "nearest" )
local car = display.newImageRect( "images/cutlass.png", 219, 51 )
car.bPerciseCollisionDetection = true
car.doObstacleCollisionCheck = true
local x,y = mainScene.city.displayGroup:contentToLocal( mainScene.rightEdge, mainScene.foldY )
car.x = x + car.width
car.y = mainScene.groundY - 40
mainScene.city.displayGroup:insert( car )
car.xChoke = 5
car.yChoke = 5
car.id = "cutless"
car.isAwake = true
car.bTestForCollision = true
car.bEnableAutoSpawn = false
car.explosionScale = 2
local frontTire = display.newImageRect( "images/tire.png", 30, 29 )
mainScene.city.displayGroup:insert( frontTire )
frontTire.x = car.x - 69
frontTire.y = mainScene.groundY - 17
frontTire.isAwake = true
frontTire.bTestForCollision = true
frontTire.linearX = 10
frontTire.angle = 80
local frontHubcap = display.newImageRect( "images/hubcap.png", 16, 16 )
mainScene.city.displayGroup:insert( frontHubcap )
frontHubcap.x = frontTire.x
frontHubcap.y = frontTire.y
local rearTire = display.newImageRect( "images/tire.png", 30, 29 )
mainScene.city.displayGroup:insert( rearTire )
rearTire.x = car.x + 55
rearTire.y = frontTire.y
rearTire.isAwake = true
rearTire.bTestForCollision = true
rearTire.linearX = 30
rearTire.angle = 90
local rearHubcap = display.newImageRect( "images/hubcap.png", 16, 16 )
mainScene.city.displayGroup:insert( rearHubcap )
rearHubcap.x = rearTire.x
rearHubcap.y = rearTire.y
--local tailpipeSheet = graphics.newImageSheet( "images/smogTailpipeAnim.gif", { width=100, height=185, numFrames=72 } )
--local tailpipe = display.newSprite( tailpipeSheet, {{ name = "loop", start=1, count=72, time=2000, loopCount=0 }} )
tailpipe = display.newImageRect( "images/basketball.png", 100, 185 )
tailpipe.anchorX = 0.5
tailpipe.anchorY = 0.5
tailpipe.blendMode = "screen"
tailpipe.xScale = 1.5
tailpipe.yScale = 1.5
--tailpipe.alpha = 0.95
tailpipe.alpha = 0.001
mainScene.city.displayGroup:insert( tailpipe )
local smogSheet = graphics.newImageSheet( "images/smogAnim.gif", { width=240, height=135, numFrames=23 } )
local smog = display.newSprite( smogSheet, {{ name = "loop", start=1, count=23, time=1100, loopCount=0 }} )
smog.anchorX = 0.5
smog.anchorY = 0.5
smog.x = display.contentCenterX
smog.y = display.contentCenterY
smog.blendMode = "screen"
smog.xScale = display.actualContentWidth / smog.width * -1
smog.yScale = display.actualContentHeight / smog.height
smog.width = smog.width + 8
smog.height = smog.height + 8
smog.alpha = 1
smog:play()
smog.isVisible = false
mainScene.effectsGroup:insert( smog )
local mask = graphics.newMask( "images/smogMask.png" )
smog:setMask( mask )
smog.maskX = -620
smog.maskScaleY = 1.2
display.setDefault( "magTextureFilter", "linear" )
display.setDefault( "minTextureFilter", "linear" )
local loop = function()
if( not mainScene or not smog.x or mainScene.bGameOver ) then
Runtime:removeEventListener( "enterFrame", loop )
return
end
update(mainScene, car, frontTire, frontHubcap, rearTire, rearHubcap, tailpipe, smog, mask)
end
Runtime:addEventListener( "enterFrame", loop )
car.linearX = 140 + math.random( 30 )
car.angle = 90
local impactSound = mainScene.sound:load( "carcrash.wav", true )
if( mainScene:getSelectedCharacter() == "don" ) then
local donCough = mainScene.sound:loadVoice( "voice-donCough.wav" )
mainScene.sound:playVoice( donCough, 2 )
end
car.onInitialImpact = function()
mainScene.sound:play( impactSound, true, true )
local dispose = function()
if( impactSound ) then
audio.dispose( impactSound )
impactSound = nil
end
end
timer.performWithDelay( 4000, dispose )
local achievement = "CgkIhf7UyIMOEAIQBw"
if ( system.getInfo("platformName") == "iPhone OS" ) then
achievement = "fakeDisability"
end
gameNetwork.request( "unlockAchievement", { achievement = { identifier=achievement, percentComplete=100, showsCompletionBanner=true } } )
local d = 1.1
local f = 0.1
local b = 0.2
car.bCollided = true
frontHubcap:removeSelf()
rearHubcap:removeSelf()
frontHubcap = nil
rearHubcap = nil
mainScene.obstacles:addMisc( car )
mainScene.obstacles:addMisc( frontTire )
mainScene.obstacles:addMisc( rearTire )
physics.addBody( car, "dynamic",
{ density=d, friction=f, bounce=b, shape = { -105.5, -3.5 , -71.5, 8.5 , -85.5, 20.5 , -104.5, 21.5 } },
{ density=d, friction=f, bounce=b, shape = { 71.5, 19.5 , 54.5, 8.5 , 29.5, -24.5 , 100.5, -1.5 , 108.5, 15.5 } },
{ density=d, friction=f, bounce=b, shape = { -36.5, -10.5 , -71.5, 8.5 , -105.5, -3.5 } },
{ density=d, friction=f, bounce=b, shape = { -36.5, -10.5 , 37.5, 22.5 , -52.5, 22.5 , -71.5, 8.5 } },
{ density=d, friction=f, bounce=b, shape = { -14.5, -23.5 , 29.5, -24.5 , 54.5, 8.5 , 37.5, 22.5 , -36.5, -10.5 } }
)
physics.addBody( rearTire, { density = 0.4, friction = 0.2, bounce = 0.9, radius = 15 } )
physics.addBody( frontTire, { density = 0.4, friction = 0.2, bounce = 0.9, radius = 15 } )
end
table.insert( obstacleGroup.bodies, car )
table.insert( obstacleGroup.bodies, frontTire )
table.insert( obstacleGroup.bodies, rearTire )
return obstacleGroup
end
return cutlass