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/SLZ/SwingPlat.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Swing 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.propertyValue : object.length
13
14
private alias object.value0 : object.swingAngle
15
private alias object.value1 : object.drawPos.x
16
private alias object.value2 : object.drawPos.y
17
private alias object.value3 : object.collisionOffset.x
18
private alias object.value4 : object.collisionOffset.y
19
20
// Player Aliases
21
private alias object.xpos : player.xpos
22
private alias object.ypos : player.ypos
23
24
private alias object.value17 : debugMode.currentSelection
25
26
27
// ========================
28
// Function Declarations
29
// ========================
30
31
reserve function SwingPlatform_DebugDraw
32
reserve function SwingPlatform_DebugSpawn
33
34
35
// ========================
36
// Static Values
37
// ========================
38
39
private value SwingPlatform_startDebugID = 0
40
41
42
// ========================
43
// Function Definitions
44
// ========================
45
46
private function SwingPlatform_DebugDraw
47
temp7 = debugMode[0].currentSelection
48
temp7 -= SwingPlatform_startDebugID
49
50
// Draw the post
51
DrawSprite(0)
52
53
// Draw the chains
54
temp0 = 0
55
temp1 = 16
56
while temp0 < temp7
57
Cos(temp2, 128)
58
temp2 *= temp1
59
temp2 <<= 7
60
temp2 += object.xpos
61
Sin(temp3, 128)
62
temp3 *= temp1
63
temp3 <<= 7
64
temp3 += object.ypos
65
DrawSpriteXY(1, temp2, temp3)
66
temp0++
67
temp1 += 16
68
loop
69
70
// Draw the platform itself
71
temp1 -= 8
72
Cos(temp2, 128)
73
temp2 *= temp1
74
temp2 <<= 7
75
temp2 += object.xpos
76
77
Sin(temp3, 128)
78
temp3 *= temp1
79
temp3 <<= 7
80
temp3 += object.ypos
81
82
DrawSpriteXY(2, temp2, temp3)
83
end function
84
85
86
private function SwingPlatform_DebugSpawn
87
temp0 = debugMode[0].currentSelection
88
temp0 -= SwingPlatform_startDebugID
89
90
CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)
91
object[tempObjectPos].direction = object.direction
92
end function
93
94
95
// ========================
96
// Events
97
// ========================
98
99
event ObjectUpdate
100
// Backup the object's position, as it'll need to be moved for collision checks
101
temp2 = object.xpos
102
temp3 = object.ypos
103
104
GetTableValue(object.swingAngle, 12, StageSetup_oscillationTable)
105
object.swingAngle >>= 8
106
if object.direction == FLIP_X
107
object.swingAngle ^= 255
108
object.swingAngle += 129
109
end if
110
object.swingAngle <<= 1
111
112
temp1 = object.length
113
temp1++
114
temp1 <<= 4
115
temp1 -= 8
116
object.xpos = object.drawPos.x
117
object.ypos = object.drawPos.y
118
119
Cos(object.collisionOffset.x, object.swingAngle)
120
object.collisionOffset.x *= temp1
121
object.collisionOffset.x <<= 7
122
object.collisionOffset.x += temp2
123
object.collisionOffset.x &= 0xFFFF0000
124
object.drawPos.x = object.collisionOffset.x
125
object.collisionOffset.x -= object.xpos
126
127
Sin(object.collisionOffset.y, object.swingAngle)
128
object.collisionOffset.y *= temp1
129
object.collisionOffset.y <<= 7
130
object.collisionOffset.y += temp3
131
object.collisionOffset.y &= 0xFFFF0000
132
object.drawPos.y = object.collisionOffset.y
133
object.collisionOffset.y -= object.ypos
134
135
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
136
BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -16, 32, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
137
if checkResult == true
138
player[currentPlayer].xpos += object.collisionOffset.x
139
player[currentPlayer].ypos += object.collisionOffset.y
140
else
141
BoxCollisionTest(C_TOUCH, object.entityPos, -32, 0, 32, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
142
if checkResult == true
143
CallFunction(Player_Hit)
144
else
145
BoxCollisionTest(C_TOUCH, object.entityPos, -16, 8, 16, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
146
if checkResult == true
147
CallFunction(Player_Hit)
148
end if
149
end if
150
end if
151
next
152
// Move the object back to its actual position
153
object.xpos = temp2
154
object.ypos = temp3
155
end event
156
157
158
event ObjectDraw
159
DrawSprite(0)
160
161
temp0 = 0
162
temp1 = 16
163
while temp0 < object.length
164
Cos(temp2, object.swingAngle)
165
temp2 *= temp1
166
temp2 <<= 7
167
temp2 += object.xpos
168
Sin(temp3, object.swingAngle)
169
temp3 *= temp1
170
temp3 <<= 7
171
temp3 += object.ypos
172
DrawSpriteXY(1, temp2, temp3)
173
temp0++
174
temp1 += 16
175
loop
176
177
temp1 -= 8 // this line.. doesn't really mean much
178
DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)
179
end event
180
181
182
event ObjectStartup
183
LoadSpriteSheet("SLZ/Objects.gif")
184
SpriteFrame(-8, -8, 16, 16, 173, 141)
185
SpriteFrame(-8, -8, 16, 16, 173, 158)
186
SpriteFrame(-44, -16, 88, 46, 84, 141)
187
188
temp0 = 0
189
SwingPlatform_startDebugID = DebugMode_ObjCount
190
SwingPlatform_startDebugID--
191
while temp0 < 8
192
SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)
193
SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
194
SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
195
DebugMode_ObjCount++
196
temp0++
197
loop
198
end event
199
200
201
event RSDKDraw
202
DrawSprite(0)
203
temp0 = 0
204
temp1 = 16
205
206
while temp0 < object.length
207
Cos(temp2, 128)
208
temp2 *= temp1
209
temp2 <<= 7
210
temp2 += object.xpos
211
Sin(temp3, 128)
212
temp3 *= temp1
213
temp3 <<= 7
214
temp3 += object.ypos
215
DrawSpriteXY(1, temp2, temp3)
216
temp0++
217
temp1 += 16
218
loop
219
220
temp1 -= 8
221
Cos(temp2, 128)
222
temp2 *= temp1
223
temp2 <<= 7
224
temp2 += object.xpos
225
Sin(temp3, 128)
226
temp3 *= temp1
227
temp3 <<= 7
228
temp3 += object.ypos
229
DrawSpriteXY(2, temp2, temp3)
230
end event
231
232
233
event RSDKLoad
234
LoadSpriteSheet("SLZ/Objects.gif")
235
SpriteFrame(-8, -8, 16, 16, 173, 141)
236
SpriteFrame(-8, -8, 16, 16, 173, 158)
237
SpriteFrame(-44, -16, 88, 46, 84, 141)
238
239
SetVariableAlias(ALIAS_VAR_PROPVAL, "length")
240
end event
241
242