Path: blob/master/Sonic 1/Scripts/Special/SpecialSetup.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Special Setup Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.bgClr.r13private alias object.value2 : object.bgClr.g14private alias object.value3 : object.bgClr.b15private alias object.value4 : object.bgClr.a1617// Player Aliases18private alias object.xpos : player.xpos19private alias object.ypos : player.ypos20private alias object.xvel : player.xvel21private alias object.yvel : player.yvel22private alias object.collisionLeft : player.collisionLeft23private alias object.collisionTop : player.collisionTop24private alias object.collisionRight : player.collisionRight25private alias object.collisionBottom : player.collisionBottom2627private alias object.value11 : player.collisionFlags2829// Game Modes30public alias 1 : MODE_SAVEGAME31public alias 2 : MODE_TIMEATTACK3233// Tracks34private alias 0 : TRACK_STAGE35private alias 1 : TRACK_ACTFINISH3637// Reserved object slots38private alias 0 : SLOT_PLAYER139private alias 9 : SLOT_HUD404142// ========================43// Function Declarations44// ========================4546reserve function SpecialSetup_CopyAniTiles47reserve function SpecialSetup_ProcessHScroll48reserve function SpecialSetup_GetBlockPos49reserve function SpecialSetup_PlayerBlockCol505152// ========================53// Static Values54// ========================5556public value SpecialSetup_gemBlockTimer = 057public value SpecialSetup_gemBlockBusy = 058public value SpecialSetup_blockTimer = 0596061// ========================62// Tables63// ========================6465private table SpecialSetup_replay_attract_STK660x00F00000, 0x00340000670x00, 68680x30, 1690x20, 2700x24, 25710x04, 12720x00, 8730x08, 28740x00, 53750x30, 1760x20, 30770x28, 8780x08, 2790x00, 3800x04, 35810x00, 85820x04, 21830x00, 66840x04, 19850x00, 68860x38, 1870x28, 24880x08, 20890x38, 1900x28, 12910x08, 124920x00, 73930x08, 12940x38, 1950x28, 7960x08, 6970x00, 7980x04, 31990x00, 311000x30, 11010x20, 51020x00, 301030x08, 241040x00, 211050x38, 11060x28, 81070x08, 61080x00, 171090x08, 431100x38, 11110x28, 121120x08, 27113end table114115116// ========================117// Function Definitions118// ========================119120public function SpecialSetup_CopyAniTiles121temp0 = 0122while temp0 < 16123Copy16x16Tile(temp1, temp2)124temp1++125temp2++126temp0++127loop128end function129130131public function SpecialSetup_ProcessHScroll132temp0 = oscillation133temp0 <<= 1134Sin(hParallax[8].scrollPos, temp0)135hParallax[8].scrollPos <<= 10136137temp0 = oscillation138temp0 <<= 2139Sin(hParallax[9].scrollPos, temp0)140hParallax[9].scrollPos <<= 9141142temp0 = oscillation143temp0 <<= 1144temp0 += 256145Sin(hParallax[10].scrollPos, temp0)146hParallax[10].scrollPos <<= 11147148temp0 = oscillation149temp0 <<= 2150temp0 += 128151Sin(hParallax[11].scrollPos, temp0)152hParallax[11].scrollPos <<= 9153end function154155156public function SpecialSetup_GetBlockPos157// This code is kinda hard to read, so here's what it'd look like in a more C-like syntax158// sx = (object.xpos - player[0].xpos) >> 8159// sy = (object.ypos - player[0].ypos) >> 8160// x = ((Sin(Player_stageRotation) * sx + Cos(Player_stageRotation) * sy) >> 1) + player[0].xpos161// y = ((Cos(Player_stageRotation) * sy - Sin(Player_stageRotation) * sx) >> 1) + player[0].ypos162163temp2 = object.xpos164temp2 -= player[0].xpos165temp2 >>= 8166temp3 = object.ypos167temp3 -= player[0].ypos168temp3 >>= 8169170Sin(temp4, Player_stageRotation)171temp4 *= temp3172Cos(temp5, Player_stageRotation)173temp5 *= temp2174temp0 = temp4175temp0 += temp5176temp0 >>= 1177temp0 += player[0].xpos178179Cos(temp4, Player_stageRotation)180temp4 *= temp3181Sin(temp5, Player_stageRotation)182temp5 *= temp2183temp1 = temp4184temp1 -= temp5185temp1 >>= 1186temp1 += player[0].ypos187188object.rotation = 512189object.rotation -= Player_stageRotation190end function191192193public function SpecialSetup_PlayerBlockCol194BoxCollisionTest(C_SOLID2, object.entityPos, -12, -12, 12, 12, 0, C_BOX, C_BOX, C_BOX, C_BOX)195if checkResult != COL_NONE196SetBit(player[0].collisionFlags, checkResult, true)197else198BoxCollisionTest(C_TOUCH, object.entityPos, -10, -10, 10, 10, 0, C_BOX, C_BOX, C_BOX, C_BOX)199if checkResult == true200temp0 = player[0].xvel201temp1 = player[0].yvel202Abs(temp0)203Abs(temp1)204205if temp0 > temp1206if player[0].xvel > 0207SetBit(player[0].collisionFlags, 2, true)208player[0].xpos = player[0].collisionLeft209player[0].xpos -= 12210player[0].xpos <<= 16211else212SetBit(player[0].collisionFlags, 3, true)213player[0].xpos = player[0].collisionRight214player[0].xpos += 12215player[0].xpos <<= 16216end if217218player[0].xpos += object.xpos219else220if player[0].yvel > 0221SetBit(player[0].collisionFlags, 1, true)222player[0].ypos = player[0].collisionTop223player[0].ypos -= 12224player[0].ypos <<= 16225else226SetBit(player[0].collisionFlags, 4, true)227player[0].ypos = player[0].collisionBottom228player[0].ypos += 12229player[0].ypos <<= 16230end if231232player[0].ypos += object.ypos233end if234end if235end if236end function237238239// ========================240// Events241// ========================242243event ObjectUpdate244if Player_rotateDir == 0245switch Player_rotateSpeed246case 0247temp0 = oscillation248temp0 &= 1249Player_stageRotation -= temp0250if Player_stageRotation < 0251Player_stageRotation += 512252end if253break254255case 1256Player_stageRotation--257if Player_stageRotation < 0258Player_stageRotation += 512259end if260break261end switch262else263switch Player_rotateSpeed264case 0265temp0 = oscillation266temp0 &= 1267Player_stageRotation += temp0268Player_stageRotation &= 511269break270271case 1272Player_stageRotation++273Player_stageRotation &= 511274break275end switch276end if277278oscillation++279oscillation &= 511280SpecialSetup_gemBlockTimer++281SpecialSetup_gemBlockTimer %= 20282SpecialSetup_blockTimer++283SpecialSetup_blockTimer &= 63284285// These aren't exactly the type of states that are in-depth and deserving of proper names so I hope you enjoy numbers286switch object.state287case 0288object.timer++289if object.timer == 8290object.timer = 0291object.bgClr.r = 0x00292object.bgClr.g = 0xA0293object.bgClr.b = 0xA0294object.bgClr.a = 0xFF295temp1 = 184296temp2 = 264297CallFunction(SpecialSetup_CopyAniTiles)298object.state++299end if300break301302case 1303object.timer++304if object.timer == 4305object.timer = 0306object.bgClr.r = 0x00307object.bgClr.g = 0x60308object.bgClr.b = 0x80309object.bgClr.a = 0xFF310object.state++311end if312break313314case 2315object.timer++316if object.timer == 4317object.timer = 0318object.bgClr.r = 0x00319object.bgClr.g = 0x40320object.bgClr.b = 0x60321object.bgClr.a = 0xFF322object.state++323end if324break325326case 3327object.timer++328if object.timer == 4329object.timer = 0330object.bgClr.r = 0x00331object.bgClr.g = 0x00332object.bgClr.b = 0x40333object.bgClr.a = 0xFF334object.state++335end if336break337338case 4339object.timer++340if object.timer == 4341object.timer = 0342stage.activeLayer[0] = 1343object.bgClr.r = 0x00344object.bgClr.g = 0x00345object.bgClr.b = 0x40346object.bgClr.a = 0xE0347temp1 = 104348temp2 = 136349CallFunction(SpecialSetup_CopyAniTiles)350object.state++351end if352break353354case 5355if object.bgClr.a > 0x00356object.bgClr.a -= 0x10357end if358359object.timer++360if object.timer == 8361object.timer = 0362temp1 = 104363temp2 = 152364CallFunction(SpecialSetup_CopyAniTiles)365object.state++366end if367break368369case 6370if object.bgClr.a > 0x00371object.bgClr.a -= 0x10372end if373374object.timer++375if object.timer == 8376object.timer = 0377stage.activeLayer[1] = 4378hParallax[0].scrollSpeed = -0x10000379object.state++380end if381break382383case 7384object.timer++385if object.timer == 1020386object.timer = 0387stage.activeLayer[1] = 3388hParallax[0].scrollSpeed = 0389object.state++390end if391break392393case 8394if object.bgClr.a < 0x00395object.bgClr.a += 0x10396end if397398object.timer++399if object.timer == 8400object.timer = 0401402temp1 = 104403temp2 = 136404CallFunction(SpecialSetup_CopyAniTiles)405object.state++406end if407break408409case 9410if object.bgClr.a < 0x00411object.bgClr.a += 0x10412end if413414object.timer++415if object.timer == 8416object.timer = 0417object.bgClr.r = 0x00418object.bgClr.g = 0x00419object.bgClr.b = 0x40420object.bgClr.a = 0xFF421temp1 = 104422temp2 = 120423CallFunction(SpecialSetup_CopyAniTiles)424object.state++425end if426break427428case 10429object.timer++430if object.timer == 4431object.timer = 0432object.bgClr.r = 0x00433object.bgClr.g = 0x40434object.bgClr.b = 0x60435object.bgClr.a = 0xFF436object.state++437end if438break439440case 11441object.timer++442if object.timer == 4443object.timer = 0444object.bgClr.r = 0x00445object.bgClr.g = 0x60446object.bgClr.b = 0x80447object.bgClr.a = 0xFF448object.state++449end if450break451452case 12453object.timer++454if object.timer == 4455object.timer = 0456object.bgClr.r = 0x00457object.bgClr.g = 0xA0458object.bgClr.b = 0xA0459object.bgClr.a = 0xFF460object.state++461end if462break463464case 13465object.timer++466if object.timer == 4467object.timer = 0468object.bgClr.a = 0x00469470temp1 = 184471temp2 = 200472CallFunction(SpecialSetup_CopyAniTiles)473object.state++474end if475break476477case 14478object.timer++479if object.timer == 8480object.timer = 0481object.bgClr.r = 0x60482object.bgClr.g = 0xC0483object.bgClr.b = 0x40484object.bgClr.a = 0xFF485temp1 = 104486temp2 = 264487CallFunction(SpecialSetup_CopyAniTiles)488object.state++489end if490break491492case 15493object.timer++494if object.timer == 4495object.timer = 0496object.bgClr.r = 0x40497object.bgClr.g = 0x80498object.bgClr.b = 0x40499object.bgClr.a = 0xFF500object.state++501end if502break503504case 16505object.timer++506if object.timer == 4507object.timer = 0508object.bgClr.r = 0x20509object.bgClr.g = 0x40510object.bgClr.b = 0x40511object.bgClr.a = 0xFF512object.state++513end if514break515516case 17517object.timer++518if object.timer == 4519object.timer = 0520object.bgClr.r = 0x00521object.bgClr.g = 0x00522object.bgClr.b = 0x40523object.bgClr.a = 0xFF524object.state++525end if526break527528case 18529object.timer++530if object.timer == 4531object.timer = 0532stage.activeLayer[0] = 2533object.bgClr.r = 0x00534object.bgClr.g = 0x00535object.bgClr.b = 0x40536object.bgClr.a = 0xE0537538temp1 = 184539temp2 = 216540CallFunction(SpecialSetup_CopyAniTiles)541object.state++542end if543break544545case 19546CallFunction(SpecialSetup_ProcessHScroll)547if object.bgClr.a > 0x00548object.bgClr.a -= 0x10549end if550551object.timer++552if object.timer == 8553object.timer = 0554555temp1 = 184556temp2 = 232557CallFunction(SpecialSetup_CopyAniTiles)558object.state++559end if560break561562case 20563CallFunction(SpecialSetup_ProcessHScroll)564if object.bgClr.a > 0x00565object.bgClr.a -= 0x10566end if567568object.timer++569if object.timer == 8570object.timer = 0571stage.activeLayer[1] = 5572hParallax[0].scrollSpeed = 0x10000573object.state++574end if575break576577case 21578CallFunction(SpecialSetup_ProcessHScroll)579object.timer++580if object.timer == 1020581object.timer = 0582stage.activeLayer[1] = 3583hParallax[0].scrollSpeed = 0584object.state++585end if586break587588case 22589CallFunction(SpecialSetup_ProcessHScroll)590if object.bgClr.a < 0x00591object.bgClr.a += 0x10592end if593594object.timer++595if object.timer == 8596object.timer = 0597598temp1 = 184599temp2 = 216600CallFunction(SpecialSetup_CopyAniTiles)601object.state++602end if603break604605case 23606CallFunction(SpecialSetup_ProcessHScroll)607if object.bgClr.a < 0x00608object.bgClr.a += 0x10609end if610611object.timer++612if object.timer == 8613object.timer = 0614object.bgClr.r = 0x00615object.bgClr.g = 0x00616object.bgClr.b = 0x40617object.bgClr.a = 0xFF618619temp1 = 184620temp2 = 200621CallFunction(SpecialSetup_CopyAniTiles)622object.state++623end if624break625626case 24627object.timer++628if object.timer == 4629object.timer = 0630object.bgClr.r = 0x20631object.bgClr.g = 0x40632object.bgClr.b = 0x40633object.bgClr.a = 0xFF634object.state++635end if636break637638case 25639object.timer++640if object.timer == 4641object.timer = 0642object.bgClr.r = 0x40643object.bgClr.g = 0x80644object.bgClr.b = 0x40645object.bgClr.a = 0xFF646object.state++647end if648break649650case 26651object.timer++652if object.timer == 4653object.timer = 0654object.bgClr.r = 0x60655object.bgClr.g = 0xC0656object.bgClr.b = 0x40657object.bgClr.a = 0xFF658object.state++659end if660break661662case 27663object.timer++664if object.timer == 4665object.timer = 0666object.bgClr.a = 0x00667temp1 = 104668temp2 = 120669CallFunction(SpecialSetup_CopyAniTiles)670object.state = 0671end if672break673674end switch675676ringTimer++677if ringTimer == 4678ringTimer = 0679ringFrame++680ringFrame &= 7681end if682683#platform: USE_ORIGINS684if game.coinMode != false685game.hudEnable = HUDENABLE_ON // There's no HUD in the Special Stage, even with this enabled. What's the point of this?686end if687#endplatform688end event689690691event ObjectDraw692screen.xoffset = player[0].xpos693screen.xoffset >>= 16694screen.xoffset -= screen.xcenter695696screen.yoffset = player[0].ypos697screen.yoffset >>= 16698screen.yoffset -= 104699700DrawRect(0, 0, screen.xsize, screen.ysize, object.bgClr.r, object.bgClr.g, object.bgClr.b, object.bgClr.a)701end event702703704event ObjectStartup705SetMusicTrack("Specialstage.ogg", TRACK_STAGE, true)706SetMusicTrack("ActComplete.ogg", TRACK_ACTFINISH, false)707708if options.gameMode == MODE_TIMEATTACK709object[SLOT_HUD].type = TypeName[HUD]710object[SLOT_HUD].priority = PRIORITY_ACTIVE711object[SLOT_HUD].drawOrder = 6712713// Wait huh, arrayPos0? Where'd that come from?714// This code might've just been copied from the standard Stage Setup code, where the HUD is set up within a foreach715object[SLOT_HUD].propertyValue = object[arrayPos0].propertyValue716717#platform: USE_STANDALONE718stage.timeEnabled = true719#endplatform720end if721722#platform: USE_ORIGINS723stage.timeEnabled = true724#endplatform725726object[19].type = TypeName[Special Setup]727object[19].priority = PRIORITY_ACTIVE728object[19].drawOrder = 1729730object[20].type = TypeName[Fade In]731object[20].priority = PRIORITY_ACTIVE732733stage.activeLayer[0] = 9734stage.activeLayer[1] = 3735stage.activeLayer[2] = 9736stage.activeLayer[3] = 9737738if options.attractMode == false739#platform: USE_ORIGINS740// This is likely "platform: STANDARD" instead, given how this condition was also in 2013, but technically we can't 100% confirm that...741stage.pauseEnabled = true742#endplatform743else744stage.pauseEnabled = false745options.touchControls = false746end if747748ringExtraLife = 100749SpecialSetup_gemBlockTimer = 0750SpecialSetup_gemBlockBusy = false751SpecialSetup_blockTimer = 0752Player_rotateSpeed = 0753Player_rotateDir = 0754755if options.attractMode == true756Player_attractTable = SpecialSetup_replay_attract_STK757Player_attractTableSize = 94758Player_attractDuration = 1200759CallFunction(Player_SetupAttractDemo)760end if761end event762763764// ========================765// Editor Events766// ========================767768event RSDKDraw769DrawSprite(0)770end event771772773event RSDKLoad774LoadSpriteSheet("Global/Display.gif")775SpriteFrame(-16, -16, 32, 32, 1, 143)776777SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")778end event779780781