-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchicagoRandyRanch.lua
More file actions
executable file
·176 lines (148 loc) · 6.05 KB
/
chicagoRandyRanch.lua
File metadata and controls
executable file
·176 lines (148 loc) · 6.05 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
----------------------------------
-- THE BIG 3 VIDEO GAME ---
-- andrew@langleycreations.com ---
----------------------------------
-- Script controls the randy ranch behaviors and properties
-- for the Chicago endless runner level
local randyRanch = {
bPlayedVoice = false
}
local function update(mainScene,topDrop,midDrop,bottomDrop,self)
if( topDrop.x ) then
local x,y = mainScene.city.displayGroup:localToContent( topDrop.x, topDrop.y )
if( x <= mainScene.rightEdge - (math.random( 20 ) + 10) and not topDrop.bPlayedAnim ) then
topDrop.bPlayedAnim = true
bottomDrop.isVisible = false
topDrop:play()
local dropSound = mainScene.sound:loadDamageSound( "drop.wav" )
mainScene.sound:playDamageSound( dropSound )
local function mySpriteListener( event )
if ( event.phase == "ended" ) then
topDrop:removeEventListener( "sprite", mySpriteListener )
midDrop.isVisible = true
midDrop.counter = 0
end
end
topDrop:addEventListener( "sprite", mySpriteListener )
end
if( x <= mainScene.leftEdge - 20 ) then
topDrop:removeSelf()
if( midDrop.x ) then
midDrop:removeSelf()
end
end
end
if( midDrop.isVisible ) then
midDrop.counter = midDrop.counter + 1
if( midDrop.counter == 2 ) then
if( not midDrop.speed ) then
local speed = mainScene.city.curSpeed
if( speed < -8 ) then
speed = -8
end
midDrop.speed = 1.167 * math.abs( speed )
end
if( mainScene.player.bDashing ) then
midDrop.speed = 7
end
midDrop.y = midDrop.y + ( midDrop.speed * ( 60 / display.fps ) )
if( midDrop.y > bottomDrop.y - 3 ) then
bottomDrop.isVisible = true
if( not self.bPlayedVoice and mainScene:getSelectedCharacter() ~= "perry" ) then
local voiceSound = mainScene.sound:loadVoice( "voice-" .. mainScene:getSelectedCharacter() .. "RandyRanch.wav" )
self.bPlayedVoice = true
mainScene.sound:playVoice( voiceSound, 0 )
end
local splatSound = mainScene.sound:loadDamageSound( "splat.wav" )
mainScene.sound:playDamageSound( splatSound )
midDrop:removeSelf()
local frame = 0
local function mySpriteListener( event )
if( event.phase == "next" ) then
frame = frame + 1
if ( frame >= 2 and bottomDrop ) then
bottomDrop.bDisableCollision = false
bottomDrop:removeEventListener( "sprite", mySpriteListener )
end
end
end
bottomDrop:addEventListener( "sprite", mySpriteListener )
bottomDrop:play()
end
midDrop.counter = 0
end
end
end
function randyRanch:spawn(scene)
mainScene = scene
display.setDefault( "magTextureFilter", "nearest" )
display.setDefault( "minTextureFilter", "nearest" )
local topSheet = graphics.newImageSheet( "images/randyRanch_topAnim.png", { width=80, height=46, numFrames=10 } )
local topDrop = display.newSprite( topSheet, {{ name = "loop", start=1, count=10, time=600, loopCount=1 }} )
topDrop:setSequence( "loop" )
topDrop.anchorY = 0
topDrop.anchorX = 0.5
topDrop.y = mainScene.topEdge - 3
topDrop.x = mainScene.city:getGroundSpawnCoordinate() + 100
mainScene.city:setGroundSpawnCoordinate(topDrop.x+100 + math.random(200), topDrop.name)
topDrop.alpha = 0.9
mainScene.city.displayGroup:insert( topDrop )
topDrop.bEnableAutoSpawn = true
topDrop.name = "randyRanch"
local midDrop = display.newImageRect( "images/randyRanch_drop.png", 8, 19 )
midDrop.anchorY = 0.5
midDrop.anchorX = 0.5
midDrop.x = topDrop.x
midDrop.y = topDrop.y + 35
midDrop.isVisible = false
midDrop.name = "randyRanch"
midDrop.alpha = 0.9
midDrop.isVisible = false
mainScene.city.displayGroup:insert( midDrop )
local bottomSheet = graphics.newImageSheet( "images/randyRanch_bottomAnim.png", { width=82, height=46, numFrames=4 } )
local bottomDrop = display.newSprite( bottomSheet, {{ name = "loop", start=1, count=4, time=350, loopCount=1 }} )
bottomDrop:setSequence( "loop" )
bottomDrop.y = mainScene.groundY - 28
bottomDrop.x = midDrop.x + 2
bottomDrop.isVisible = false
bottomDrop.xChoke = 30
bottomDrop.yChoke = 24
bottomDrop.alpha = 0.9
bottomDrop.name = "randyRanch"
if( mainScene:getSelectedCharacter() == "perry" ) then
bottomDrop.bNoDamage = true
else
bottomDrop.bDisableCollision = true
end
bottomDrop.bImmortal = true
mainScene.city.displayGroup:insert( bottomDrop )
bottomDrop.update = function()
update(mainScene,topDrop,midDrop,bottomDrop, self)
end
bottomDrop.onPlayerCollision = function()
local voice = nil
if( mainScene:getSelectedCharacter() == "perry" ) then
voice = mainScene.sound:loadVoice( "voice-perryMmm.wav" )
else
voice = mainScene.sound:loadVoice( "voice-" .. mainScene:getSelectedCharacter() .. "Eww.wav" )
end
mainScene.sound:playVoice( voice )
local dispose = function()
audio.dispose( voice )
end
timer.performWithDelay( 5000, dispose, 1 )
end
bottomDrop.dispose = function()
if ( midDrop.x ) then
midDrop:removeSelf()
end
if( topDrop.x ) then
topDrop:removeSelf()
end
end
bottomDrop.bPerciseCollisionDetection = true
display.setDefault( "magTextureFilter", "linear" )
display.setDefault( "minTextureFilter", "linear" )
return bottomDrop
end
return randyRanch