Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/GHZ/CLedgeLeft.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: C Ledge Left 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 : CLEDGEL_ACTIVE
16
private alias 1 : CLEDGEL_COLLAPSE
17
private alias 2 : CLEDGEL_COLLAPSED
18
private alias 3 : CLEDGEL_NONE
19
private alias 4 : CLEDGEL_TILEDELAY
20
private alias 5 : CLEDGEL_TILEFALL
21
22
// Player Aliases
23
private alias object.xpos : player.xpos
24
private alias object.ypos : player.ypos
25
private alias object.yvel : player.yvel
26
27
28
// ========================
29
// Function Declarations
30
// ========================
31
32
reserve function CLedgeLeft_DebugDraw
33
reserve function CLedgeLeft_DebugSpawn
34
35
36
// ========================
37
// Tables
38
// ========================
39
40
// This table is used by CLedgeRight as well, which is why it's public
41
// (Neat note - in earlier versions of S1 this was a raw file, but after tables were introduced it was made to be like this instead)
42
public table CLedgeLeft_heightArray
43
32, 32, 32, 32, 32, 32
44
32, 32, 33, 33, 34, 34
45
35, 35, 36, 36, 37, 37
46
38, 38, 39, 39, 40, 40
47
41, 41, 42, 42, 43, 43
48
44, 44, 45, 45, 46, 46
49
47, 47, 48, 48, 48, 48
50
48, 48, 48, 48, 48, 48
51
end table
52
53
54
// ========================
55
// Function Definitions
56
// ========================
57
58
private function CLedgeLeft_DebugDraw
59
DrawSprite(0)
60
end function
61
62
63
private function CLedgeLeft_DebugSpawn
64
CreateTempObject(TypeName[C Ledge Left], 0, object.xpos, object.ypos)
65
end function
66
67
68
// ========================
69
// Events
70
// ========================
71
72
event ObjectUpdate
73
switch object.state
74
case CLEDGEL_NONE
75
break
76
77
case CLEDGEL_COLLAPSE
78
if object.timer < 10
79
object.timer++
80
else
81
object.frame = 1
82
temp0 = 0
83
temp3 = object.ypos
84
temp3 -= 0x380000
85
temp4 = 10
86
while temp0 < 6
87
temp1 = 0
88
temp2 = object.xpos
89
temp2 -= 0x280000
90
while temp1 < 6
91
CreateTempObject(TypeName[C Ledge Left], object.frame, temp2, temp3)
92
object[tempObjectPos].state = CLEDGEL_TILEDELAY
93
object[tempObjectPos].delay = temp4
94
object.frame++
95
temp1++
96
temp2 += 0x100000
97
temp4 += 4
98
loop
99
temp4 -= 26
100
temp0++
101
temp3 += 0x100000
102
loop
103
104
// In initial versions this just played Sfx[Ledge Break], but a later update changed it
105
// and made it play a sound across both ears
106
107
PlaySfx(SfxName[Ledge Break L], false)
108
SetSfxAttributes(SfxName[Ledge Break L], -1, -100)
109
PlaySfx(SfxName[Ledge Break R], false)
110
SetSfxAttributes(SfxName[Ledge Break R], -1, 100)
111
112
object.timer = 0
113
114
object.state++
115
end if
116
break
117
118
case CLEDGEL_COLLAPSED
119
if object.timer < 20
120
object.timer++
121
else
122
object.timer = 0
123
object.state++
124
ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, object.xpos, object.ypos)
125
end if
126
break
127
128
case CLEDGEL_NONE
129
break
130
131
case CLEDGEL_TILEDELAY
132
if object.timer < object.delay
133
object.timer++
134
else
135
object.timer = 0
136
object.state++
137
end if
138
break
139
140
case CLEDGEL_TILEFALL
141
object.ypos += object.yvel
142
object.yvel += 0x4000
143
if object.outOfBounds == true
144
object.type = TypeName[Blank Object]
145
end if
146
break
147
148
end switch
149
150
if object.state < CLEDGEL_NONE
151
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
152
if player[currentPlayer].yvel >= 0
153
temp0 = player[currentPlayer].xpos
154
temp0 -= object.xpos
155
temp0 >>= 17
156
temp0 += 24
157
if temp0 < 0
158
temp0 = 0
159
end if
160
if temp0 > 47
161
temp0 = 47
162
end if
163
temp2 = 47
164
temp2 -= temp0
165
GetTableValue(temp1, temp2, CLedgeLeft_heightArray)
166
temp1 -= 84
167
temp0 = temp1
168
temp0 += 32
169
BoxCollisionTest(C_PLATFORM, object.entityPos, -48, temp1, 48, temp0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
170
if checkResult == true
171
player[currentPlayer].ypos += 0x40000
172
if object.state == CLEDGEL_ACTIVE
173
object.state = CLEDGEL_COLLAPSE
174
end if
175
end if
176
end if
177
next
178
end if
179
end event
180
181
182
event ObjectDraw
183
switch object.state
184
case CLEDGEL_ACTIVE
185
case CLEDGEL_COLLAPSE
186
DrawSprite(0)
187
break
188
189
case CLEDGEL_TILEDELAY
190
case CLEDGEL_TILEFALL
191
DrawSprite(object.propertyValue)
192
break
193
194
case CLEDGEL_COLLAPSED
195
case CLEDGEL_NONE
196
default
197
break
198
199
end switch
200
end event
201
202
203
event ObjectStartup
204
LoadSpriteSheet("GHZ/Objects.gif")
205
206
// 0 - Full Platform Frame
207
SpriteFrame(-48, -64, 96, 96, 1, 51)
208
209
// All the Platform "Tile" Frames are done in a loop
210
temp0 = 51
211
while temp0 < 147 // sprY + height (51 + 96 = 147)
212
temp1 = 1
213
while temp1 < 97 // sprX + width (1 + 96 = 97)
214
SpriteFrame(-8, -8, 16, 16, temp1, temp0)
215
temp1 += 16
216
loop
217
218
temp0 += 16
219
loop
220
221
// This was hangin' out in the earliest S1 builds
222
// It's safe to assume that this is how it was done pre-tables, given that this object was done while the RSDKv4 spec was still being developed
223
// (Also separate other note - LoadTextFile had 3 paramters back then but in current versions in only has 2, that's another neat little change)
224
// LoadTextFile(MENU_2, "Data/Game/Misc/CLedgeMask.bin", false)
225
226
SetTableValue(TypeName[C Ledge Left], DebugMode_ObjCount, DebugMode_TypesTable)
227
SetTableValue(CLedgeLeft_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
228
SetTableValue(CLedgeLeft_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
229
DebugMode_ObjCount++
230
end event
231
232
233
// ========================
234
// Editor Events
235
// ========================
236
237
event RSDKDraw
238
DrawSprite(0)
239
240
if editor.showGizmos == true
241
editor.drawingOverlay = true
242
243
temp0 = 48; temp1 = 48; temp2 = 48; temp3 = 48;
244
CallFunction(EditorHelpers_DrawHitbox)
245
246
editor.drawingOverlay = false
247
end if
248
end event
249
250
251
event RSDKLoad
252
LoadSpriteSheet("GHZ/Objects.gif")
253
SpriteFrame(-48, -64, 96, 96, 1, 51)
254
255
// Although used by the object, it shouldn't be set by the editor
256
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
257
end event
258
259