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/MCZ/CollapsingLedge.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: C Ledge 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.delay
14
15
private alias 0 : CLEDGE_ACTIVE
16
private alias 1 : CLEDGE_COLLAPSE
17
private alias 2 : CLEDGE_COLLAPSED
18
private alias 3 : CLEDGE_NONE
19
private alias 4 : CLEDGE_TILEDELAY
20
private alias 5 : CLEDGE_TILEFALL
21
22
23
// ========================
24
// Function Declarations
25
// ========================
26
27
reserve function CLedge_DebugDraw
28
reserve function CLedge_DebugSpawn
29
30
31
// ========================
32
// Tables
33
// ========================
34
35
private table CLedge_tileFrameTable
36
1, 2, 3, 4, 5, 6
37
end table
38
39
private table CLedge_collapseTable
40
2, 6, 10, 14, 18, 22
41
end table
42
43
44
// ========================
45
// Function Definitions
46
// ========================
47
48
private function CLedge_DebugDraw
49
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
50
end function
51
52
53
private function CLedge_DebugSpawn
54
CreateTempObject(TypeName[C Ledge], 0, object.xpos, object.ypos)
55
object[tempObjectPos].direction = object.direction
56
end function
57
58
59
// ========================
60
// Events
61
// ========================
62
63
event ObjectUpdate
64
switch object.state
65
case CLEDGE_ACTIVE
66
break
67
68
case CLEDGE_COLLAPSE
69
if object.timer < 10
70
object.timer++
71
else
72
temp0 = 0
73
while temp0 < 6
74
GetTableValue(temp1, temp0, CLedge_tileFrameTable)
75
CreateTempObject(TypeName[C Ledge], temp1, object.xpos, object.ypos)
76
object[tempObjectPos].state = CLEDGE_TILEDELAY
77
object[tempObjectPos].direction = object.direction
78
GetTableValue(object[tempObjectPos].delay, temp0, CLedge_collapseTable)
79
temp0++
80
loop
81
PlaySfx(SfxName[Ledge Break], false)
82
object.timer = 0
83
object.state++
84
end if
85
break
86
87
case CLEDGE_COLLAPSED
88
// During this state, the object is invisible, but it's still providing collision for a brief moment before it truly disappears
89
if object.timer < 20
90
object.timer++
91
else
92
object.timer = 0
93
object.state++
94
end if
95
break
96
97
case CLEDGE_NONE
98
break
99
100
case CLEDGE_TILEDELAY
101
if object.timer < object.delay
102
object.timer++
103
else
104
object.timer = 0
105
object.state++
106
end if
107
break
108
109
case CLEDGE_TILEFALL
110
object.ypos += object.yvel
111
object.yvel += 0x4000
112
if object.outOfBounds == true
113
object.type = TypeName[Blank Object]
114
end if
115
break
116
117
end switch
118
119
if object.state < CLEDGE_TILEDELAY
120
if object.outOfBounds == true
121
object.state = CLEDGE_ACTIVE
122
object.timer = 0
123
object.priority = PRIORITY_BOUNDS
124
end if
125
end if
126
127
if object.state < CLEDGE_NONE
128
// In one of the platform states, so act like one and provide collision to the player
129
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
130
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -24, 32, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
131
132
if checkResult == true
133
if object.state == CLEDGE_ACTIVE
134
object.state = CLEDGE_COLLAPSE
135
object.priority = PRIORITY_ACTIVE
136
end if
137
end if
138
next
139
end if
140
end event
141
142
143
event ObjectDraw
144
switch object.state
145
case CLEDGE_ACTIVE
146
case CLEDGE_COLLAPSE
147
// Full platform - simply draw the entire sprite
148
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
149
break
150
151
case CLEDGE_COLLAPSED
152
case CLEDGE_NONE
153
break
154
155
case CLEDGE_TILEDELAY
156
case CLEDGE_TILEFALL
157
// Tile fragment, draw whatever sprite's assigned to this object
158
DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)
159
break
160
161
end switch
162
end event
163
164
165
event ObjectStartup
166
LoadSpriteSheet("MCZ/Objects.gif")
167
168
SpriteFrame(-32, -24, 64, 48, 136, 66) // 0 - Full platform
169
170
SpriteFrame( 8, -8, 24, 32, 176, 82) // 1-6 - Individual platform strips
171
SpriteFrame(-16, -8, 24, 32, 152, 82) // (for when it falls apart)
172
SpriteFrame( 16, -24, 16, 16, 184, 66)
173
SpriteFrame( 0, -24, 16, 16, 168, 66)
174
SpriteFrame(-16, -24, 16, 16, 152, 66)
175
SpriteFrame(-32, -24, 16, 16, 136, 66)
176
177
// Huh? Blank Object?
178
// Prolly meant to be [C Ledge], but it might be [C Floor] or something in the original source instead
179
foreach (TypeName[Blank Object], arrayPos0, ALL_ENTITIES)
180
// This uses Property Value as direction, though that isn't the case for this object
181
// -> Interestingly, there are a few C Ledges that do have their prop val set to 1, the majority are
182
// right-facing ones, though there is a single left-facing one with it too
183
// -> Once again though, this doesn't matter anyway - check out down below
184
185
object[arrayPos0].direction = object[arrayPos0].propertyValue
186
object[arrayPos0].direction &= FLIP_X
187
next
188
189
// The above is meant to set up the directions of all C Ledges in the scene, but thanks to an erroneous TypeName
190
// it doesn't function correctly
191
// However this still works by chance, because the direction attribute is already set from the scene
192
// There are many ledges that have something in their property value, but that value isn't used by the game
193
194
SetTableValue(TypeName[C Ledge], DebugMode_ObjCount, DebugMode_TypesTable)
195
SetTableValue(CLedge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
196
SetTableValue(CLedge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
197
DebugMode_ObjCount++
198
end event
199
200
201
// ========================
202
// Editor Events
203
// ========================
204
205
event RSDKEdit
206
if editor.returnVariable == true
207
switch editor.variableID
208
case EDIT_VAR_PROPVAL // property value
209
checkResult = object.propertyValue
210
break
211
212
case 0 // direction
213
checkResult = object.direction
214
checkResult &= 1
215
break
216
217
end switch
218
else
219
switch editor.variableID
220
case EDIT_VAR_PROPVAL // property value
221
object.propertyValue = editor.variableValue
222
break
223
224
case 0 // direction
225
object.direction = editor.variableValue
226
object.direction &= 1
227
break
228
229
end switch
230
end if
231
end event
232
233
234
event RSDKDraw
235
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
236
end event
237
238
239
event RSDKLoad
240
LoadSpriteSheet("MCZ/Objects.gif")
241
SpriteFrame(-32, -24, 64, 48, 136, 66)
242
243
// Redundant to the actual direction attribute, but this helps to highlight this over property value
244
AddEditorVariable("direction")
245
SetActiveVariable("direction")
246
AddEnumVariable("Left", 0)
247
AddEnumVariable("Right", 1)
248
249
// May as well chuck this here too, y'know?
250
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
251
end event
252
253