Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 2/Scripts/MPZ/ButtonBridge.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Button Bridge Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.value0 : object.timer
13
private alias object.value1 : object.drawPos.x
14
15
// States
16
private alias 0 : BUTTONBRIDGE_HIDDEN
17
private alias 1 : BUTTONBRIDGE_SHOWING
18
private alias 2 : BUTTONBRIDGE_SHOWN
19
private alias 3 : BUTTONBRIDGE_HIDING
20
21
// Player Aliases
22
private alias object.state : player.state
23
private alias object.xpos : player.xpos
24
private alias object.animation : player.animation
25
26
private alias object.value1 : player.timer
27
private alias object.value17 : debugMode.currentSelection
28
29
// PushButton Aliases
30
private alias object.value0 : pushButton.pressed
31
32
33
// ========================
34
// Function Declarations
35
// ========================
36
37
reserve function ButtonBridge_Setup
38
reserve function ButtonBridge_DebugDraw
39
reserve function ButtonBridge_DebugSpawn
40
41
42
// ========================
43
// Static Values
44
// ========================
45
46
private value ButtonBridge_startDebugID = 0
47
48
49
// ========================
50
// Function Defintions
51
// ========================
52
53
private function ButtonBridge_Setup
54
object[arrayPos0].priority = PRIORITY_ACTIVE
55
object[arrayPos0].timer = 64
56
object[arrayPos0].drawPos.x = object[arrayPos0].xpos
57
if object[arrayPos0].direction == FLIP_NONE
58
object[arrayPos0].drawPos.x -= 0x4C0000
59
else
60
object[arrayPos0].drawPos.x += 0x4C0000
61
end if
62
63
if object[arrayPos0].propertyValue == 1
64
if object[arrayPos0].direction == FLIP_NONE
65
object[arrayPos0].xpos -= 0x800000
66
else
67
object[arrayPos0].xpos += 0x800000
68
end if
69
end if
70
end function
71
72
73
private function ButtonBridge_DebugDraw
74
temp0 = debugMode[0].currentSelection
75
temp0 -= ButtonBridge_startDebugID
76
77
temp1 = object.xpos
78
if object.direction == FLIP_NONE
79
temp1 -= 0x4C0000
80
else
81
temp1 += 0x4C0000
82
end if
83
DrawSpriteXY(0, temp1, object.ypos)
84
85
temp1 = object.xpos
86
if temp0 == 1
87
if object.direction == FLIP_NONE
88
temp1 -= 0x800000
89
else
90
temp1 += 0x800000
91
end if
92
end if
93
DrawSpriteXY(4, temp1, object.ypos)
94
end function
95
96
97
private function ButtonBridge_DebugSpawn
98
temp0 = debugMode[0].currentSelection
99
temp0 -= ButtonBridge_startDebugID
100
CreateTempObject(TypeName[Button Bridge], temp0, object.xpos, object.ypos)
101
object[tempObjectPos].direction = object.direction
102
arrayPos0 = object[tempObjectPos].entityPos
103
CallFunction(ButtonBridge_Setup)
104
end function
105
106
107
// ========================
108
// Events
109
// ========================
110
111
event ObjectUpdate
112
switch object.state
113
case BUTTONBRIDGE_HIDDEN
114
if pushButton[+1].pressed == true
115
if object.propertyValue == 0
116
object.state = BUTTONBRIDGE_SHOWING
117
else
118
object.state = BUTTONBRIDGE_HIDING
119
end if
120
end if
121
122
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
123
BoxCollisionTest(C_SOLID, object.entityPos, -64, -12, 64, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
124
next
125
break
126
127
case BUTTONBRIDGE_SHOWING
128
temp0 = object.xpos
129
temp0 &= 0xFFFF0000
130
if object.direction == FLIP_NONE
131
object.xpos -= 0x20000
132
object.frame++
133
else
134
object.xpos += 0x20000
135
object.frame--
136
end if
137
138
object.frame &= 3
139
140
object.timer--
141
if object.timer <= 0
142
if object.propertyValue == 0
143
object.state = BUTTONBRIDGE_SHOWN
144
else
145
object.state = BUTTONBRIDGE_HIDDEN
146
object.timer = 64
147
end if
148
end if
149
150
temp1 = object.xpos
151
temp1 &= 0xFFFF0000
152
temp1 -= temp0
153
temp2 = object.xpos
154
155
object.xpos = temp0
156
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
157
BoxCollisionTest(C_SOLID, object.entityPos, -64, -12, 64, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
158
switch checkResult
159
case COL_TOP
160
player[currentPlayer].xpos += temp1
161
break
162
163
case COL_LEFT
164
case COL_RIGHT
165
if player[currentPlayer].state == Player_State_Climb
166
player[currentPlayer].timer = 0
167
player[currentPlayer].animation = ANI_GLIDING_DROP
168
player[currentPlayer].state = Player_State_GlideDrop
169
end if
170
break
171
end switch
172
next
173
object.xpos = temp2
174
break
175
176
case BUTTONBRIDGE_SHOWN
177
object.timer++
178
if object.timer == 180
179
object.timer = 0
180
if object.propertyValue == 0
181
object.state = BUTTONBRIDGE_HIDING
182
else
183
object.state = BUTTONBRIDGE_SHOWING
184
end if
185
object.timer = 64
186
end if
187
188
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
189
BoxCollisionTest(C_SOLID, object.entityPos, -64, -12, 64, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
190
next
191
break
192
193
case BUTTONBRIDGE_HIDING
194
temp0 = object.xpos
195
temp0 &= 0xFFFF0000
196
if object.direction == FLIP_NONE
197
object.xpos += 0x20000
198
object.frame--
199
else
200
object.xpos -= 0x20000
201
object.frame++
202
end if
203
object.frame &= 3
204
205
object.timer--
206
if object.timer <= 0
207
if object.propertyValue == 0
208
object.state = BUTTONBRIDGE_HIDDEN
209
object.timer = 64
210
else
211
object.state = BUTTONBRIDGE_SHOWN
212
end if
213
end if
214
215
temp1 = object.xpos
216
temp1 &= 0xFFFF0000
217
temp1 -= temp0
218
temp2 = object.xpos
219
220
object.xpos = temp0
221
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
222
BoxCollisionTest(C_SOLID, object.entityPos, -64, -12, 64, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
223
switch checkResult
224
case COL_TOP
225
player[currentPlayer].xpos += temp1
226
break
227
228
case COL_LEFT
229
case COL_RIGHT
230
if player[currentPlayer].state == Player_State_Climb
231
player[currentPlayer].timer = 0
232
player[currentPlayer].animation = ANI_GLIDING_DROP
233
player[currentPlayer].state = Player_State_GlideDrop
234
end if
235
break
236
end switch
237
next
238
239
object.xpos = temp2
240
break
241
242
end switch
243
end event
244
245
246
event ObjectDraw
247
DrawSpriteXY(object.frame, object.drawPos.x, object.ypos)
248
DrawSprite(4)
249
end event
250
251
252
event ObjectStartup
253
LoadSpriteSheet("MPZ/Objects.gif")
254
SpriteFrame(-12, 8, 24, 24, 133, 126)
255
SpriteFrame(-12, 8, 24, 24, 158, 126)
256
SpriteFrame(-12, 8, 24, 24, 158, 126)
257
SpriteFrame(-12, 8, 24, 24, 183, 126)
258
SpriteFrame(-64, -12, 128, 24, 350, 182)
259
260
foreach (TypeName[Button Bridge], arrayPos0, ALL_ENTITIES)
261
CallFunction(ButtonBridge_Setup)
262
next
263
264
temp0 = 0
265
ButtonBridge_startDebugID = DebugMode_ObjCount
266
while temp0 < 2
267
SetTableValue(TypeName[Button Bridge], DebugMode_ObjCount, DebugMode_TypesTable)
268
SetTableValue(ButtonBridge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
269
SetTableValue(ButtonBridge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
270
DebugMode_ObjCount++
271
temp0++
272
loop
273
end event
274
275
276
// ========================
277
// Editor Events
278
// ========================
279
280
event RSDKEdit
281
if editor.returnVariable == true
282
switch editor.variableID
283
case EDIT_VAR_PROPVAL // property value
284
checkResult = object.propertyValue
285
break
286
287
case 0 // type
288
checkResult = object.propertyValue
289
break
290
291
end switch
292
else
293
switch editor.variableID
294
case EDIT_VAR_PROPVAL // property value
295
object.propertyValue = editor.variableValue
296
break
297
298
case 0 // type
299
object.propertyValue = editor.variableValue
300
break
301
302
end switch
303
end if
304
end event
305
306
307
event RSDKDraw
308
temp1 = object.xpos
309
if object.direction == FLIP_NONE
310
temp1 -= 0x4C0000
311
else
312
temp1 += 0x4C0000
313
end if
314
DrawSpriteXY(0, temp1, object.ypos)
315
316
temp1 = object.xpos
317
if object.propertyValue == 1
318
if object.direction == FLIP_NONE
319
temp1 -= 0x800000
320
else
321
temp1 += 0x800000
322
end if
323
end if
324
DrawSpriteXY(1, temp1, object.ypos)
325
end event
326
327
328
event RSDKLoad
329
LoadSpriteSheet("MPZ/Objects.gif")
330
SpriteFrame(-12, 8, 24, 24, 133, 126)
331
SpriteFrame(-64, -12, 128, 24, 350, 182)
332
333
AddEditorVariable("type")
334
SetActiveVariable("type")
335
AddEnumVariable("Show On Activate", 0)
336
AddEnumVariable("Hide On Activate", 1)
337
338
// Direction is to be set from editor
339
end event
340
341