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/VDropBridge.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: V 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 0 : VDROPBRIDGE_CLOSED
13
private alias 1 : VDROPBRIDGE_OPENING_L
14
private alias 2 : VDROPBRIDGE_OPENING_R
15
private alias 3 : VDROPBRIDGE_OPEN_L
16
private alias 4 : VDROPBRIDGE_OPEN_R
17
18
// Activator switch alias
19
private alias object.propertyValue : pullSwitch.pulled
20
21
22
// ========================
23
// Function Declarations
24
// ========================
25
26
reserve function VDropBridge_DebugDraw
27
reserve function VDropBridge_DebugSpawn
28
29
30
// ========================
31
// Function Definitions
32
// ========================
33
34
private function VDropBridge_DebugDraw
35
DrawSprite(0)
36
end function
37
38
39
private function VDropBridge_DebugSpawn
40
CreateTempObject(TypeName[V Drop Bridge], 0, object.xpos, object.ypos)
41
object[tempObjectPos].direction = object.direction
42
object[tempObjectPos].angle = 256
43
end function
44
45
46
// ========================
47
// Events
48
// ========================
49
50
event ObjectUpdate
51
switch object.state
52
case VDROPBRIDGE_CLOSED
53
if pullSwitch[-1].pulled == true
54
if object.direction == FLIP_NONE
55
object.state = VDROPBRIDGE_OPENING_R
56
else
57
object.state = VDROPBRIDGE_OPENING_L
58
end if
59
60
if object.priority != PRIORITY_XBOUNDS_DESTROY
61
object.priority = PRIORITY_ACTIVE
62
end if
63
64
PlaySfx(SfxName[Drop Bridge], false)
65
end if
66
67
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
68
BoxCollisionTest(C_SOLID, object.entityPos, -8, -136, 8, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
69
next
70
break
71
72
case VDROPBRIDGE_OPENING_L
73
if object.angle < 384
74
object.angle += 2
75
else
76
object.state = VDROPBRIDGE_OPEN_L
77
PlaySfx(SfxName[Drop Bridge 2], false)
78
end if
79
80
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
81
BoxCollisionTest(C_SOLID, object.entityPos, -8, -136, 8, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
82
next
83
break
84
85
case VDROPBRIDGE_OPENING_R
86
if object.angle > 128
87
object.angle -= 2
88
else
89
object.state = VDROPBRIDGE_OPEN_R
90
PlaySfx(SfxName[Drop Bridge 2], false)
91
end if
92
93
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
94
BoxCollisionTest(C_SOLID, object.entityPos, -8, -136, 8, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
95
next
96
break
97
98
case VDROPBRIDGE_OPEN_L
99
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
100
BoxCollisionTest(C_SOLID, object.entityPos, -136, -8, -8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
101
next
102
break
103
104
case VDROPBRIDGE_OPEN_R
105
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
106
BoxCollisionTest(C_SOLID, object.entityPos, 8, -8, 136, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
107
next
108
break
109
110
end switch
111
112
if object.outOfBounds == true
113
if object.priority != PRIORITY_XBOUNDS_DESTROY
114
// If offscreen, reset this object
115
object.angle = 256
116
object.state = VDROPBRIDGE_CLOSED
117
end if
118
end if
119
end event
120
121
122
event ObjectDraw
123
// Draw all the bridge segments with a loop
124
temp0 = 0
125
temp1 = 0x800
126
while temp0 < 8
127
Sin(temp2, object.angle)
128
temp2 *= temp1
129
temp2 += object.xpos
130
131
Cos(temp3, object.angle)
132
temp3 *= temp1
133
temp3 += object.ypos
134
135
DrawSpriteXY(0, temp2, temp3)
136
137
temp0++
138
temp1 += 0x800
139
loop
140
end event
141
142
143
event ObjectStartup
144
LoadSpriteSheet("MCZ/Objects.gif")
145
146
SpriteFrame(-8, -8, 16, 16, 135, 131)
147
148
foreach (TypeName[V Drop Bridge], arrayPos0, ALL_ENTITIES)
149
object[arrayPos0].angle = 256
150
object[arrayPos0].direction = object[arrayPos0].propertyValue
151
object[arrayPos0].direction &= FLIP_X
152
next
153
154
SetTableValue(TypeName[V Drop Bridge], DebugMode_ObjCount, DebugMode_TypesTable)
155
SetTableValue(VDropBridge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
156
SetTableValue(VDropBridge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
157
DebugMode_ObjCount++
158
end event
159
160
161
// ========================
162
// Editor Events
163
// ========================
164
165
event RSDKEdit
166
if editor.returnVariable == true
167
switch editor.variableID
168
case EDIT_VAR_PROPVAL // property value
169
checkResult = object.propertyValue
170
break
171
172
case 0 // openDir
173
checkResult = object.propertyValue
174
checkResult &= 1
175
break
176
177
end switch
178
else
179
switch editor.variableID
180
case EDIT_VAR_PROPVAL // property value
181
object.propertyValue = editor.variableValue
182
break
183
184
case 0 // openDir
185
object.propertyValue = editor.variableValue
186
break
187
188
end switch
189
end if
190
end event
191
192
193
event RSDKDraw
194
temp0 = 0
195
temp1 = 0x800
196
while temp0 < 8
197
Sin(temp2, 256)
198
temp2 *= temp1
199
temp2 += object.xpos
200
Cos(temp3, 256)
201
temp3 *= temp1
202
temp3 += object.ypos
203
DrawSpriteXY(0, temp2, temp3)
204
temp0++
205
temp1 += 0x800
206
loop
207
208
if editor.showGizmos == true
209
editor.drawingOverlay = true
210
211
// Draw semi-transparent version of how the bridge will be when lowered
212
213
if object.propertyValue == 0
214
temp4 = 128
215
else
216
temp4 = 384
217
end if
218
219
object.inkEffect = INK_BLEND
220
221
temp0 = 0
222
temp1 = 0x800
223
while temp0 < 8
224
Sin(temp2, temp4)
225
temp2 *= temp1
226
temp2 += object.xpos
227
Cos(temp3, temp4)
228
temp3 *= temp1
229
temp3 += object.ypos
230
DrawSpriteFX(0, FX_INK, temp2, temp3)
231
temp0++
232
temp1 += 0x800
233
loop
234
235
editor.drawingOverlay = false
236
end if
237
end event
238
239
240
event RSDKLoad
241
LoadSpriteSheet("MCZ/Objects.gif")
242
SpriteFrame(-8, -8, 16, 16, 135, 131)
243
244
AddEditorVariable("openDir")
245
SetActiveVariable("openDir")
246
AddEnumVariable("Right", 0)
247
AddEnumVariable("Left", 1)
248
end event
249
250