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/HDropBridge.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: H Drop Bridge 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.left.angle
13
private alias object.value2 : object.right.angle
14
private alias object.value3 : object.left.x
15
private alias object.value4 : object.right.x
16
17
private alias 0 : HDROPBRIDGE_CLOSED
18
private alias 1 : HDROPBRIDGE_OPENING
19
private alias 2 : HDROPBRIDGE_OPENED
20
21
// Activator Switch Aliases
22
private alias object.propertyValue : pullSwitch.pulled
23
24
25
// ========================
26
// Function Declarations
27
// ========================
28
29
reserve function HDropBridge_DebugDraw
30
reserve function HDropBridge_DebugSpawn
31
32
33
// ========================
34
// Function Definitions
35
// ========================
36
37
private function HDropBridge_DebugDraw
38
temp0 = object.xpos
39
temp1 = 0
40
temp0 -= 0x380000
41
while temp1 < 8
42
DrawSpriteXY(0, temp0, object.ypos)
43
temp0 += 0x100000
44
temp1++
45
loop
46
end function
47
48
49
private function HDropBridge_DebugSpawn
50
CreateTempObject(TypeName[H Drop Bridge], 0, object.xpos, object.ypos)
51
object[tempObjectPos].drawOrder = 4
52
object[tempObjectPos].left.angle = 0
53
object[tempObjectPos].right.angle = 256
54
object[tempObjectPos].left.x = object[tempObjectPos].xpos
55
object[tempObjectPos].left.x -= 0x380000
56
object[tempObjectPos].right.x = object[tempObjectPos].xpos
57
object[tempObjectPos].right.x += 0x380000
58
end function
59
60
61
// ========================
62
// Events
63
// ========================
64
65
event ObjectUpdate
66
switch object.state
67
case HDROPBRIDGE_CLOSED
68
// object[-1] is a switch of either the normal or vine variety
69
if pullSwitch[-1].pulled == true
70
object.state++
71
PlaySfx(SfxName[Flapping Door], false)
72
if object.priority != PRIORITY_XBOUNDS_DESTROY
73
object.priority = PRIORITY_ACTIVE
74
end if
75
end if
76
77
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
78
BoxCollisionTest(C_SOLID, object.entityPos, -64, -8, 64, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
79
next
80
break
81
82
case HDROPBRIDGE_OPENING
83
if object.left.angle < 128
84
object.left.angle += 8
85
object.right.angle -= 8
86
else
87
object.state++
88
end if
89
// [Fallthrough]
90
case HDROPBRIDGE_OPENED
91
temp6 = object.xpos
92
temp7 = object.ypos
93
94
temp0 = 0
95
temp1 = 0
96
while temp0 < 4
97
Cos(object.xpos, object.left.angle)
98
object.xpos *= temp1
99
object.xpos += object.left.x
100
Sin(object.ypos, object.left.angle)
101
object.ypos *= temp1
102
object.ypos += temp7
103
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
104
BoxCollisionTest(C_SOLID, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
105
next
106
temp0++
107
temp1 += 0x800
108
loop
109
110
temp0 = 0
111
temp1 = 0
112
while temp0 < 4
113
Cos(object.xpos, object.right.angle)
114
object.xpos *= temp1
115
object.xpos += object.right.x
116
Sin(object.ypos, object.right.angle)
117
object.ypos *= temp1
118
object.ypos += temp7
119
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
120
BoxCollisionTest(C_SOLID, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
121
next
122
temp0++
123
temp1 += 0x800
124
loop
125
object.xpos = temp6
126
object.ypos = temp7
127
break
128
129
end switch
130
131
if object.outOfBounds == true
132
if object.priority != PRIORITY_XBOUNDS_DESTROY
133
object.left.angle = 0
134
object.right.angle = 256
135
object.state = HDROPBRIDGE_CLOSED
136
end if
137
end if
138
end event
139
140
141
event ObjectDraw
142
// Draw the left 4 pieces first
143
temp0 = 0
144
temp1 = 0
145
while temp0 < 4
146
Cos(temp2, object.left.angle)
147
temp2 *= temp1
148
temp2 += object.left.x
149
Sin(temp3, object.left.angle)
150
temp3 *= temp1
151
temp3 += object.ypos
152
DrawSpriteXY(0, temp2, temp3)
153
temp0++
154
temp1 += 0x800
155
loop
156
157
// Then draw the right 4 pieces afterwards
158
temp0 = 0
159
temp1 = 0
160
while temp0 < 4
161
Cos(temp2, object.right.angle)
162
temp2 *= temp1
163
temp2 += object.right.x
164
Sin(temp3, object.right.angle)
165
temp3 *= temp1
166
temp3 += object.ypos
167
DrawSpriteXY(0, temp2, temp3)
168
temp0++
169
temp1 += 0x800
170
loop
171
end event
172
173
174
event ObjectStartup
175
LoadSpriteSheet("MCZ/Objects.gif")
176
177
SpriteFrame(-8, -8, 16, 16, 135, 131)
178
179
foreach (TypeName[H Drop Bridge], arrayPos0, ALL_ENTITIES)
180
object[arrayPos0].drawOrder = 4
181
object[arrayPos0].left.angle = 0
182
object[arrayPos0].right.angle = 256
183
object[arrayPos0].left.x = object[arrayPos0].xpos
184
object[arrayPos0].left.x -= 0x380000
185
object[arrayPos0].right.x = object[arrayPos0].xpos
186
object[arrayPos0].right.x += 0x380000
187
next
188
189
// Add this object to the debug item list
190
SetTableValue(TypeName[H Drop Bridge], DebugMode_ObjCount, DebugMode_TypesTable)
191
SetTableValue(HDropBridge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
192
SetTableValue(HDropBridge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
193
DebugMode_ObjCount++
194
end event
195
196
197
// ========================
198
// Editor Events
199
// ========================
200
201
event RSDKDraw
202
temp0 = 0
203
temp1 = 0
204
while temp0 < 4
205
Cos(temp2, 0)
206
temp2 *= temp1
207
temp2 += object.xpos
208
temp2 -= 0x380000
209
Sin(temp3, 0)
210
temp3 *= temp1
211
temp3 += object.ypos
212
DrawSpriteXY(0, temp2, temp3)
213
temp0++
214
temp1 += 0x800
215
loop
216
217
temp0 = 0
218
temp1 = 0
219
while temp0 < 4
220
Cos(temp2, 256)
221
temp2 *= temp1
222
temp2 += object.xpos
223
temp2 += 0x380000
224
Sin(temp3, 256)
225
temp3 *= temp1
226
temp3 += object.ypos
227
DrawSpriteXY(0, temp2, temp3)
228
temp0++
229
temp1 += 0x800
230
loop
231
232
if editor.showGizmos == true
233
editor.drawingOverlay = true
234
235
// Draw a semi-transparent version of how the bridge will look when opened
236
237
object.inkEffect = INK_BLEND
238
239
temp0 = 0
240
temp1 = 0
241
while temp0 < 4
242
Cos(temp2, 128)
243
temp2 *= temp1
244
temp2 += object.xpos
245
temp2 -= 0x380000
246
Sin(temp3, 128)
247
temp3 *= temp1
248
temp3 += object.ypos
249
DrawSpriteXY(0, FX_INK, temp2, temp3)
250
temp0++
251
temp1 += 0x800
252
loop
253
254
temp0 = 0
255
temp1 = 0
256
while temp0 < 4
257
Cos(temp2, 128)
258
temp2 *= temp1
259
temp2 += object.xpos
260
temp2 += 0x380000
261
Sin(temp3, 128)
262
temp3 *= temp1
263
temp3 += object.ypos
264
DrawSpriteXY(0, FX_INK, temp2, temp3)
265
temp0++
266
temp1 += 0x800
267
loop
268
269
editor.drawingOverlay = false
270
end if
271
end event
272
273
274
event RSDKLoad
275
LoadSpriteSheet("MCZ/Objects.gif")
276
SpriteFrame(-8, -8, 16, 16, 135, 131)
277
278
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
279
end event
280
281