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/Global/StarPost.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Star Post 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.id
13
14
private alias object.value0 : object.ballAngle
15
private alias object.value1 : object.ballPos.x
16
private alias object.value2 : object.ballPos.y
17
private alias object.value3 : object.starTimer
18
private alias object.value4 : object.starType
19
private alias object.value5 : object.starAngleX
20
private alias object.value6 : object.starAngleY
21
private alias object.value7 : object.starRadius
22
private alias object.value8 : object.starFrame
23
private alias object.value9 : object.timer
24
private alias object.value10 : object.targetPlayer
25
26
private alias 0 : STARPOST_AWAITPLAYER
27
private alias 1 : STARPOST_SPUN
28
private alias 2 : STARPOST_SHOWINGSTARS
29
private alias 3 : STARPOST_TOSPECIALSTAGE
30
private alias 4 : STARPOST_AWAITOTHERPLAYER
31
32
private alias 0 : STARPOST_ANI_IDLE
33
private alias 1 : STARPOST_ANI_SPINNING
34
private alias 2 : STARPOST_ANI_SPUN
35
36
// Player Aliases
37
private alias object.xpos : player.xpos
38
private alias object.ypos : player.ypos
39
private alias object.ixpos : player.ixpos
40
private alias object.iypos : player.iypos
41
private alias object.controlMode : player.controlMode
42
private alias object.value0 : player.rings
43
private alias object.value16 : player.isSidekick
44
45
// Game Modes
46
private alias 2 : MODE_TIMEATTACK
47
48
// Tracks
49
private alias 1 : TRACK_ACTFINISH
50
51
52
// ========================
53
// Function Declarations
54
// ========================
55
56
reserve function StarPost_DebugDraw
57
reserve function StarPost_DebugSpawn
58
59
60
// ========================
61
// Function Definitions
62
// ========================
63
64
private function StarPost_DebugDraw
65
DrawSprite(2)
66
end function
67
68
69
private function StarPost_DebugSpawn
70
CreateTempObject(TypeName[Star Post], 0, object.xpos, object.ypos)
71
end function
72
73
74
// ========================
75
// Events
76
// ========================
77
78
event ObjectUpdate
79
switch object.state
80
case STARPOST_AWAITPLAYER
81
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
82
if player[currentPlayer].isSidekick == false
83
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -44, 8, 20, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
84
if checkResult == true
85
if options.vsMode == true
86
if currentPlayer == 0
87
vs.restartX1 = object.xpos
88
vs.restartY1 = object.ypos
89
object.targetPlayer = 1
90
else
91
vs.restartX2 = object.xpos
92
vs.restartY2 = object.ypos
93
object.targetPlayer = 0
94
end if
95
96
object.state = STARPOST_AWAITOTHERPLAYER
97
else
98
starPostID = object.entityPos
99
foreach (TypeName[Star Post], arrayPos0, ALL_ENTITIES)
100
if object[arrayPos0].id < object.id
101
object[arrayPos0].state = STARPOST_SPUN
102
object[arrayPos0].animation = STARPOST_ANI_SPUN
103
object[arrayPos0].ballAngle = 0
104
end if
105
next
106
107
if specialStage.emeralds < 0x7F
108
if options.gameMode != MODE_TIMEATTACK
109
if player[0].rings >= 50
110
object.state = STARPOST_SHOWINGSTARS
111
object.starType = 4
112
object.starTimer = 0
113
object.starAngleY = 0
114
object.starAngleX = 0
115
object.starRadius = 0
116
else
117
object.state = STARPOST_SPUN
118
end if
119
else
120
object.state = STARPOST_SPUN
121
end if
122
else
123
object.state = STARPOST_SPUN
124
end if
125
end if
126
127
#platform: USE_ORIGINS
128
StatsUsabilityParam1 = StageStatsUsabilityParam1
129
StatsUsabilityParam2 = StageStatsUsabilityParam2
130
StatsUsabilityParam3 = StageStatsUsabilityParam3
131
StatsUsabilityParam4 = StageStatsUsabilityParam4
132
StatsUsabilityParam5 = StageStatsUsabilityParam5
133
134
recScore = player.score
135
recRing = player[0].rings
136
#endplatform
137
recMilliSeconds = stage.milliSeconds
138
recSeconds = stage.seconds
139
recMinutes = stage.minutes
140
recWaterState = stage.waterState
141
recWaterLevel = stage.waterLevel
142
143
object.ballAngle = 0x180
144
145
if object.priority != PRIORITY_XBOUNDS_DESTROY
146
object.priority = PRIORITY_ACTIVE
147
end if
148
149
object.animation = STARPOST_ANI_SPINNING
150
PlaySfx(SfxName[Star Post], false)
151
152
#platform: USE_ORIGINS
153
if options.attractMode == false
154
CallNativeFunction2(NotifyCallback, NOTIFY_TOUCH_CHECKPOINT, 0)
155
end if
156
#endplatform
157
end if
158
end if
159
next
160
break
161
162
case STARPOST_SPUN
163
object.animationTimer++
164
object.animationTimer &= 7
165
object.frame = object.animationTimer
166
object.frame >>= 2
167
break
168
169
case STARPOST_SHOWINGSTARS
170
object.starAngleX += 18
171
object.starAngleX &= 0x1FF
172
object.starAngleY += 4
173
object.starAngleY &= 0x1FF
174
175
if object.starTimer < 128
176
object.starRadius++
177
else
178
if object.starTimer > 472
179
object.starRadius--
180
end if
181
end if
182
183
object.starTimer++
184
if object.starTimer == 600
185
object.state = STARPOST_SPUN
186
object.starTimer = 0
187
object.starType = 0
188
if object.priority != PRIORITY_XBOUNDS_DESTROY
189
object.priority = PRIORITY_BOUNDS
190
end if
191
end if
192
193
object.animationTimer++
194
object.animationTimer &= 7
195
object.frame = object.animationTimer
196
object.frame >>= 2
197
temp0 = object.starRadius
198
temp0 >>= 2
199
FlipSign(temp0)
200
temp1 = object.starRadius
201
temp1 >>= 2
202
203
if object.starTimer > 60
204
BoxCollisionTest(C_TOUCH, object.entityPos, temp0, -64, temp1, -56, 0, C_BOX, C_BOX, C_BOX, C_BOX)
205
if checkResult == true
206
PlaySfx(SfxName[Warp], false)
207
object.state = STARPOST_TOSPECIALSTAGE
208
object.priority = PRIORITY_ALWAYS
209
stage.state = STAGE_FROZEN
210
player[0].controlMode = CONTROLMODE_NONE
211
#platform: USE_ORIGINS
212
StopSfx(SfxName[Flying])
213
StopSfx(SfxName[Tired])
214
#endplatform
215
fadeColor = 208
216
fadeColor <<= 16
217
temp0 = 0xFF
218
temp0 <<= 8
219
fadeColor += temp0
220
fadeColor += 0xE0
221
object.timer = 0
222
end if
223
end if
224
break
225
226
case STARPOST_TOSPECIALSTAGE
227
options.touchControls = false
228
music.volume -= 2
229
object.timer += 8
230
SetScreenFade(208, 255, 224, object.timer)
231
if object.timer == 0x400
232
specialStage.nextZone = stage.listPos
233
stage.activeList = SPECIAL_STAGE
234
stage.listPos = specialStage.listPos
235
LoadStage()
236
end if
237
break
238
239
case STARPOST_AWAITOTHERPLAYER
240
currentPlayer = object.targetPlayer
241
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -44, 8, 20, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
242
if checkResult == true
243
if currentPlayer == 0
244
vs.restartX1 = object.xpos
245
vs.restartY1 = object.ypos
246
else
247
vs.restartX2 = object.xpos
248
vs.restartY2 = object.ypos
249
end if
250
251
if object.animation != STARPOST_ANI_SPINNING
252
object.ballAngle = 0x180
253
end if
254
255
if object.priority != PRIORITY_XBOUNDS_DESTROY
256
object.priority = PRIORITY_ACTIVE
257
end if
258
object.animation = STARPOST_ANI_SPINNING
259
object.state = STARPOST_SPUN
260
PlaySfx(SfxName[Star Post], false)
261
end if
262
263
object.animationTimer++
264
object.animationTimer &= 7
265
object.frame = object.animationTimer
266
object.frame >>= 2
267
break
268
269
end switch
270
271
if object.animation == STARPOST_ANI_SPINNING
272
Cos(object.ballPos.x, object.ballAngle)
273
object.ballPos.x *= -0x500
274
275
Sin(object.ballPos.y, object.ballAngle)
276
object.ballPos.y *= 0x500
277
278
object.ballPos.x += object.xpos
279
object.ballPos.y += object.ypos
280
object.ballPos.y -= 0x1A0000
281
object.ballAngle += 32
282
if object.ballAngle > 0x580
283
object.ballAngle = 0
284
object.animation = STARPOST_ANI_SPUN
285
if object.priority != PRIORITY_XBOUNDS_DESTROY
286
if object.starType == 0
287
object.priority = PRIORITY_BOUNDS
288
end if
289
end if
290
end if
291
end if
292
end event
293
294
295
event ObjectDraw
296
switch object.animation
297
case STARPOST_ANI_IDLE
298
DrawSprite(2)
299
break
300
301
case STARPOST_ANI_SPINNING
302
DrawSprite(3)
303
DrawSpriteXY(0, object.ballPos.x, object.ballPos.y)
304
break
305
306
case STARPOST_ANI_SPUN
307
DrawSprite(3)
308
temp0 = object.ypos
309
temp0 -= 0x240000
310
DrawSpriteXY(object.frame, object.xpos, temp0)
311
break
312
313
end switch
314
315
if object.starType > 0
316
temp0 = 0
317
temp1 = object.starAngleX
318
Sin(temp4, object.starAngleY)
319
temp4 *= 3
320
object.starFrame = object.starAngleY
321
object.starFrame &= 15
322
object.starFrame >>= 2
323
object.starFrame += object.starType
324
while temp0 < 4
325
Sin(temp2, temp1)
326
temp2 <<= 12
327
Cos(temp3, temp1)
328
temp3 <<= 10
329
Sin(temp5, temp1)
330
temp5 *= temp4
331
temp3 += temp5
332
temp2 *= object.starRadius
333
temp2 >>= 7
334
temp3 *= object.starRadius
335
temp3 >>= 7
336
temp2 += object.xpos
337
temp3 += object.ypos
338
temp3 -= 0x3C0000
339
DrawSpriteXY(object.starFrame, temp2, temp3)
340
temp0++
341
temp1 += 128
342
loop
343
end if
344
end event
345
346
347
event ObjectStartup
348
LoadSpriteSheet("Global/Items.gif")
349
SpriteFrame(-8, -8, 16, 16, 1, 137)
350
SpriteFrame(-8, -8, 16, 16, 1, 202)
351
SpriteFrame(-8, -44, 16, 64, 1, 137)
352
SpriteFrame(-8, -28, 16, 48, 1, 153)
353
SpriteFrame(-1, -1, 3, 3, 76, 214)
354
SpriteFrame(-3, -3, 7, 7, 68, 214)
355
SpriteFrame(-7, -7, 15, 15, 52, 214)
356
SpriteFrame(-3, -3, 7, 7, 68, 214)
357
358
SetTableValue(TypeName[Star Post], DebugMode_ObjCount, DebugMode_TypesTable)
359
SetTableValue(StarPost_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
360
SetTableValue(StarPost_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
361
DebugMode_ObjCount++
362
363
if starPostID >= 32
364
arrayPos0 = starPostID
365
currentPlayer = 0
366
while currentPlayer < playerCount
367
player[currentPlayer].xpos = object[arrayPos0].xpos
368
player[currentPlayer].ypos = object[arrayPos0].ypos
369
currentPlayer++
370
loop
371
372
foreach (TypeName[Star Post], arrayPos1, ALL_ENTITIES)
373
if object[arrayPos1].id < object[arrayPos0].id
374
object[arrayPos1].state = STARPOST_SPUN
375
object[arrayPos1].animation = STARPOST_ANI_SPUN
376
object[arrayPos1].ballAngle = 0
377
end if
378
next
379
380
camera[0].xpos = player[0].ixpos
381
camera[0].ypos = player[0].iypos
382
383
object[arrayPos0].state = STARPOST_SPUN
384
object[arrayPos0].animation = STARPOST_ANI_SPUN
385
386
#platform: USE_ORIGINS
387
player.score = recScore
388
389
if player.deadResetRings == true
390
player[0].rings = 0
391
player.deadResetRings = false
392
else
393
player[0].rings = recRing
394
end if
395
396
ringExtraLife = 100
397
ringExtraLife += player[0].rings
398
temp0 = player[0].rings
399
temp0 %= 100
400
ringExtraLife -= temp0
401
if ringExtraLife > 300
402
ringExtraLife = 1000
403
end if
404
#endplatform
405
406
stage.milliSeconds = recMilliSeconds
407
stage.seconds = recSeconds
408
stage.minutes = recMinutes
409
410
#platform: USE_ORIGINS
411
StageStatsUsabilityParam1 = StatsUsabilityParam1
412
StageStatsUsabilityParam2 = StatsUsabilityParam2
413
StageStatsUsabilityParam3 = StatsUsabilityParam3
414
StageStatsUsabilityParam4 = StatsUsabilityParam4
415
StageStatsUsabilityParam5 = StatsUsabilityParam5
416
else
417
game.timeOver = false
418
#endplatform
419
end if
420
end event
421
422
423
// ========================
424
// Editor Events
425
// ========================
426
427
event RSDKDraw
428
DrawSprite(0)
429
end event
430
431
432
event RSDKLoad
433
LoadSpriteSheet("Global/Items.gif")
434
SpriteFrame(-8, -44, 16, 64, 1, 137)
435
436
SetVariableAlias(ALIAS_VAR_PROPVAL, "id")
437
end event
438
439