Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Global/TimeWarp.txt
1319 views
1
//-----------------Sonic CD Time Warp Script------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value7 : Object.CurrentPeriod
7
#alias Object.Value1 : Object.Timer
8
9
// Player Aliases
10
#alias Player.Value0 : Player.Rings
11
#alias Player.Value4 : Player.InvincibleTimer
12
#alias Player.Value6 : Player.MinRollSpeed
13
14
// HUD Alias
15
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
16
17
// States
18
#alias 0 : TIMEWARP_SETUP
19
#alias 1 : TIMEWARP_FADE_IN
20
#alias 2 : TIMEWARP_BACKGROUND
21
#alias 3 : TIMEWARP_BLANK
22
#alias 4 : TIMEWARP_LEAVING
23
#alias 5 : TIMEWARP_TRAVEL
24
25
// Player
26
#alias 0 : PLAYER_SONIC_A
27
28
// Control Mode
29
#alias -1 : CONTROLMODE_NONE
30
31
// Global SFX
32
#alias 14 : SFX_G_TIMEWARP
33
#alias 24 : SFX_G_FLYING
34
#alias 25 : SFX_G_TIRED
35
36
// Warp Destination
37
#alias 1 : WARPDEST_PAST
38
39
// Next Period
40
#alias 0 : TIME_PRESENT
41
#alias 1 : TIME_PAST
42
#alias 2 : TIME_GOOD_FUTURE
43
#alias 3 : TIME_BAD_FUTURE
44
45
46
sub ObjectDraw
47
switch Object.State
48
case TIMEWARP_SETUP
49
if Object.Timer < 320
50
if Object.Timer == 0
51
Warp.XPos = Player.XPos
52
Warp.YPos = Player.YPos
53
54
Warp.XVelocity = Player.XVelocity
55
Warp.YVelocity = Player.YVelocity
56
Warp.Speed = Player.Speed
57
Warp.MinRollSpeed = Player.MinRollSpeed
58
59
Warp.CollisionMode = Player.CollisionMode
60
Warp.Gravity = Player.Gravity
61
62
if Player.State == Player_State_Static
63
Warp.State = Player_State_Air
64
else
65
if Player.State == Player_State_SpinningTop
66
Warp.State = Player_State_Air
67
else
68
if Player.State == Player_State_WaterCurrent
69
Warp.State = Player_State_Air
70
else
71
Warp.State = Player.State
72
endif
73
endif
74
endif
75
76
Warp.Animation = Player.Animation
77
Warp.Angle = Player.Angle
78
Warp.PlayerFrame = Player.Frame
79
80
Player.InvincibleTimer = 1000
81
Player.ControlMode = CONTROLMODE_NONE
82
Player.Visible = false
83
end if
84
Music.Volume -= 8
85
SetScreenFade(208, 255, 224, Object.Timer)
86
Object.Timer += 10
87
else
88
// 88 Miles per Hour unlock criteria
89
if Stage.PlayerListPos == PLAYER_SONIC_A // PLAYER_SONIC in origins
90
if Stage.DebugMode == false
91
SetAchievement(0, 100)
92
end if
93
end if
94
95
#platform: Use_Haptics
96
HapticEffect(91, 0, 0, 0)
97
#endplatform
98
99
StopSFX(SFX_G_FLYING)
100
StopSFX(SFX_G_TIRED)
101
Stage.State = STAGE_RUNNING
102
Stage.TimeEnabled = false
103
104
// Saves everything
105
CallFunction(StageSetup_SaveStageState)
106
Rec_Milliseconds = Stage.MilliSeconds
107
Rec_Seconds = Stage.Seconds
108
Rec_Minutes = Stage.Minutes
109
110
Warp.Rings = Player.Rings
111
TempValue2 = HUD.CurrentTimePeriod
112
113
// Sets every object as a blank object in the current period
114
//(likely to avoid the player's death during the cutscene)
115
TempValue0 = 0
116
while TempValue0 < 1184
117
ResetObjectEntity(TempValue0, TypeName[Blank Object], 0, 0, 0)
118
TempValue0++
119
loop
120
// Blanks the level layers
121
Screen.XOffset = 0
122
Screen.YOffset = 0
123
Stage[0].ActiveLayer = 9
124
Stage[1].ActiveLayer = 9
125
Stage[2].ActiveLayer = 9
126
Stage[3].ActiveLayer = 9
127
ArrayPos0 = 0
128
129
// Sets the fade in
130
Object[ArrayPos0].Type = TypeName[Time Warp]
131
Object[ArrayPos0].State = TIMEWARP_FADE_IN
132
Object[ArrayPos0].Timer = 320
133
Object[ArrayPos0].CurrentPeriod = TempValue2
134
ArrayPos0++
135
136
// Creates the background
137
TempValue0 = -32
138
while TempValue0 < 256
139
TempValue1 = 0
140
while TempValue1 < Screen.XSize
141
Object[ArrayPos0].Type = TypeName[Time Warp]
142
Object[ArrayPos0].State = TIMEWARP_BACKGROUND
143
Rand(Object[ArrayPos0].Frame, 27)
144
Object[ArrayPos0].Frame >>= 2
145
Object[ArrayPos0].Frame <<= 2
146
Object[ArrayPos0].iXPos = TempValue1
147
Object[ArrayPos0].iYPos = TempValue0
148
Object[ArrayPos0].iXPos += 16
149
Object[ArrayPos0].iYPos += 16
150
Rand(Object[ArrayPos0].Direction, 15)
151
Object[ArrayPos0].Direction >>= 2
152
ArrayPos0++
153
TempValue1 += 32
154
loop
155
TempValue0 += 32
156
loop
157
// And of course, the star of the show appears
158
Object[ArrayPos0].Type = TypeName[Warp Sonic]
159
Object[ArrayPos0].iXPos = Screen.CenterX
160
Object[ArrayPos0].iYPos = 480
161
162
SetScreenFade(208, 255, 224, 255)
163
164
PlaySfx(SFX_G_TIMEWARP, false)
165
end if
166
break
167
168
case TIMEWARP_FADE_IN
169
if Object.Timer > 0
170
SetScreenFade(208, 255, 224, Object.Timer)
171
Object.Timer -= 10
172
else
173
174
#platform: Use_Origins
175
game.callbackParam0 = Object.PropertyValue // Signal the new period over to the engine
176
EngineCallback(NOTIFY_FUTURE_PAST)
177
#endplatform
178
179
Object.State = TIMEWARP_BLANK
180
end if
181
break
182
183
case TIMEWARP_BACKGROUND
184
TempValue0 = Object.Frame
185
TempValue0 >>= 1
186
DrawSpriteFX(TempValue0, FX_FLIP, Object.XPos, Object.YPos)
187
Object.Frame++
188
if Object.Frame == 28
189
Object.Frame = 0
190
end if
191
192
Object.YPos += 0x40000
193
if Object.YPos >= 0x1000000
194
Object.YPos -= 0x1200000
195
end if
196
break
197
198
case TIMEWARP_BLANK
199
break
200
201
case TIMEWARP_LEAVING
202
Object.Timer++
203
if Object.Timer == 40
204
Object.Timer = 0
205
Object.State = TIMEWARP_TRAVEL
206
end if
207
break
208
209
case TIMEWARP_TRAVEL
210
if Object.Timer < 1800
211
SetScreenFade(208, 255, 224, Object.Timer)
212
Object.Timer += 10
213
else
214
SetScreenFade(208, 255, 224, 255)
215
switch Object.CurrentPeriod
216
// from this point onward any "Object.CurrentPeriod" was added by Origins for HE2 tracking
217
case TIME_PRESENT
218
if Warp.Destination == WARPDEST_PAST
219
Stage.ListPos++
220
Object.CurrentPeriod = TIME_PAST
221
else
222
if Transporter_Destroyed == true
223
Stage.ListPos += 2
224
Object.CurrentPeriod = TIME_GOOD_FUTURE
225
else
226
Stage.ListPos += 3
227
Object.CurrentPeriod = TIME_BAD_FUTURE
228
end if
229
end if
230
break
231
232
case TIME_PAST
233
Stage.ListPos--
234
Object.CurrentPeriod = TIME_PRESENT
235
break
236
237
case TIME_GOOD_FUTURE
238
Stage.ListPos -= 2
239
Object.CurrentPeriod = TIME_PRESENT
240
break
241
242
case TIME_BAD_FUTURE
243
244
#platform: Use_Standalone
245
Stage.ListPos -= 3
246
#endplatform
247
248
#platform: Use_Origins
249
if game.playMode != BOOT_PLAYMODE_MISSION
250
Stage.ListPos -= 3
251
else
252
Stage.ListPos -= 2
253
endif
254
#endplatform
255
256
Object.CurrentPeriod = TIME_PRESENT
257
break
258
259
end switch
260
Fade_Colour = 208
261
Fade_Colour <<= 16
262
TempValue0 = 255
263
TempValue0 <<= 8
264
Fade_Colour += TempValue0
265
Fade_Colour += 224
266
267
#platform: Use_Origins
268
game.callbackParam0 = 1 // Lamp Post Related?
269
EngineCallback(NOTIFY_STATS_PARAM_1)
270
game.callbackParam0 = Object.CurrentPeriod // Get current period
271
EngineCallback(NOTIFY_GOTO_FUTURE_PAST)
272
#endplatform
273
274
LoadStage()
275
#platform: Use_Origins
276
// PlayerObject will use this as part of a check to keep mini state after the stage load
277
Warp.Timer = 204
278
Warp.Timer += 1
279
#endplatform
280
end if
281
break
282
end switch
283
end sub
284
285
286
sub ObjectStartup
287
LoadSpriteSheet("Global/Items3.gif")
288
289
SpriteFrame(-16, -16, 32, 32, 83, 0) // #0 - Time Travel BG Chunk 0
290
SpriteFrame(-16, -16, 32, 32, 83, 32) // #1 - Time Travel BG Chunk 1
291
SpriteFrame(-16, -16, 32, 32, 83, 64) // #2 - Time Travel BG Chunk 2
292
SpriteFrame(-16, -16, 32, 32, 83, 96) // #3 - Time Travel BG Chunk 3
293
SpriteFrame(-16, -16, 32, 32, 83, 128) // #4 - Time Travel BG Chunk 4
294
SpriteFrame(-16, -16, 32, 32, 83, 160) // #5 - Time Travel BG Chunk 5
295
SpriteFrame(-16, -16, 32, 32, 83, 192) // #6 - Time Travel BG Chunk 6
296
SpriteFrame(-16, -16, 32, 32, 83, 224) // #7 - Time Travel BG Chunk 7
297
SpriteFrame(-16, -16, 32, 32, 115, 0) // #8 - Time Travel BG Chunk 8
298
SpriteFrame(-16, -16, 32, 32, 115, 32) // #9 - Time Travel BG Chunk 9
299
SpriteFrame(-16, -16, 32, 32, 115, 64) // #10 - Time Travel BG Chunk 10
300
SpriteFrame(-16, -16, 32, 32, 115, 96) // #11 - Time Travel BG Chunk 11
301
SpriteFrame(-16, -16, 32, 32, 115, 128) // #12 - Time Travel BG Chunk 12
302
SpriteFrame(-16, -16, 32, 32, 115, 160) // #13 - Time Travel BG Chunk 13
303
end sub
304
305
306
// ========================
307
// Editor Subs
308
// ========================
309
310
sub RSDKDraw
311
DrawSprite(0)
312
end sub
313
314
315
sub RSDKLoad
316
LoadSpriteSheet("Global/Items3.gif")
317
SpriteFrame(-16, -16, 32, 32, 83, 0) // #0 - Time Travel BG Chunk 0
318
319
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
320
end sub
321
322