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/CPZ/BumpingPlatform.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Bumping Platform 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.platformPos1.x
13
private alias object.value1 : object.platformPos2.x
14
private alias object.value2 : object.boundsL
15
private alias object.value3 : object.boundsR
16
17
private alias 0 : BUMPINGPLATFORM_USE1PLATFORM
18
private alias 1 : BUMPINGPLATFORM_USE2PLATFORM
19
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
23
24
// ========================
25
// Function Declarations
26
// ========================
27
28
reserve function BumpingPlatform_DebugDraw
29
reserve function BumpingPlatform_DebugSpawn
30
31
32
// ========================
33
// Tables
34
// ========================
35
36
private table BumpingPlatform_stateTable
37
0 // BUMPINGPLATFORM_USE1PLATFORM
38
1 // BUMPINGPLATFORM_USE2PLATFORM
39
1 // BUMPINGPLATFORM_USE2PLATFORM
40
0 // BUMPINGPLATFORM_USE1PLATFORM
41
end table
42
43
private table BumpingPlatform_boundsTable
44
0x680000
45
0xA80000
46
0xE80000
47
0x680000
48
end table
49
50
private table BumpingPlatform_offsetTable
51
-0x680000, 0x000000
52
-0xB00000, 0x400000
53
-0x780000, 0x800000
54
0x670000, 0x000000
55
end table
56
57
58
// ========================
59
// Function Definitions
60
// ========================
61
62
private function BumpingPlatform_DebugDraw
63
DrawSprite(0)
64
end function
65
66
67
private function BumpingPlatform_DebugSpawn
68
CreateTempObject(TypeName[Bumping Platform], 0, object.xpos, object.ypos)
69
object[tempObjectPos].state = BUMPINGPLATFORM_USE1PLATFORM
70
object[tempObjectPos].boundsL = object.xpos
71
object[tempObjectPos].boundsL -= 0x680000
72
object[tempObjectPos].boundsR = object.xpos
73
object[tempObjectPos].boundsR += 0x680000
74
object[tempObjectPos].platformPos1.x = object.xpos
75
object[tempObjectPos].platformPos1.x += -0x680000
76
object[tempObjectPos].platformPos2.x = object.xpos
77
object[tempObjectPos].platformPos2.x += 0x000000
78
end function
79
80
81
// ========================
82
// Events
83
// ========================
84
85
event ObjectUpdate
86
temp6 = object.platformPos1.x
87
temp7 = object.platformPos2.x
88
89
GetBit(temp0, object.direction, 0)
90
if temp0 == FLIP_NONE
91
object.platformPos1.x += 0x10000
92
if object.platformPos1.x >= object.boundsR
93
SetBit(object.direction, 0, FLIP_X)
94
end if
95
else
96
object.platformPos1.x -= 0x10000
97
if object.platformPos1.x <= object.boundsL
98
SetBit(object.direction, 0, FLIP_NONE)
99
end if
100
end if
101
102
if object.state == BUMPINGPLATFORM_USE2PLATFORM
103
// Check Platform 1 Bumping
104
if object.direction == FLIP_Y
105
temp0 = object.platformPos1.x
106
temp0 += 0x180000
107
temp1 = object.platformPos2.x
108
temp1 -= 0x180000
109
if temp0 == temp1
110
object.direction ^= FLIP_XY
111
end if
112
end if
113
114
if object.direction == FLIP_X
115
temp0 = object.platformPos1.x
116
temp0 -= 0x180000
117
temp1 = object.platformPos2.x
118
temp1 += 0x180000
119
if temp0 == temp1
120
object.direction ^= FLIP_XY
121
end if
122
end if
123
124
// Move Platform 2
125
GetBit(temp0, object.direction, 1)
126
if temp0 == FLIP_NONE
127
object.platformPos2.x += 0x10000
128
if object.platformPos2.x >= object.boundsR
129
SetBit(object.direction, 1, FLIP_X)
130
end if
131
else
132
object.platformPos2.x -= 0x10000
133
if object.platformPos2.x <= object.boundsL
134
SetBit(object.direction, 1, FLIP_NONE)
135
end if
136
end if
137
138
// Check Platform 2 Bumping
139
if object.direction == FLIP_Y
140
temp0 = object.platformPos1.x
141
temp0 += 0x180000
142
temp1 = object.platformPos2.x
143
temp1 -= 0x180000
144
if temp0 == temp1
145
object.direction ^= FLIP_XY
146
end if
147
end if
148
149
if object.direction == FLIP_X
150
temp0 = object.platformPos1.x
151
temp0 -= 0x180000
152
temp1 = object.platformPos2.x
153
temp1 += 0x180000
154
if temp0 == temp1
155
object.direction ^= FLIP_XY
156
end if
157
end if
158
end if
159
160
temp4 = object.platformPos1.x
161
temp5 = object.platformPos2.x
162
temp4 -= temp6
163
temp5 -= temp7
164
temp0 = object.xpos
165
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
166
object.xpos = temp6
167
BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
168
if checkResult == true
169
player[currentPlayer].xpos += temp4
170
end if
171
172
if object.state == BUMPINGPLATFORM_USE2PLATFORM
173
object.xpos = temp7
174
BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
175
if checkResult == true
176
player[currentPlayer].xpos += temp5
177
end if
178
end if
179
next
180
object.xpos = temp0
181
end event
182
183
184
event ObjectDraw
185
DrawSpriteXY(0, object.platformPos1.x, object.ypos)
186
if object.state == BUMPINGPLATFORM_USE2PLATFORM
187
DrawSpriteXY(0, object.platformPos2.x, object.ypos)
188
end if
189
end event
190
191
192
event ObjectStartup
193
LoadSpriteSheet("CPZ/Objects.gif")
194
SpriteFrame(-24, -8, 48, 14, 6, 204)
195
196
foreach (TypeName[Bumping Platform], arrayPos0, ALL_ENTITIES)
197
temp0 = object[arrayPos0].propertyValue
198
199
GetTableValue(object[arrayPos0].state, temp0, BumpingPlatform_stateTable)
200
201
GetTableValue(temp1, temp0, BumpingPlatform_boundsTable)
202
object[arrayPos0].boundsL = object[arrayPos0].xpos
203
object[arrayPos0].boundsL -= temp1
204
object[arrayPos0].boundsR = object[arrayPos0].xpos
205
object[arrayPos0].boundsR += temp1
206
temp0 <<= 1
207
208
GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)
209
object[arrayPos0].platformPos1.x = object[arrayPos0].xpos
210
object[arrayPos0].platformPos1.x += temp1
211
temp0++
212
213
GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)
214
object[arrayPos0].platformPos2.x = object[arrayPos0].xpos
215
object[arrayPos0].platformPos2.x += temp1
216
217
if object[arrayPos0].propertyValue == 2
218
object[arrayPos0].direction = FLIP_X
219
end if
220
221
object[arrayPos0].priority = PRIORITY_ACTIVE
222
next
223
224
SetTableValue(TypeName[Bumping Platform], DebugMode_ObjCount, DebugMode_TypesTable)
225
SetTableValue(BumpingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
226
SetTableValue(BumpingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
227
DebugMode_ObjCount++
228
end event
229
230
231
// ========================
232
// Editor Events
233
// ========================
234
235
event RSDKEdit
236
if editor.returnVariable == true
237
switch editor.variableID
238
case EDIT_VAR_PROPVAL // property value
239
checkResult = object.propertyValue
240
break
241
242
case 0 // type
243
checkResult = object.propertyValue
244
checkResult &= 3
245
break
246
247
end switch
248
else
249
switch editor.variableID
250
case EDIT_VAR_PROPVAL // property value
251
object.propertyValue = editor.variableValue
252
break
253
254
case 0 // type
255
object.propertyValue = editor.variableValue
256
object.propertyValue &= 3
257
break
258
259
end switch
260
end if
261
end event
262
263
264
event RSDKDraw
265
temp0 = object.propertyValue
266
temp0 <<= 1
267
268
GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)
269
// using temp2 as a object.platformPos1.x stand-in
270
temp2 = object.xpos
271
temp2 += temp1
272
temp0++
273
274
GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)
275
// and using temp3 as a object.platformPos2.x stand-in
276
temp3 = object.xpos
277
temp3 += temp1
278
279
DrawSpriteXY(0, temp2, object.ypos)
280
if object.state == BUMPINGPLATFORM_USE2PLATFORM
281
DrawSpriteXY(0, temp3, object.ypos)
282
end if
283
end event
284
285
286
event RSDKLoad
287
LoadSpriteSheet("CPZ/Objects.gif")
288
SpriteFrame(-24, -8, 48, 14, 6, 204)
289
290
AddEditorVariable("type")
291
SetActiveVariable("type")
292
AddEnumVariable("Small Gap (1 Platform, Moving Right)", 0)
293
AddEnumVariable("Large Gap (2 Platforms)", 1)
294
AddEnumVariable("Large Gap (2 Platforms)", 2)
295
AddEnumVariable("Small Gap (1 Platform, Moving Left)", 3)
296
end event
297
298