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/CNZ/Elevator.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Elevator 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.value1 : object.startPos.y
13
private alias object.value2 : object.targetVelDest.y
14
private alias object.value3 : object.targetVelStart.y
15
private alias object.value4 : object.targetPos.y
16
private alias object.value5 : object.collisionOffset.y
17
private alias object.value6 : object.stood
18
private alias object.value7 : object.canReset
19
20
// States
21
private alias 0 : ELEVATOR_READY
22
private alias 1 : ELEVATOR_MOVETOTARGET
23
private alias 2 : ELEVATOR_REACHEDTARGET
24
private alias 3 : ELEVATOR_RETURNTOSTART
25
private alias 4 : ELEVATOR_WAITFORFINISH
26
27
// Player Aliases
28
private alias object.ypos : player.ypos
29
private alias object.collisionPlane : player.collisionPlane
30
31
32
// ========================
33
// Function Declarations
34
// ========================
35
36
reserve function Elevator_DebugDraw
37
reserve function Elevator_DebugSpawn
38
39
40
// ========================
41
// Function Definitions
42
// ========================
43
44
private function Elevator_DebugDraw
45
DrawSprite(0)
46
end function
47
48
49
private function Elevator_DebugSpawn
50
CreateTempObject(TypeName[Elevator], 0, object.xpos, object.ypos)
51
object[tempObjectPos].startPos.y = object.ypos
52
object[tempObjectPos].targetVelDest.y -= 0x200000
53
object[tempObjectPos].targetPos.y -= 0x400000
54
end function
55
56
57
// ========================
58
// Events
59
// ========================
60
61
event ObjectUpdate
62
temp6 = object.ypos
63
switch object.state
64
case ELEVATOR_READY
65
if object.stood == true
66
object.state = ELEVATOR_MOVETOTARGET
67
if object.priority != PRIORITY_XBOUNDS_DESTROY
68
object.priority = PRIORITY_ACTIVE
69
end if
70
PlaySfx(SfxName[Elevator], false)
71
else
72
foreach (TypeName[Elevator], arrayPos0, ACTIVE_ENTITIES)
73
if object.entityPos != arrayPos0
74
if object[arrayPos0].state == ELEVATOR_MOVETOTARGET
75
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -8, 16, 8, arrayPos0, -16, -56, 16, 8)
76
if checkResult == true
77
object.state = ELEVATOR_WAITFORFINISH
78
object.canReset = false
79
end if
80
end if
81
end if
82
next
83
end if
84
break
85
86
case ELEVATOR_MOVETOTARGET
87
if object.ypos >= object.targetVelDest.y
88
object.yvel -= 0x800
89
else
90
object.yvel += 0x800
91
end if
92
object.ypos += object.yvel
93
94
if object.propertyValue == 0
95
if object.ypos <= object.targetPos.y
96
object.ypos = object.targetPos.y
97
object.yvel = 0
98
object.state = ELEVATOR_REACHEDTARGET
99
end if
100
else
101
if object.ypos >= object.targetPos.y
102
object.ypos = object.targetPos.y
103
object.yvel = 0
104
object.state = ELEVATOR_REACHEDTARGET
105
end if
106
end if
107
break
108
109
case ELEVATOR_REACHEDTARGET
110
if object.stood == false
111
PlaySfx(SfxName[Elevator], false)
112
object.state = ELEVATOR_RETURNTOSTART
113
end if
114
break
115
116
case ELEVATOR_RETURNTOSTART
117
if object.ypos >= object.targetVelStart.y
118
object.yvel -= 0x800
119
else
120
object.yvel += 0x800
121
end if
122
object.ypos += object.yvel
123
124
if object.propertyValue == 0
125
if object.ypos >= object.startPos.y
126
object.ypos = object.startPos.y
127
object.yvel = 0
128
object.state = ELEVATOR_READY
129
end if
130
else
131
if object.ypos <= object.startPos.y
132
object.ypos = object.startPos.y
133
object.yvel = 0
134
object.state = ELEVATOR_READY
135
end if
136
end if
137
break
138
139
case ELEVATOR_WAITFORFINISH
140
if object.canReset == true
141
object.state = ELEVATOR_READY
142
end if
143
object.canReset = true
144
break
145
146
end switch
147
148
object.stood = false
149
temp0 = object.ypos
150
temp6 &= 0xFFFF0000
151
object.collisionOffset.y = object.ypos
152
object.collisionOffset.y &= 0xFFFF0000
153
object.collisionOffset.y -= temp6
154
155
object.ypos = temp6
156
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
157
switch object.state
158
case ELEVATOR_READY
159
case ELEVATOR_MOVETOTARGET
160
case ELEVATOR_REACHEDTARGET
161
BoxCollisionTest(C_TOUCH, object.entityPos, -48, -64, 48, 8, currentPlayer, 0, C_BOX, 0, C_BOX)
162
if checkResult == true
163
player[currentPlayer].collisionPlane = 0
164
end if
165
166
BoxCollisionTest(C_TOUCH, object.entityPos, -20, -32, 20, 8, currentPlayer, 0, C_BOX, 0, C_BOX)
167
if checkResult == true
168
player[currentPlayer].collisionPlane = 1
169
end if
170
171
BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -8, 16, 8, currentPlayer, 0, C_BOX, 0, C_BOX)
172
if checkResult == true
173
player[currentPlayer].ypos += object.collisionOffset.y
174
player[currentPlayer].collisionPlane = 1
175
object.stood = true
176
end if
177
break
178
179
case ELEVATOR_RETURNTOSTART
180
BoxCollisionTest(C_TOUCH, object.entityPos, -48, -64, 48, 8, currentPlayer, 0, C_BOX, 0, C_BOX)
181
if checkResult == true
182
player[currentPlayer].collisionPlane = 0
183
end if
184
// [Fallthrough]
185
case ELEVATOR_WAITFORFINISH
186
BoxCollisionTest(C_TOUCH, object.entityPos, -20, -32, 20, 8, currentPlayer, 0, C_BOX, 0, C_BOX)
187
if checkResult == true
188
object.canReset = false
189
end if
190
break
191
end switch
192
next
193
194
object.ypos = temp0
195
if object.outOfBounds == true
196
temp0 = object.ypos
197
object.ypos = object.startPos.y
198
if object.outOfBounds == true
199
object.state = ELEVATOR_READY
200
if object.priority != PRIORITY_XBOUNDS_DESTROY
201
object.priority = PRIORITY_BOUNDS
202
end if
203
object.stood = 0
204
object.yvel = 0
205
else
206
object.ypos = temp0
207
end if
208
end if
209
end event
210
211
212
event ObjectDraw
213
DrawSprite(0)
214
end event
215
216
217
event ObjectStartup
218
LoadSpriteSheet("CNZ/Objects.gif")
219
SpriteFrame(-16, -8, 32, 16, 193, 34)
220
221
foreach (TypeName[Elevator], arrayPos0, ALL_ENTITIES)
222
object[arrayPos0].startPos.y = object[arrayPos0].ypos
223
object[arrayPos0].targetVelDest.y = object[arrayPos0].ypos
224
object[arrayPos0].targetVelStart.y = object[arrayPos0].ypos
225
object[arrayPos0].targetPos.y = object[arrayPos0].ypos
226
227
temp0 = object[arrayPos0].propertyValue
228
temp0 &= 0x7F
229
temp0 <<= 18
230
231
object[arrayPos0].propertyValue >>= 7
232
if object[arrayPos0].propertyValue == 1
233
object[arrayPos0].ypos -= temp0
234
object[arrayPos0].startPos.y -= temp0
235
object[arrayPos0].targetPos.y += temp0
236
object[arrayPos0].targetVelDest.y += 0x20000
237
object[arrayPos0].targetVelStart.y -= 0x20000
238
else
239
object[arrayPos0].ypos += temp0
240
object[arrayPos0].startPos.y += temp0
241
object[arrayPos0].targetPos.y -= temp0
242
end if
243
next
244
245
SetTableValue(TypeName[Elevator], DebugMode_ObjCount, DebugMode_TypesTable)
246
SetTableValue(Elevator_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
247
SetTableValue(Elevator_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
248
DebugMode_ObjCount++
249
end event
250
251
252
// ========================
253
// Editor Events
254
// ========================
255
256
event RSDKEdit
257
if editor.returnVariable == true
258
switch editor.variableID
259
case EDIT_VAR_PROPVAL // property value
260
checkResult = object.propertyValue
261
break
262
263
case 0 // distance
264
checkResult = object.propertyValue
265
checkResult &= 0x7F
266
break
267
268
case 1 // direction
269
GetBit(checkResult, object.propertyValue, 7)
270
break
271
272
end switch
273
else
274
switch editor.variableID
275
case EDIT_VAR_PROPVAL // property value
276
object.propertyValue = editor.variableValue
277
break
278
279
case 0 // distance
280
editor.variableValue &= 0x7F
281
object.propertyValue &= 0x80
282
283
object.propertyValue |= editor.variableValue
284
break
285
286
case 1 // direction
287
CheckNotEqual(editor.variableValue, false)
288
SetBit(object.propertyValue, 7, checkResult)
289
break
290
291
end switch
292
end if
293
end event
294
295
296
event RSDKDraw
297
DrawSprite(0)
298
299
if editor.showGizmos == true
300
editor.drawingOverlay = true
301
302
object.startPos.y = object.ypos
303
object.targetPos.y = object.ypos
304
305
temp0 = object.propertyValue
306
temp0 &= 0x7F
307
temp0 <<= 18
308
309
GetBit(checkResult, object.propertyValue, 7)
310
if checkResult == true
311
object.startPos.y -= temp0
312
object.targetPos.y += temp0
313
else
314
object.startPos.y += temp0
315
object.targetPos.y -= temp0
316
end if
317
318
object.inkEffect = INK_BLEND
319
320
DrawSpriteFX(0, FX_INK, object.xpos, object.startPos.y)
321
DrawSpriteFX(0, FX_INK, object.xpos, object.targetPos.y)
322
323
object.inkEffect = INK_NONE
324
325
DrawArrow(object.xpos, object.startPos.y, object.xpos, object.targetPos.y, 0x00, 0xFF, 0x00)
326
327
editor.drawingOverlay = false
328
end if
329
end event
330
331
332
event RSDKLoad
333
LoadSpriteSheet("CNZ/Objects.gif")
334
SpriteFrame(-16, -8, 32, 16, 193, 34)
335
336
AddEditorVariable("distance")
337
SetActiveVariable("distance")
338
339
AddEditorVariable("direction")
340
SetActiveVariable("direction")
341
AddEnumVariable("Up", 0)
342
AddEnumVariable("Down", 1)
343
end event
344
345