Path: blob/main/Scripts/R7/MetalSonic.txt
1319 views
//----------------Sonic CD Metal Sonic Script-----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.Timer67#alias Object.Value1 : Object.XVelocity8#alias Object.Value2 : Object.YVelocity910// For the extra sprites associated with Metal Sonic, like his lightning effects11#alias Object.Value3 : Object.AccessoryAnimation12#alias Object.Value4 : Object.AccessoryFrame1314// State Aliases15#alias 0 : METALSONIC_WAITING16#alias 1 : METALSONIC_TURNRIGHT17#alias 2 : METALSONIC_STARTUP18#alias 3 : METALSONIC_ADVANCEMAIN19#alias 4 : METALSONIC_CHARGEUP20#alias 5 : METALSONIC_ELETRICSHIELD21#alias 6 : METALSONIC_DASHING22#alias 7 : METALSONIC_TAUNTING23#alias 8 : METALSONIC_DEFEATED2425// Accessory Aliases, to be set to Object.AccessoryAnimation26#alias 0 : ACCESSORY_NONE27#alias 1 : ACCESSORY_CHARGE128#alias 2 : ACCESSORY_CHARGE229#alias 3 : ACCESSORY_CHARGE330#alias 4 : ACCESSORY_LIGHTNING3132// Metal Sonic has an entire animation file, these aliases correspond to animations in there33#alias 0 : ANI_STANDING34#alias 1 : ANI_TAUNTING35#alias 2 : ANI_TURNING36#alias 3 : ANI_HOVERING37#alias 4 : ANI_HOVERINGFAST38#alias 5 : ANI_ELECTRIFIED39#alias 6 : ANI_DASHING140#alias 7 : ANI_DASHING241#alias 8 : ANI_DEFEATED42#alias 9 : ANI_CHARGING4344// If you're wondering what Metal Sonic's SpriteFrames are then, it's for his effects like lightning and such4546// Vertical Door States47#alias 2 : VERTICALDOOR_END_CLOSING48#alias 4 : VERTICALDOOR_END_CLOSING_METAL49#alias 6 : VERTICALDOOR_END_CLOSED_SONIC5051// Player Aliases52#alias 0 :PLAYER_SONIC_A5354// Collision Side Aliases55#alias 0 : CSIDE_FLOOR5657// Global SFX Aliases58#alias 22 : SFX_G_EXPLOSION5960// Stage SFX Aliases61#alias 4 : SFX_S_MSCHARGE62#alias 5 : SFX_S_MSELECTRIC63#alias 6 : SFX_S_MSJET6465// Priority Aliases66#alias 1 : PRIORITY_ACTIVE676869// Function declarations70#function MetalSonic_FollowGround717273function MetalSonic_FollowGround7475// Move Metal Sonic 32 pixels up to help him follow the ground76Object.YPos -= 0x2000007778ObjectTileGrip(CSIDE_FLOOR, 0, 20, 0)79if CheckResult == false8081// Metal Sonic's in the air, move him 16 pixels down and try again82Object.YPos += 0x1000008384ObjectTileGrip(CSIDE_FLOOR, 0, 20, 0)85if CheckResult == false8687// He's still airborne even after moving him down before,88// Move him even further down and try again89Object.YPos += 0x1000009091ObjectTileGrip(CSIDE_FLOOR, 0, 20, 0)92end if93end if9495end function969798sub ObjectMain99switch Object.State100case METALSONIC_WAITING101if Object.Animation == ANI_STANDING102if Player.JumpPress == true103// Player's goofing around, go ahead and taunt them for two seconds104Object.Timer = 120105Object.Animation = ANI_TAUNTING106end if107else // Object.Animation == ANI_TAUNTING108if Object.Timer > 0109Object.Timer--110else111Object.Animation = ANI_STANDING112end if113end if114break115116case METALSONIC_TURNRIGHT117// (He is turning to our right btw, not his right)118119if Object.Timer < 140120Object.Timer++121else122// From this point on make Metal Sonic always active, as the player may overtake it during the race and put it out of normal bounds123Object.Priority = PRIORITY_ACTIVE124125// Get ready...126Object.Timer = 0127Object.AccessoryAnimation = ACCESSORY_CHARGE1128Object.AccessoryFrame = 0129Object.State++130end if131break132133case METALSONIC_STARTUP134if Object.Timer < 204135Object.Timer++136else137// And take off, at the speed of sound! (4 pixels per frame, to be exact!)138139Object.Timer = 0140Object.AccessoryAnimation = ACCESSORY_CHARGE2141Object.Animation = ANI_HOVERINGFAST142Object.XVelocity = 0x40000143144// Reset the achievement value145Player.HeavyMetalFlag = true146147Object.State++148end if149break150151case METALSONIC_ADVANCEMAIN152// (Object [-2] is the final vertical door at the end of the race)153TempValue0 = Object[-2].XPos154TempValue0 -= 0x7000000155156// Is the final door farther than 1792 pixels from Metal Sonic?157if Object.XPos < TempValue0158159// Go at a speed depending on how far the player is160TempValue0 = Object.XPos161TempValue0 -= Player.XPos162TempValue0 >>= 6163Object.XVelocity = 0x40000164Object.XVelocity -= TempValue0165166// Minimum speed of 2 pixels per frame167if Object.XVelocity < 0x20000168Object.XVelocity = 0x20000169end if170171// Maximum speed of 6 pixels per frame172if Object.XVelocity > 0x60000173Object.XVelocity = 0x60000174end if175176// Threshold for the 3rd charge level animation is 3.75 pixels per frame177if Object.XVelocity < 0x3C000178Object.AccessoryAnimation = ACCESSORY_CHARGE2179Object.Animation = ANI_HOVERING180else181Object.AccessoryAnimation = ACCESSORY_CHARGE3182Object.Animation = ANI_HOVERINGFAST183end if184185if Object.Timer < 180186Object.Timer++187else188// Start attacking189Object.Animation = ANI_CHARGING190Object.Timer = 0191Object.AccessoryAnimation = ACCESSORY_CHARGE1192Object.State++193PlayStageSfx(SFX_S_MSCHARGE, false)194end if195else196// Metal Sonic is within 1792 pixels of the door197198// Go at a speed depending on how far the player is199TempValue0 = Object.XPos200TempValue0 -= Player.XPos201TempValue0 >>= 6202Object.XVelocity = 0x40000203Object.XVelocity -= TempValue0204205// Minimum speed of 2 pixels per frame206if Object.XVelocity < 0x20000207Object.XVelocity = 0x20000208end if209210// Maximum speed of 6 pixels per frame211if Object.XVelocity > 0x60000212Object.XVelocity = 0x60000213end if214215// Threshold for the 3rd charge level animation is 3.75 pixels per frame216if Object.XVelocity < 0x3C000217Object.AccessoryAnimation = ACCESSORY_CHARGE2218Object.Animation = ANI_HOVERING219else220Object.AccessoryAnimation = ACCESSORY_CHARGE3221Object.Animation = ANI_HOVERINGFAST222end if223224// Removed code here so that Metal doesn't switch states while near the door225end if226break227228case METALSONIC_CHARGEUP229if Object.Timer < 60230Object.Timer++231else232Object.Timer = 0233if Player.XPos > Object.XPos234// If the player's ahead of Metal Sonic then we gotta catch up, start a Super Dash!235236Object.State = METALSONIC_DASHING237Object.Animation = ANI_DASHING1238Object.AccessoryAnimation = ACCESSORY_NONE239Object.AccessoryFrame = 0240PlayStageSfx(SFX_S_MSJET, false)241242#platform: Use_Haptics243// and play a super dash-esque motion as well, even if the player probably doesn't even see Metal Sonic...244HapticEffect(55, 0, 0, 0)245#endplatform246247else248// The player's behind Metal Sonic so we don't want to run too far, just initiate the Eletric Shield instead249Object.State = METALSONIC_ELETRICSHIELD250251// Slowing down to a speed of 2 pixels per frame252Object.XVelocity = 0x20000253Object.Animation = ANI_ELECTRIFIED254Object.AccessoryAnimation = ACCESSORY_LIGHTNING255Object.AccessoryFrame = 0256PlayStageSfx(SFX_S_MSELECTRIC, false)257258#platform: Use_Haptics259HapticEffect(60, 0, 0, 0)260#endplatform261262end if263end if264break265266case METALSONIC_ELETRICSHIELD267if Object.Timer < 180268Object.Timer++269270TempValue0 = Object[-1].XPos271TempValue0 += 0x400000272273// See if Metal Sonic is past 64 pixels from the starting door274if Object.XPos < TempValue0275Object.State = METALSONIC_DASHING276Object.Timer = 60277Object.Animation = ANI_DASHING2278Object.AccessoryAnimation = ACCESSORY_NONE279Object.AccessoryFrame = 0280PlayStageSfx(SFX_S_MSJET, false)281282#platform: Use_Haptics283HapticEffect(55, 0, 0, 0)284#endplatform285286end if287else288Object.Timer = 0289Object.State = METALSONIC_ADVANCEMAIN290Object.AccessoryFrame = 0291end if292break293294case METALSONIC_DASHING295Object.XVelocity += 0x800296if Object.XVelocity > 0x80000297Object.XVelocity = 0x80000298end if299300if Object.Timer < 180301Object.Timer++302if Object.Timer == 10303Object.Animation = ANI_DASHING2304end if305else306Object.Timer = 0307Object.State = METALSONIC_ADVANCEMAIN308end if309break310311case METALSONIC_TAUNTING312// This State is used if Metal Sonic passes the final door before Sonic does313314// Wait for the Player to die, then start taunting them315if Player.Animation == ANI_DYING316Object.Animation = ANI_TAUNTING317end if318break319320case METALSONIC_DEFEATED321// This state is used for Metal Sonic after being killed with Robotnik's laser322323Object.YVelocity += 0x3800324Object.YPos += Object.YVelocity325326if Object.YVelocity > 0x100000327ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, 0, 0)328329#platform: Use_Origins330// Some new code for Origins's Boss Rush331332// Let the game know we've finished the Boss333// -> This code also exists in the Amy 1 Object, though that doesn't have any effect since this code is reached first334game.callbackParam0 = true335EngineCallback(NOTIFY_BOSS_END)336337if game.playMode == BOOT_PLAYMODE_BOSSRUSH338// With how transitions in Boss Rush work, just stop the music here with no fade or anything339340StopMusic()341end if342#endplatform343344end if345break346347end switch348349if Object.XVelocity > 0350351// Object[-1] is the first door in the race352TempValue0 = Object[-1].XPos353TempValue0 += 0x400000354355// Make sure Metal Sonic is always at least 64 pixels past the first door356if Object.XPos < TempValue0357Object.XPos = TempValue0358end if359360// At higher speeds, we want to be more weary to avoid Robotnik's diabolical traps...361if Object.XVelocity > 0x30000362TempValue0 = Object.XVelocity363TempValue0 -= 0x30000364365Object.XPos += 0x30000366CallFunction(MetalSonic_FollowGround)367368Object.XPos += TempValue0369CallFunction(MetalSonic_FollowGround)370else371Object.XPos += Object.XVelocity372CallFunction(MetalSonic_FollowGround)373end if374375if CheckResult == true376// If on the ground, reset Metal Sonic's Y Velocity377Object.YVelocity = 0378else379Object.YVelocity += 0x3800380Object.YPos += Object.YVelocity381end if382383// Object [-2] is the final vertical door at the end of the race384switch Object[-2].State385case VERTICALDOOR_END_CLOSING386case VERTICALDOOR_END_CLOSED_SONIC387// Door in its closed state, meaning Metal Sonic lost and Sonic won388389if Player.HeavyMetalFlag == true390if Stage.PlayerListPos == PLAYER_SONIC_A391// Player managed to get through the fight without getting hit, give them the Heavy Metal achievment392SetAchievement(6, 100)393end if394end if395396TempValue0 = Object[-2].XPos397TempValue0 -= 0x1E0000398if Object.XPos > TempValue0399Object.XPos = TempValue0400Object.XVelocity = 0401Object.YVelocity = -0x68000402403Object.AccessoryAnimation = ACCESSORY_NONE404Object.Animation = ANI_DEFEATED405406Object.State = METALSONIC_DEFEATED407CreateTempObject(TypeName[Explosion], 0, Object.XPos, Object.YPos)408409// Create some Debris, with randomised properties410TempValue0 = 0411TempValue1 = 4412while TempValue0 < 8413CreateTempObject(TypeName[Debris], TempValue1, Object.XPos, Object.YPos)414Rand(Object[TempObjectPos].XVelocity, 4)415Object[TempObjectPos].YVelocity++416Object[TempObjectPos].XVelocity <<= 16417FlipSign(Object[TempObjectPos].XVelocity)418Rand(Object[TempObjectPos].YVelocity, 3)419Object[TempObjectPos].YVelocity += 2420Object[TempObjectPos].YVelocity <<= 16421FlipSign(Object[TempObjectPos].YVelocity)422TempValue0++423TempValue1++424if TempValue1 > 8425TempValue1 = 4426end if427loop428429PlaySfx(SFX_G_EXPLOSION, false)430431#platform: Use_Haptics432HapticEffect(90, 0, 0, 0)433#endplatform434435end if436break437438case VERTICALDOOR_END_CLOSING_METAL439TempValue0 = Object[-2].XPos440TempValue0 += 0x240000441if Object.XPos > TempValue0442Object.XPos = TempValue0443Object.XVelocity = 0444Object.AccessoryAnimation = ACCESSORY_NONE445Object.Animation = ANI_STANDING446Object.State = METALSONIC_TAUNTING447end if448break449450end switch451452end if453454ProcessAnimation()455end sub456457458sub ObjectPlayerInteraction459switch Object.Animation460case ANI_ELECTRIFIED461case ANI_DASHING2462// Metal Sonic is in a sparking animation, harm the player if they make contact463PlayerObjectCollision(C_TOUCH, -16, -12, 16, 12)464if CheckResult == true465CallFunction(Player_Hit)466467// Now that the player's been hit, the achievement is unobtainable468Player.HeavyMetalFlag = false469end if470471// (No break used here since there's nothing following)472473end switch474475end sub476477478sub ObjectDraw479// First, draw Metal Sonic's "accessory" (of sorts) behind him480switch Object.AccessoryAnimation481482// ACCESSORY_NONE is an unhandled case since it's supposed to show nothing483484case ACCESSORY_CHARGE1485TempValue0 = Object.AccessoryFrame486TempValue0 >>= 1487DrawSprite(TempValue0)488Object.AccessoryFrame++489Object.AccessoryFrame &= 7490break491492case ACCESSORY_CHARGE2493TempValue0 = Object.AccessoryFrame494TempValue0 >>= 1495TempValue0 += 4496DrawSprite(TempValue0)497Object.AccessoryFrame++498Object.AccessoryFrame &= 7499break500501case ACCESSORY_CHARGE3502TempValue0 = Object.AccessoryFrame503TempValue0 >>= 1504TempValue0 += 8505DrawSprite(TempValue0)506Object.AccessoryFrame++507Object.AccessoryFrame &= 7508break509510case ACCESSORY_LIGHTNING511TempValue0 = Object.AccessoryFrame512TempValue0 += 12513DrawSprite(TempValue0)514Object.AccessoryFrame++515Object.AccessoryFrame %= 10516break517518end switch519520// And now draw Metal Sonic himself, notably done here so he appears on top of these other sprites521DrawObjectAnimation()522523end sub524525526sub ObjectStartup527528LoadSpriteSheet("R7/Objects3.gif")529530LoadAnimation("MetalSonic.Ani")531532// 0-3 - Thruster Frames Set 1533SpriteFrame(0, 0, 0, 0, 1, 83)534SpriteFrame(-12, 3, 16, 16, 1, 83)535SpriteFrame(0, 0, 0, 0, 1, 83)536SpriteFrame(-12, 3, 16, 16, 18, 83)537538// 4-7 - Thruster Frames Set 2539SpriteFrame(0, 0, 0, 0, 1, 83)540SpriteFrame(-14, -8, 16, 16, 18, 83)541SpriteFrame(0, 0, 0, 0, 1, 83)542SpriteFrame(-18, -12, 24, 24, 1, 100)543544// 8-11 - Thruster Frames Set 3545SpriteFrame(0, 0, 0, 0, 1, 83)546SpriteFrame(-18, -12, 24, 24, 1, 100)547SpriteFrame(0, 0, 0, 0, 1, 83)548SpriteFrame(-22, -16, 32, 32, 1, 125)549550// 12-16 - Static Charge Shield Frames551SpriteFrame(-24, -28, 48, 48, 150, 75)552SpriteFrame(-24, -28, 48, 48, 150, 75)553SpriteFrame(-24, -28, 48, 48, 150, 75)554SpriteFrame(-24, -28, 48, 48, 150, 75)555SpriteFrame(0, 0, 0, 0, 1, 83)556SpriteFrame(-24, -28, 48, 48, 199, 75)557SpriteFrame(-24, -28, 48, 48, 199, 75)558SpriteFrame(-24, -28, 48, 48, 199, 75)559SpriteFrame(-24, -28, 48, 48, 199, 75)560SpriteFrame(0, 0, 0, 0, 1, 83)561562ArrayPos0 = 32563while ArrayPos0 < 1056564if Object[ArrayPos0].Type == TypeName[Metal Sonic]565566// Store Metal Sonic's EntityNo to the global variable for it567// -> It's used by Break Spikes to know when they should break568MetalSonic_EntityNo = ArrayPos0569570end if571572ArrayPos0++573loop574575end sub576577578// ========================579// Editor Subs580// ========================581582sub RSDKDraw583DrawSprite(0)584end sub585586587sub RSDKLoad588LoadSpriteSheet("R7/Objects3.gif")589SpriteFrame(-20, -20, 40, 40, 83, 1) // Pose for the fans!590591SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")592end sub593594595