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/MPZ/MPZSetup.txt
1478 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: MPZ Setup 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.paletteTimer
13
private alias object.value2 : object.cylinder1TileFrame
14
private alias object.value3 : object.cylinder2TileFrame
15
private alias object.value4 : object.bgPiston1TileFrame
16
private alias object.value5 : object.bgPiston2TileFrame
17
private alias object.value6 : object.lavaTileFrame
18
private alias object.value7 : object.bgPistonTileDuration
19
private alias object.value8 : object.bgPistonTileAnimID
20
private alias object.value9 : object.lavaTileDuration
21
private alias object.value10 : object.palCycle1Timer
22
private alias object.value11 : object.palCycle1Index
23
private alias object.value12 : object.palCycle2Timer
24
private alias object.value13 : object.palCycle2Index
25
26
// Universal MPZ Object Aliases
27
// (As in, all objects in MPZ use their value31 like this)
28
private alias object.value31 : object.wrapOffset.y
29
30
// Player Aliases
31
private alias object.state : player.state
32
private alias object.xpos : player.xpos
33
private alias object.ypos : player.ypos
34
35
// Tracks
36
private alias 0 : TRACK_STAGE
37
private alias 1 : TRACK_ACTFINISH
38
private alias 2 : TRACK_INVINCIBLE
39
private alias 3 : TRACK_CONTINUE
40
private alias 4 : TRACK_BOSS
41
private alias 5 : TRACK_GAMEOVER
42
private alias 6 : TRACK_DROWNING
43
private alias 7 : TRACK_SUPER
44
45
// Reserved Object Slots Aliases
46
private alias 10 : SLOT_ZONESETUP
47
private alias 25 : SLOT_MUSICEVENT_CHANGE
48
private alias 26 : SLOT_MUSICEVENT_BOSS
49
50
// Tile Flag Aliases
51
private alias 1 : TILE_LAVA
52
53
// Tile Info ID Aliases
54
private alias 8 : TILEINFO_ANGLEB
55
56
// Music Events
57
private alias 2 : MUSICEVENT_TRANSITION
58
59
private alias 0 : MUSICEVENT_FLAG_NOCHANGE
60
private alias 1 : MUSICEVENT_FLAG_SPEEDUP
61
private alias 2 : MUSICEVENT_FLAG_SLOWDOWN
62
63
// Music Loops
64
private alias 309378 : MUSIC_LOOP_MPZ
65
private alias 247394 : MUSIC_LOOP_MPZ_F
66
67
private alias 38679 : MUSIC_LOOP_INV
68
private alias 30897 : MUSIC_LOOP_INV_F
69
70
// Achievement Aliases
71
private alias 9 : ACHIEVEMENT_MPZMASTER
72
73
74
// ========================
75
// Function Declarations
76
// ========================
77
78
reserve function MPZSetup_SpeedUpMusic
79
reserve function MPZSetup_SlowDownMusic
80
81
82
// ========================
83
// Static Values
84
// ========================
85
86
private value MPZSetup_prevStageWrap = 0
87
public value MPZSetup_cogFrame = 0
88
public value MPZSetup_cogTimer = 0
89
private value MPZSetup_checkedAchievement = 0
90
private value MPZSetup_playerWasHit = 0
91
private value MPZSetup_unused1 = 0 // As the name suggests, it is not used
92
private value MPZSetup_unused2 = 0 // As the name suggests, it is not used
93
94
95
// ========================
96
// Tables
97
// ========================
98
99
private table MPZSetup_palCycle1
100
0x00A000, 0x000000, 0xE0E000, 0x000000, 0xE02000
101
0x000000, 0xE020E0, 0x000000, 0x0080E0, 0x000000
102
end table
103
104
private table MPZSetup_palCycle2
105
0x600000, 0x800000, 0xA00000
106
0xC00000, 0xA00000, 0x800000
107
end table
108
109
110
// ========================
111
// Function Definitions
112
// ========================
113
114
private function MPZSetup_SpeedUpMusic
115
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].type, TypeName[Music Event])
116
temp0 = checkResult
117
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].propertyValue, MUSICEVENT_TRANSITION)
118
temp0 &= checkResult
119
CheckEqual(stage.musicFlag, MUSICEVENT_FLAG_NOCHANGE)
120
temp0 &= checkResult
121
if temp0 == false
122
switch music.currentTrack
123
case TRACK_STAGE
124
SetMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV_F)
125
SwapMusicTrack("Metropolis_F.ogg", TRACK_STAGE, MUSIC_LOOP_MPZ_F, 8000)
126
break
127
128
case TRACK_INVINCIBLE
129
SetMusicTrack("Metropolis_F.ogg", TRACK_STAGE, MUSIC_LOOP_MPZ_F)
130
SwapMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV_F, 8000)
131
break
132
133
case TRACK_BOSS
134
case TRACK_GAMEOVER
135
case TRACK_SUPER
136
SetMusicTrack("Metropolis_F.ogg", TRACK_STAGE, MUSIC_LOOP_MPZ_F)
137
SetMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV_F)
138
break
139
140
end switch
141
else
142
stage.musicFlag = MUSICEVENT_FLAG_SPEEDUP
143
end if
144
end function
145
146
147
private function MPZSetup_SlowDownMusic
148
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].type, TypeName[Music Event])
149
temp0 = checkResult
150
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].propertyValue, MUSICEVENT_TRANSITION)
151
temp0 &= checkResult
152
CheckEqual(stage.musicFlag, MUSICEVENT_FLAG_NOCHANGE)
153
temp0 &= checkResult
154
if temp0 == false
155
switch music.currentTrack
156
case TRACK_STAGE
157
SetMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV)
158
SwapMusicTrack("Metropolis.ogg", TRACK_STAGE, MUSIC_LOOP_MPZ, 12500)
159
break
160
161
case TRACK_INVINCIBLE
162
SetMusicTrack("Metropolis.ogg", TRACK_STAGE, MUSIC_LOOP_MPZ)
163
SwapMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV, 12500)
164
break
165
166
case TRACK_BOSS
167
case TRACK_GAMEOVER
168
case TRACK_SUPER
169
SetMusicTrack("Metropolis.ogg", TRACK_STAGE, MUSIC_LOOP_MPZ)
170
SetMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV)
171
break
172
173
end switch
174
else
175
stage.musicFlag = MUSICEVENT_FLAG_SLOWDOWN
176
end if
177
end function
178
179
// ========================
180
// Events
181
// ========================
182
183
event ObjectUpdate
184
object.paletteTimer++
185
if object.paletteTimer > 2
186
object.paletteTimer = 0
187
RotatePalette(0, 161, 163, false)
188
end if
189
190
object.palCycle1Timer++
191
if object.palCycle1Timer >= 10
192
object.palCycle1Timer = 0
193
object.palCycle1Index++
194
if object.palCycle1Index >= 10
195
object.palCycle1Index = 0
196
end if
197
GetTableValue(temp0, object.palCycle1Index, MPZSetup_palCycle1)
198
SetPaletteEntry(0, 175, temp0)
199
end if
200
201
202
object.palCycle2Timer++
203
if object.palCycle2Timer >= 18
204
object.palCycle2Timer = 0
205
object.palCycle2Index++
206
if object.palCycle2Index >= 6
207
object.palCycle2Index = 0
208
end if
209
GetTableValue(temp0, object.palCycle2Index, MPZSetup_palCycle2)
210
SetPaletteEntry(0, 168, temp0)
211
end if
212
213
214
// Cylinder Animations (Interactable)
215
Copy16x16Tile(760, object.cylinder1TileFrame)
216
object.cylinder1TileFrame++
217
218
Copy16x16Tile(761, object.cylinder1TileFrame)
219
object.cylinder1TileFrame++
220
221
Copy16x16Tile(762, object.cylinder1TileFrame)
222
object.cylinder1TileFrame++
223
224
Copy16x16Tile(763, object.cylinder1TileFrame)
225
object.cylinder1TileFrame++
226
227
Copy16x16Tile(764, object.cylinder1TileFrame)
228
object.cylinder1TileFrame++
229
230
Copy16x16Tile(765, object.cylinder1TileFrame)
231
object.cylinder1TileFrame++
232
233
Copy16x16Tile(766, object.cylinder1TileFrame)
234
object.cylinder1TileFrame++
235
236
Copy16x16Tile(767, object.cylinder1TileFrame)
237
object.cylinder1TileFrame++
238
239
if object.cylinder1TileFrame == 832
240
object.cylinder1TileFrame = 768
241
end if
242
243
// Cylinder Animations (BG)
244
Copy16x16Tile(744, object.cylinder2TileFrame)
245
object.cylinder2TileFrame++
246
247
Copy16x16Tile(745, object.cylinder2TileFrame)
248
object.cylinder2TileFrame++
249
250
Copy16x16Tile(746, object.cylinder2TileFrame)
251
object.cylinder2TileFrame++
252
253
Copy16x16Tile(747, object.cylinder2TileFrame)
254
object.cylinder2TileFrame++
255
256
Copy16x16Tile(748, object.cylinder2TileFrame)
257
object.cylinder2TileFrame++
258
259
Copy16x16Tile(749, object.cylinder2TileFrame)
260
object.cylinder2TileFrame++
261
262
Copy16x16Tile(750, object.cylinder2TileFrame)
263
object.cylinder2TileFrame++
264
265
Copy16x16Tile(751, object.cylinder2TileFrame)
266
object.cylinder2TileFrame++
267
268
if object.cylinder2TileFrame == 896
269
object.cylinder2TileFrame = 832
270
end if
271
272
if object.bgPistonTileDuration < 2
273
Copy16x16Tile(753, object.bgPiston1TileFrame)
274
object.bgPiston1TileFrame++
275
276
Copy16x16Tile(754, object.bgPiston1TileFrame)
277
object.bgPiston1TileFrame++
278
279
Copy16x16Tile(755, object.bgPiston1TileFrame)
280
object.bgPiston1TileFrame++
281
282
if object.bgPiston1TileFrame == 908
283
object.bgPiston1TileFrame = 896
284
end if
285
286
Copy16x16Tile(742, object.bgPiston2TileFrame)
287
object.bgPiston2TileFrame++
288
289
Copy16x16Tile(743, object.bgPiston2TileFrame)
290
object.bgPiston2TileFrame++
291
292
Copy16x16Tile(752, object.bgPiston2TileFrame)
293
object.bgPiston2TileFrame++
294
295
if object.bgPiston2TileFrame == 908
296
object.bgPiston2TileFrame = 896
297
end if
298
299
if object.bgPistonTileAnimID == 0
300
object.bgPistonTileDuration = 20
301
else
302
object.bgPistonTileDuration = 8
303
end if
304
object.bgPistonTileAnimID ^= 1
305
else
306
object.bgPistonTileDuration--
307
end if
308
309
if object.lavaTileDuration < 2
310
Copy16x16Tile(756, object.lavaTileFrame)
311
object.lavaTileFrame++
312
313
Copy16x16Tile(757, object.lavaTileFrame)
314
object.lavaTileFrame++
315
316
Copy16x16Tile(758, object.lavaTileFrame)
317
object.lavaTileFrame++
318
319
Copy16x16Tile(759, object.lavaTileFrame)
320
object.lavaTileFrame++
321
322
if object.lavaTileFrame == 932
323
object.lavaTileFrame = 908
324
end if
325
object.lavaTileDuration = 14
326
else
327
object.lavaTileDuration--
328
end if
329
330
// Cycle through all players
331
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
332
// Check if the player is on lava
333
temp1 = player[currentPlayer].xpos
334
temp1 >>= 16
335
336
temp2 = player[currentPlayer].ypos
337
temp2 >>= 16
338
339
temp2 += 4
340
341
// First bit is set for lava tiles
342
Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)
343
temp0 &= TILE_LAVA
344
345
if temp0 == TILE_LAVA
346
CallFunction(Player_FireHit)
347
end if
348
next
349
350
MPZSetup_cogFrame += MPZSetup_cogTimer
351
MPZSetup_cogFrame &= 3
352
353
if player[0].ypos >= 0x8F00000
354
temp1 = player[0].ypos
355
currentPlayer = 0
356
while currentPlayer < playerCount
357
temp0 = player[currentPlayer].ypos
358
temp0 -= temp1
359
Abs(temp0)
360
if temp0 < 0x8C0000
361
player[currentPlayer].ypos -= 0x8000000
362
end if
363
currentPlayer++
364
loop
365
366
if camera[0].ypos >= 0x800
367
camera[0].ypos -= 0x800
368
screen.yoffset -= 0x800
369
end if
370
end if
371
372
if player[0].ypos <= 0x900000
373
temp1 = player[0].ypos
374
currentPlayer = 0
375
while currentPlayer < playerCount
376
temp0 = player[currentPlayer].ypos
377
temp0 -= temp1
378
Abs(temp0)
379
if temp0 < 0x8C0000
380
player[currentPlayer].ypos += 0x8000000
381
end if
382
currentPlayer++
383
loop
384
385
if camera[0].ypos <= 384
386
camera[0].ypos += 0x800
387
screen.yoffset += 0x800
388
end if
389
end if
390
391
// Stage Wrap (Bottom)
392
if camera[0].ypos >= 1552
393
if MPZSetup_prevStageWrap == 0
394
MPZSetup_prevStageWrap = 1
395
arrayPos0 = 0x20
396
while arrayPos0 < 0x4A0
397
if object[arrayPos0].ypos <= 0x2800000
398
object[arrayPos0].ypos += 0x8000000
399
object[arrayPos0].wrapOffset.y += 0x8000000
400
end if
401
arrayPos0++
402
loop
403
end if
404
end if
405
406
// Stage Wrap (Top)
407
if camera[0].ypos <= 640
408
if MPZSetup_prevStageWrap == 1
409
MPZSetup_prevStageWrap = 0
410
arrayPos0 = 32
411
while arrayPos0 < 0x4A0
412
if object[arrayPos0].ypos >= 0x6800000
413
object[arrayPos0].ypos -= 0x8000000
414
object[arrayPos0].wrapOffset.y -= 0x8000000
415
end if
416
arrayPos0++
417
loop
418
end if
419
end if
420
421
if player[0].state == Player_State_Hurt
422
// The player has been hurt, the achievment is unobtainable now
423
MPZSetup_playerWasHit = true
424
end if
425
426
if MPZSetup_checkedAchievement == false
427
if stage.debugMode == false
428
if object[30].type == TypeName[Act Finish]
429
MPZSetup_checkedAchievement = true
430
431
if MPZSetup_playerWasHit == false
432
// Grant the "Metropolis Master" Achieve, since the player made it though without getting hit even once
433
CallNativeFunction2(SetAchievement, ACHIEVEMENT_MPZMASTER, 100)
434
end if
435
end if
436
end if
437
end if
438
end event
439
440
441
event ObjectStartup
442
SetMusicTrack("Metropolis.ogg", TRACK_STAGE, 309378)
443
SpeedUpMusic = MPZSetup_SpeedUpMusic
444
SlowDownMusic = MPZSetup_SlowDownMusic
445
446
animalType1 = TypeName[Locky]
447
animalType2 = TypeName[Wocky]
448
449
// Reset the color used for the boss flash
450
SetPaletteEntry(0, 192, 0x000000)
451
452
object[SLOT_ZONESETUP].type = TypeName[MPZ Setup]
453
object[SLOT_ZONESETUP].priority = 1
454
object[SLOT_ZONESETUP].cylinder1TileFrame = 768
455
object[SLOT_ZONESETUP].cylinder2TileFrame = 832
456
object[SLOT_ZONESETUP].bgPiston1TileFrame = 896
457
object[SLOT_ZONESETUP].bgPiston2TileFrame = 902
458
object[SLOT_ZONESETUP].lavaTileFrame = 908
459
460
MPZSetup_prevStageWrap = 0
461
MPZSetup_cogFrame = 0
462
MPZSetup_cogTimer = 0
463
MPZSetup_checkedAchievement = false
464
if starPostID == 0
465
MPZSetup_playerWasHit = false
466
end if
467
end event
468
469
470
// ========================
471
// Editor Events
472
// ========================
473
474
event RSDKDraw
475
DrawSprite(0)
476
end event
477
478
479
event RSDKLoad
480
LoadSpriteSheet("Global/Display.gif")
481
SpriteFrame(-16, -16, 32, 32, 1, 143)
482
483
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
484
end event
485
486