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/ChemicalBall.txt
1482 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Chemical Ball 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.timer
13
private alias object.value1 : object.interval
14
private alias object.value2 : object.moveType
15
private alias object.value3 : object.distance
16
private alias object.value4 : object.acceleration
17
private alias object.value6 : object.newYVel
18
private alias object.value7 : object.startPos.x
19
private alias object.value8 : object.startPos.y
20
21
// Player Aliases
22
private alias object.value17 : debugMode.currentSelection
23
24
25
// ========================
26
// Function Declarations
27
// ========================
28
29
reserve function ChemicalBall_HandleSetup
30
reserve function ChemicalBall_DebugDraw
31
reserve function ChemicalBall_DebugSpawn
32
reserve function ChemicalBall_TryPlayChemicalSfx
33
34
35
// ========================
36
// Static Values
37
// ========================
38
39
private value ChemicalBall_startDebugID = 0
40
41
42
// ========================
43
// Function Definitions
44
// ========================
45
46
private function ChemicalBall_HandleSetup
47
object[arrayPos0].xpos = object[arrayPos0].startPos.x
48
object[arrayPos0].ypos = object[arrayPos0].startPos.y
49
object[arrayPos0].timer = object[arrayPos0].interval
50
51
if object[arrayPos0].direction == FLIP_NONE
52
object[arrayPos0].distance = 0x600000
53
object[arrayPos0].acceleration = 0xB00
54
else
55
object[arrayPos0].distance = -0x600000
56
object[arrayPos0].acceleration = -0xB00
57
end if
58
59
object[arrayPos0].newYVel = -0x48000
60
object[arrayPos0].xvel = 0
61
object[arrayPos0].yvel = -0x48000
62
object[arrayPos0].state = 0
63
64
if object[arrayPos0].priority != PRIORITY_XBOUNDS_DESTROY
65
object[arrayPos0].priority = PRIORITY_BOUNDS
66
end if
67
end function
68
69
70
private function ChemicalBall_DebugDraw
71
DrawSprite(0)
72
end function
73
74
75
private function ChemicalBall_DebugSpawn
76
temp0 = debugMode[0].currentSelection
77
temp0 -= ChemicalBall_startDebugID
78
CreateTempObject(TypeName[Chemical Ball], 0, object.xpos, object.ypos)
79
80
arrayPos0 = object[tempObjectPos].entityPos
81
object[arrayPos0].startPos.x = object.xpos
82
object[arrayPos0].startPos.y = object.ypos
83
object[arrayPos0].moveType = temp0
84
object[arrayPos0].moveType >>= 3
85
object[arrayPos0].direction = object.direction
86
object[arrayPos0].interval = temp0
87
object[arrayPos0].interval &= 7
88
CallFunction(ChemicalBall_HandleSetup)
89
end function
90
91
92
private function ChemicalBall_TryPlayChemicalSfx
93
temp0 = screen.xcenter
94
temp0 += 8
95
temp1 = screen.ycenter
96
temp1 += 8
97
CheckCameraProximity(object.ixpos, object.iypos, temp0, temp1)
98
if checkResult == true
99
PlaySfx(SfxName[Chemical Jump], false)
100
end if
101
end function
102
103
104
// ========================
105
// Events
106
// ========================
107
108
event ObjectUpdate
109
object.priority = PRIORITY_ACTIVE
110
if object.state == 0
111
object.timer--
112
if object.timer < 0
113
object.state++
114
object.timer = 59
115
CallFunction(ChemicalBall_TryPlayChemicalSfx)
116
end if
117
else
118
object.xpos += object.xvel
119
object.ypos += object.yvel
120
object.yvel += 0x1800
121
122
if object.moveType == 0
123
object.xvel += object.acceleration
124
if object.yvel == 0
125
FlipSign(object.acceleration)
126
end if
127
128
if object.ypos >= object.startPos.y
129
object.yvel = object.newYVel
130
object.xvel = 0
131
object.state--
132
end if
133
else
134
if object.yvel == 0
135
object.xpos += object.distance
136
end if
137
138
if object.yvel == 0x18000
139
CallFunction(ChemicalBall_TryPlayChemicalSfx)
140
end if
141
142
if object.ypos == object.startPos.y
143
object.yvel = object.newYVel
144
object.xpos = object.startPos.x
145
FlipSign(object.acceleration)
146
CallFunction(ChemicalBall_TryPlayChemicalSfx)
147
end if
148
end if
149
end if
150
151
temp0 = object.distance
152
temp0 >>= 1
153
temp0 += object.startPos.x
154
temp0 >>= 16
155
temp1 = screen.xcenter
156
temp1 += 192
157
CheckCameraProximity(temp0, 0, temp1, -1)
158
if checkResult == false
159
arrayPos0 = object.entityPos
160
CallFunction(ChemicalBall_HandleSetup)
161
end if
162
163
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
164
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
165
if checkResult == true
166
CallFunction(Player_Hit)
167
end if
168
next
169
end event
170
171
172
event ObjectDraw
173
DrawSprite(0)
174
end event
175
176
177
event ObjectStartup
178
LoadSpriteSheet("CPZ/Objects.gif")
179
SpriteFrame(-8, -8, 16, 16, 207, 125)
180
181
foreach (TypeName[Chemical Ball], arrayPos0, ALL_ENTITIES)
182
object[arrayPos0].startPos.x = object[arrayPos0].xpos
183
object[arrayPos0].startPos.y = object[arrayPos0].ypos
184
185
GetBit(object[arrayPos0].moveType, object[arrayPos0].propertyValue, 7)
186
187
GetBit(object[arrayPos0].direction, object[arrayPos0].propertyValue, 6)
188
189
object[arrayPos0].interval = object[arrayPos0].propertyValue
190
object[arrayPos0].interval &= 0x3F
191
CallFunction(ChemicalBall_HandleSetup)
192
next
193
194
temp0 = 0
195
ChemicalBall_startDebugID = DebugMode_ObjCount
196
while temp0 < 16
197
SetTableValue(TypeName[Chemical Ball], DebugMode_ObjCount, DebugMode_TypesTable)
198
SetTableValue(ChemicalBall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
199
SetTableValue(ChemicalBall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
200
DebugMode_ObjCount++
201
temp0++
202
loop
203
end event
204
205
206
// ========================
207
// Editor Events
208
// ========================
209
210
event RSDKEdit
211
if editor.returnVariable == true
212
switch editor.variableID
213
case EDIT_VAR_PROPVAL // property value
214
checkResult = object.propertyValue
215
break
216
217
case 0 // interval
218
checkResult = object.propertyValue
219
checkResult &= 0x3F
220
break
221
222
case 1 // direction
223
GetBit(checkResult, object.propertyValue, 6)
224
break
225
226
case 2 // type
227
GetBit(checkResult, object.propertyValue, 7)
228
break
229
230
end switch
231
else
232
switch editor.variableID
233
case EDIT_VAR_PROPVAL // property value
234
object.propertyValue = editor.variableValue
235
break
236
237
case 0 // interval
238
object.propertyValue = editor.variableValue
239
object.propertyValue &= 0x3F
240
break
241
242
case 1 // direction
243
CheckNotEqual(editor.variableValue, 0)
244
SetBit(object.propertyValue, 6, checkResult)
245
break
246
247
case 2 // type
248
CheckNotEqual(editor.variableValue, 0)
249
SetBit(object.propertyValue, 7, checkResult)
250
break
251
252
end switch
253
end if
254
end event
255
256
257
event RSDKDraw
258
DrawSprite(0)
259
end event
260
261
262
event RSDKLoad
263
LoadSpriteSheet("CPZ/Objects.gif")
264
SpriteFrame(-8, -8, 16, 16, 207, 125)
265
266
AddEditorVariable("interval")
267
SetActiveVariable("interval")
268
269
AddEditorVariable("direction")
270
SetActiveVariable("direction")
271
AddEnumVariable("No Flip", 0)
272
AddEnumVariable("Flip X", 1)
273
274
AddEditorVariable("type")
275
SetActiveVariable("type")
276
AddEnumVariable("Arc", 0)
277
AddEnumVariable("Vertical", 1)
278
end event
279
280