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/HTZ/Lift.txt
1479 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Lift 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.distTimer // Movement distance, represented as a timer for how long the object should go for
13
private alias object.value1 : object.collisionOffset.y
14
private alias object.value2 : object.originPos.x
15
private alias object.value3 : object.originPos.y
16
17
private alias 0 : LIFT_WAITING
18
private alias 1 : LIFT_MOVING
19
private alias 2 : LIFT_FALLING
20
private alias 3 : LIFT_FALLEN
21
22
// Player Aliases
23
private alias object.xpos : player.xpos
24
private alias object.ypos : player.ypos
25
26
27
// ========================
28
// Function Declarations
29
// ========================
30
31
reserve function Lift_DebugDraw
32
reserve function Lift_DebugSpawn
33
34
35
// ========================
36
// Function Definitions
37
// ========================
38
39
private function Lift_DebugDraw
40
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
41
DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)
42
end function
43
44
45
private function Lift_DebugSpawn
46
CreateTempObject(TypeName[Lift], 0, object.xpos, object.ypos)
47
object[tempObjectPos].drawOrder = 5
48
object[tempObjectPos].direction = object.direction
49
end function
50
51
52
// ========================
53
// Events
54
// ========================
55
56
event ObjectUpdate
57
// Flag, for if this Lift should check for OOB after
58
temp7 = false
59
60
switch object.state
61
case LIFT_WAITING
62
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
63
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, 41, 32, 57, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
64
if checkResult == true
65
object.state = LIFT_MOVING
66
object.priority = PRIORITY_ACTIVE
67
end if
68
next
69
break
70
71
case LIFT_MOVING
72
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
73
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, 41, 32, 57, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
74
if checkResult == true
75
if object.direction == FLIP_X
76
player[currentPlayer].xpos -= 0x20000
77
else
78
player[currentPlayer].xpos += 0x20000
79
end if
80
player[currentPlayer].ypos += 0x10000
81
end if
82
next
83
84
if object.direction == FLIP_X
85
object.xpos -= 0x20000
86
else
87
object.xpos += 0x20000
88
end if
89
90
object.ypos += 0x10000
91
temp0 = oscillation
92
temp0 &= 15
93
if temp0 == 0
94
PlaySfx(SfxName[Lift Tick], false)
95
end if
96
97
object.distTimer--
98
if object.distTimer == 0
99
object.collisionOffset.y = object.ypos
100
object.priority = PRIORITY_ACTIVE
101
object.state = LIFT_FALLING
102
end if
103
break
104
105
case LIFT_FALLING
106
// Backup the object's ypos, since it'll need to be changed soon
107
temp0 = object.ypos
108
109
// Setup object values for collision checks
110
object.ypos = object.collisionOffset.y
111
temp1 = object.collisionOffset.y
112
temp1 &= 0xFFFF0000
113
object.collisionOffset.y += object.yvel
114
object.yvel += 0x3800
115
temp2 = object.collisionOffset.y
116
temp2 &= 0xFFFF0000
117
temp2 -= temp1
118
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
119
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, 41, 32, 57, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
120
if checkResult == true
121
player[currentPlayer].ypos += temp2
122
end if
123
next
124
125
if object.outOfBounds == true
126
object.state = LIFT_FALLEN
127
else
128
// Set this flag to exlcude this object from OOB checks
129
temp7 = true
130
end if
131
132
// And now it's safe to restore the object's ypos
133
object.ypos = temp0
134
break
135
136
case LIFT_FALLEN
137
// Interesting note - in most cases whenever an object has an empty state, there's simply no case jump destination for it
138
// In this case, however, it looks like something may have been here after all...
139
break
140
141
end switch
142
143
if temp7 == false // Don't do this if the lift is still moving
144
if object.outOfBounds == true
145
temp0 = object.xpos
146
temp1 = object.ypos
147
object.xpos = object.originPos.x
148
object.ypos = object.originPos.y
149
if object.outOfBounds == true
150
object.yvel = 0
151
object.distTimer = object.propertyValue
152
object.distTimer <<= 3
153
object.priority = PRIORITY_BOUNDS
154
object.state = LIFT_WAITING
155
else
156
object.xpos = temp0
157
object.ypos = temp1
158
end if
159
end if
160
end if
161
end event
162
163
164
event ObjectDraw
165
switch object.state
166
case LIFT_WAITING
167
case LIFT_MOVING
168
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
169
DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)
170
break
171
172
case LIFT_FALLING
173
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
174
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
175
DrawSpriteFX(3, FX_FLIP, object.xpos, object.collisionOffset.y)
176
break
177
178
case LIFT_FALLEN
179
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
180
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
181
break
182
183
end switch
184
end event
185
186
187
event ObjectStartup
188
CheckCurrentStageFolder("Zone05")
189
190
if checkResult == true
191
LoadSpriteSheet("HTZ/Objects.gif")
192
SpriteFrame(-28, -63, 56, 90, 102, 1) // 0 - Holding vines frame
193
SpriteFrame(-28, 27, 56, 13, 109, 198) // 1 - Loose Vines Frame
194
SpriteFrame(-32, 27, 64, 21, 109, 212) // 2 - Platform frame, attached to vines
195
SpriteFrame(-32, 27, 64, 21, 109, 234) // 3 - Loose Platform Frame
196
else
197
LoadSpriteSheet("MBZ/Objects.gif")
198
SpriteFrame(-28, -63, 56, 90, 73, 848)
199
SpriteFrame(-28, 27, 56, 13, 73, 939)
200
SpriteFrame(-32, 27, 64, 21, 1, 953)
201
SpriteFrame(-32, 27, 64, 21, 65, 953)
202
end if
203
204
foreach (TypeName[Lift], arrayPos0, ALL_ENTITIES)
205
object[arrayPos0].originPos.x = object[arrayPos0].xpos
206
object[arrayPos0].originPos.y = object[arrayPos0].ypos
207
object[arrayPos0].drawOrder = 5
208
object[arrayPos0].distTimer = object[arrayPos0].propertyValue
209
object[arrayPos0].distTimer <<= 3
210
next
211
212
SetTableValue(TypeName[Lift], DebugMode_ObjCount, DebugMode_TypesTable)
213
SetTableValue(Lift_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
214
SetTableValue(Lift_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
215
DebugMode_ObjCount++
216
end event
217
218
219
// ========================
220
// Editor Events
221
// ========================
222
223
event RSDKDraw
224
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
225
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
226
227
if editor.showGizmos == true
228
editor.drawingOverlay = true
229
230
// Show a ghost of the lift's destination
231
232
object.inkEffect = INK_BLEND
233
234
temp0 = object.propertyValue
235
temp0 <<= 3
236
temp1 = object.xpos
237
temp2 = object.ypos
238
temp3 = 0x20000
239
240
if object.direction == FLIP_X
241
FlipSign(temp3)
242
end if
243
244
while temp0 > 0
245
temp1 += temp3
246
temp2 += 0x10000
247
temp0--
248
loop
249
250
DrawSpriteFX(0, FX_INK, temp1, temp2)
251
DrawSpriteFX(1, FX_INK, temp1, temp2)
252
253
object.inkEffect = INK_NONE
254
255
// Here -> dest
256
DrawArrow(object.xpos, object.ypos, temp1, temp2, 0xFF, 0xFF, 0x00)
257
258
editor.drawingOverlay = false
259
end if
260
end event
261
262
263
event RSDKLoad
264
CheckCurrentStageFolder("Zone05")
265
if checkResult == true
266
LoadSpriteSheet("HTZ/Objects.gif")
267
SpriteFrame(-28, -63, 56, 90, 102, 1) // Vines
268
SpriteFrame(-32, 27, 64, 21, 109, 212) // Platform
269
else
270
LoadSpriteSheet("MBZ/Objects.gif")
271
SpriteFrame(-28, -63, 56, 90, 73, 848) // Vines
272
SpriteFrame(-32, 27, 64, 21, 1, 953) // Platform
273
end if
274
275
SetVariableAlias(ALIAS_VAR_PROPVAL, "distance")
276
end event
277
278