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/RingPlatform.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Ring 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.store.x
13
private alias object.value1 : object.store.y
14
private alias object.value2 : object.roundedPos // no subpixel position
15
16
// Player aliases
17
private alias object.xpos : player.xpos
18
private alias object.ypos : player.ypos
19
20
21
// ========================
22
// Function Declarations
23
// ========================
24
25
reserve function RingPlatform_DebugDraw
26
reserve function RingPlatform_DebugSpawn
27
28
29
// ========================
30
// Tables
31
// ========================
32
33
// Unused table, possibly meant to hold values before this object was optimized
34
// Coincidentally this object is made out of 6 rings, 6*2 = 12, it maybe means something if you squint hard enough
35
private table RingPlatform_unusedTable[12]
36
37
38
// ========================
39
// Function Definitions
40
// ========================
41
42
private function RingPlatform_DebugDraw
43
DrawSprite(0)
44
end function
45
46
47
private function RingPlatform_DebugSpawn
48
CreateTempObject(TypeName[Ring Platform], 0, object.xpos, object.ypos)
49
object[tempObjectPos].drawOrder = 4
50
object[tempObjectPos].direction = object.direction
51
end function
52
53
54
// ========================
55
// Events
56
// ========================
57
58
event ObjectUpdate
59
temp0 = object.angle
60
61
// Rotate the object based on which direction it's facing
62
if object.direction == FLIP_NONE
63
object.angle++
64
else
65
object.angle--
66
end if
67
68
// Backup the object's position
69
temp6 = object.xpos
70
temp7 = object.ypos
71
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
72
73
// Setup some useful numbers
74
temp0 >>= 1
75
temp5 = object.angle
76
temp5 >>= 1
77
Cos256(temp2, temp0)
78
temp2 <<= 12
79
Sin256(temp3, temp0)
80
temp3 <<= 12
81
Cos256(temp0, temp5)
82
temp0 <<= 12
83
Sin256(temp1, temp5)
84
temp1 <<= 12
85
86
object.store.x = object.xpos
87
object.store.y = object.ypos
88
89
// This object uses every temp available (and even then some more!) so here's a short list of what they all are
90
// - temp0:
91
// - curCos
92
// - temp1:
93
// - curSin
94
// - temp2:
95
// - prevCos
96
// - temp3:
97
// - prevSin
98
// - temp4:
99
// - pieceNum
100
// - temp5:
101
// - curAngle
102
// - temp6:
103
// - backupPos.x
104
// - temp7:
105
// - backupPos.y
106
// - object.roundedPos
107
// - temporary in spirit, holds the rounded position of the object in calculations
108
109
temp4 = 0
110
while temp4 < 6
111
BoxCollisionTest(C_SOLID, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
112
if checkResult == COL_TOP
113
temp5 = object.store.x
114
temp5 &= 0xFFFF0000
115
object.roundedPos = object.xpos
116
object.roundedPos &= 0xFFFF0000
117
temp5 -= object.roundedPos
118
player[currentPlayer].xpos += temp5
119
120
temp5 = object.store.y
121
temp5 &= 0xFFFF0000
122
object.roundedPos = object.ypos
123
object.roundedPos &= 0xFFFF0000
124
temp5 -= object.roundedPos
125
player[currentPlayer].ypos += temp5
126
end if
127
128
object.xpos += temp2
129
object.ypos += temp3
130
object.store.x += temp0
131
object.store.y += temp1
132
temp4++
133
loop
134
135
// Restore the object's position
136
object.xpos = temp6
137
object.ypos = temp7
138
next
139
end event
140
141
142
event ObjectDraw
143
temp5 = object.angle
144
temp5 >>= 1
145
temp0 = object.xpos
146
temp1 = object.ypos
147
Cos256(temp2, temp5)
148
temp2 <<= 12
149
150
Sin256(temp3, temp5)
151
temp3 <<= 12
152
153
temp4 = 0
154
while temp4 < 6
155
DrawSpriteXY(0, temp0, temp1)
156
temp0 += temp2
157
temp1 += temp3
158
temp4++
159
loop
160
end event
161
162
163
event ObjectStartup
164
LoadSpriteSheet("Global/Items.gif")
165
166
foreach (TypeName[Ring Platform], arrayPos0, ALL_ENTITIES)
167
object[arrayPos0].drawOrder = 4
168
next
169
170
// 0 - First frame of the ring animation
171
// You don't see that many scripts where the foreach is between the LoadSpriteSheet and SpriteFrames, this is one of the few that does it in v4
172
SpriteFrame(-8, -8, 16, 16, 1, 1)
173
174
// Add this Object to the Debug Item list
175
SetTableValue(TypeName[Ring Platform], DebugMode_ObjCount, DebugMode_TypesTable)
176
SetTableValue(RingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
177
SetTableValue(RingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
178
DebugMode_ObjCount++
179
end event
180
181
182
// ========================
183
// Editor Events
184
// ========================
185
186
event RSDKEdit
187
if editor.returnVariable == true
188
switch editor.variableID
189
case EDIT_VAR_PROPVAL // property value
190
checkResult = object.propertyValue
191
break
192
193
case 0 // rotateDir
194
checkResult = object.direction
195
break
196
197
end switch
198
else
199
switch editor.variableID
200
case EDIT_VAR_PROPVAL // property value
201
object.propertyValue = editor.variableValue
202
break
203
204
case 0 // rotateDir
205
object.direction = editor.variableValue
206
break
207
208
end switch
209
end if
210
end event
211
212
213
event RSDKDraw
214
temp5 = 64
215
216
temp0 = object.xpos
217
temp1 = object.ypos
218
Cos256(temp2, temp5)
219
temp2 <<= 12
220
221
Sin256(temp3, temp5)
222
temp3 <<= 12
223
224
temp4 = 0
225
while temp4 < 6
226
DrawSpriteXY(0, temp0, temp1)
227
temp0 += temp2
228
temp1 += temp3
229
temp4++
230
loop
231
end event
232
233
234
event RSDKLoad
235
LoadSpriteSheet("Global/Items.gif")
236
SpriteFrame(-8, -8, 16, 16, 1, 1)
237
238
AddEditorVariable("rotateDir")
239
SetActiveVariable("rotateDir")
240
AddEnumVariable("Clockwise", 0)
241
AddEnumVariable("Counter-Clockwise", 1)
242
end event
243
244