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/OOZ/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.centerPos.y
14
private alias object.value3 : object.bounds.y
15
private alias object.value4 : object.collisionOffset.y
16
private alias object.value5 : object.stood
17
18
// States
19
private alias 0 : ELEVATOR_AWAITSTOOD
20
private alias 1 : ELEVATOR_MOVING
21
private alias 2 : ELEVATOR_IDLE
22
23
// Player Aliases
24
private alias object.ypos : player.ypos
25
26
private alias object.value17 : debugMode.currentSelection
27
28
29
// ========================
30
// Function Declarations
31
// ========================
32
33
reserve function Elevator_DebugDraw
34
reserve function Elevator_DebugSpawn
35
36
37
// ========================
38
// Static Values
39
// ========================
40
41
private value Elevator_startDebugID = 0
42
43
44
// ========================
45
// Function Definitions
46
// ========================
47
48
private function Elevator_DebugDraw
49
temp0 = debugMode[0].currentSelection
50
temp0 -= Elevator_startDebugID
51
DrawSprite(temp0)
52
end function
53
54
55
private function Elevator_DebugSpawn
56
CreateTempObject(TypeName[Elevator], 0, object.xpos, object.ypos)
57
object[tempObjectPos].startPos.y = object.ypos
58
object[tempObjectPos].centerPos.y = object.ypos
59
object[tempObjectPos].centerPos.y -= 0x420000
60
object[tempObjectPos].bounds.y = object.ypos
61
object[tempObjectPos].bounds.y -= 0x800000
62
object[tempObjectPos].frame = debugMode[0].currentSelection
63
object[tempObjectPos].frame -= Elevator_startDebugID
64
end function
65
66
67
// ========================
68
// Events
69
// ========================
70
71
event ObjectUpdate
72
temp6 = object.ypos
73
switch object.state
74
case ELEVATOR_AWAITSTOOD
75
if object.stood == true
76
object.state = ELEVATOR_MOVING
77
if object.priority != PRIORITY_XBOUNDS_DESTROY
78
object.priority = PRIORITY_ACTIVE
79
end if
80
end if
81
break
82
83
case ELEVATOR_MOVING
84
if object.ypos >= object.centerPos.y
85
object.yvel -= 0x680
86
else
87
object.yvel += 0x680
88
end if
89
object.ypos += object.yvel
90
91
if object.propertyValue == 0
92
if object.ypos <= object.bounds.y
93
object.ypos = object.bounds.y
94
object.yvel = 0
95
object.state = ELEVATOR_IDLE
96
end if
97
else
98
if object.ypos >= object.bounds.y
99
object.ypos = object.bounds.y
100
object.yvel = 0
101
object.state = ELEVATOR_IDLE
102
end if
103
end if
104
break
105
106
case ELEVATOR_IDLE
107
break
108
109
end switch
110
111
object.stood = false
112
temp0 = object.ypos
113
temp6 &= 0xFFFF0000
114
object.collisionOffset.y = object.ypos
115
object.collisionOffset.y &= 0xFFFF0000
116
object.collisionOffset.y -= temp6
117
object.ypos = temp6
118
119
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
120
if object.frame == 0
121
BoxCollisionTest(C_PLATFORM, object.entityPos, -64, -12, 64, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
122
else
123
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -12, 32, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
124
end if
125
126
if checkResult == true
127
player[currentPlayer].ypos += object.collisionOffset.y
128
object.stood = true
129
end if
130
next
131
object.ypos = temp0
132
133
if object.outOfBounds == true
134
temp0 = object.ypos
135
object.ypos = object.startPos.y
136
if object.outOfBounds == true
137
object.state = ELEVATOR_AWAITSTOOD
138
if object.priority != PRIORITY_XBOUNDS_DESTROY
139
object.priority = PRIORITY_BOUNDS
140
end if
141
object.stood = false
142
object.yvel = 0
143
else
144
object.ypos = temp0
145
end if
146
end if
147
end event
148
149
150
event ObjectDraw
151
DrawSprite(object.frame)
152
end event
153
154
155
event ObjectStartup
156
LoadSpriteSheet("OOZ/Objects.gif")
157
SpriteFrame(-64, -12, 128, 24, 127, 1)
158
SpriteFrame(-32, -12, 64, 24, 141, 26)
159
160
foreach (TypeName[Elevator], arrayPos0, ALL_ENTITIES)
161
object[arrayPos0].ypos += 0x40000
162
object[arrayPos0].startPos.y = object[arrayPos0].ypos
163
object[arrayPos0].centerPos.y = object[arrayPos0].ypos
164
object[arrayPos0].bounds.y = object[arrayPos0].ypos
165
166
temp0 = object[arrayPos0].propertyValue
167
temp0 &= 0x7F
168
temp0 <<= 18
169
object[arrayPos0].propertyValue >>= 7
170
if object[arrayPos0].propertyValue == 1
171
object[arrayPos0].ypos -= temp0
172
object[arrayPos0].startPos.y -= temp0
173
object[arrayPos0].bounds.y += temp0
174
object[arrayPos0].centerPos.y += 0x20000
175
else
176
object[arrayPos0].ypos += temp0
177
object[arrayPos0].startPos.y += temp0
178
object[arrayPos0].bounds.y -= temp0
179
object[arrayPos0].centerPos.y -= 0x20000
180
end if
181
next
182
183
temp0 = 0
184
Elevator_startDebugID = DebugMode_ObjCount
185
while temp0 < 2
186
SetTableValue(TypeName[Elevator], DebugMode_ObjCount, DebugMode_TypesTable)
187
SetTableValue(Elevator_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
188
SetTableValue(Elevator_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
189
DebugMode_ObjCount++
190
temp0++
191
loop
192
end event
193
194
195
// ========================
196
// Editor Events
197
// ========================
198
199
event RSDKEdit
200
if editor.returnVariable == true
201
switch editor.variableID
202
case EDIT_VAR_PROPVAL // property value
203
checkResult = object.propertyValue
204
break
205
206
case 0 // distance
207
checkResult = object.propertyValue
208
checkResult &= 0x7F
209
break
210
211
case 1 // direction
212
GetBit(checkResult, object.propertyValue, 7)
213
break
214
215
case 2 // size
216
checkResult = object.frame
217
break
218
219
end switch
220
else
221
switch editor.variableID
222
case EDIT_VAR_PROPVAL // property value
223
object.propertyValue = editor.variableValue
224
break
225
226
case 0 // distance
227
editor.variableValue &= 0x7F
228
object.propertyValue &= 0x80
229
230
object.propertyValue |= editor.variableValue
231
break
232
233
case 1 // direction
234
CheckNotEqual(editor.variableValue, false)
235
SetBit(object.propertyValue, 7, checkResult)
236
break
237
238
case 2 // size
239
object.frame = editor.variableValue
240
break
241
242
end switch
243
end if
244
end event
245
246
247
event RSDKDraw
248
DrawSprite(object.frame)
249
250
if editor.showGizmos == true
251
object.inkEffect = INK_BLEND
252
253
temp0 = object.propertyValue
254
temp0 &= 0x7F
255
temp0 <<= 18
256
257
// Top Preview
258
temp1 = object.ypos
259
temp1 += 0x40000
260
temp1 += temp0
261
DrawSpriteFX(object.frame, FX_INK, object.xpos, temp1)
262
263
// Bottom Preview
264
temp2 = object.ypos
265
temp2 += 0x40000
266
temp2 -= temp0
267
DrawSpriteFX(object.frame, FX_INK, object.xpos, temp2)
268
269
// Draw an arrow showing the direction this Elevator will go
270
object.inkEffect = INK_NONE
271
if object.propertyValue >= 0x80 // See what the top bit has
272
DrawArrow(object.xpos, temp2, object.xpos, temp1, 0x00, 0xFF, 0x00)
273
else
274
DrawArrow(object.xpos, temp1, object.xpos, temp2, 0x00, 0xFF, 0x00)
275
end if
276
end if
277
end event
278
279
280
event RSDKLoad
281
LoadSpriteSheet("OOZ/Objects.gif")
282
SpriteFrame(-64, -12, 128, 24, 127, 1)
283
SpriteFrame(-32, -12, 64, 24, 141, 26)
284
285
AddEditorVariable("distance")
286
SetActiveVariable("distance")
287
288
AddEditorVariable("direction")
289
SetActiveVariable("direction")
290
AddEnumVariable("Up", 0)
291
AddEnumVariable("Down", 1)
292
293
AddEditorVariable("size")
294
SetActiveVariable("size")
295
AddEnumVariable("Large", 0)
296
AddEnumVariable("Small", 1)
297
end event
298
299