Path: blob/main/Scripts/R5/DropRock.txt
1319 views
//-----------------Sonic CD Drop Rock Script------------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.XVelocity6#alias Object.Value1 : Object.YVelocity7#alias Object.Value2 : Object.OriginsPosY89#alias 0 : DROPROCK_IDLE10#alias 1 : DROPROCK_FALLING11#alias 2 : DROPROCK_WAITFORRESPAWN12#alias 3 : DROPROCK_FRAGMENT1314// Global SFX15#alias 22 : SFX_G_EXPLOSION1617// Collision Sides18#alias 0 : CSIDE_FLOOR1920// Box Collision21#alias 4 : PLAYER_COL_ROOF2223// Priority24#alias 0 : PRIORITY_BOUNDS25#alias 1 : PRIORITY_ACTIVE2627// Property Values28#alias 1 : ROCK_DEBRIS_129#alias 2 : ROCK_DEBRIS_230#alias 3 : ROCK_DEBRIS_331#alias 4 : ROCK_DEBRIS_432333435sub ObjectMain3637switch Object.State3839// state DROPROCK_IDLE doesn't have anything40// It's handled over in ObjectPlayerInteraction instead4142case DROPROCK_FALLING4344// If not yet falling at a speed of 8 px/frame, accelerate a rate of 0.25 per frame45if Object.YVelocity < 0x8000046Object.YVelocity += 0x400047end if4849Object.YPos += Object.YVelocity5051// Only check for Collision if the Object is falling at a rate faster than 2px per frame52if Object.YVelocity > 0x2000053ObjectTileCollision(CSIDE_FLOOR, 0, 12, 0)54if CheckResult == true55PlaySfx(SFX_G_EXPLOSION, 0)5657// Make the Rock invisible and make it wait for respawning58Object.State = DROPROCK_WAITFORRESPAWN5960// Create all the Rock Fragments now61// The appropriate info for each Fragment is listed as needed, in the format of62// X: X offset from the Rock's base position63// Y: Y offset from the Rock's base position64// XVel: Starting X Velocity of the Fragment65// YVel: Starting Y Velocity of the Fragment6667// Top left Fragment!68// - X: 8 pixels left69// - Y: 8 pixels up70// - XVel: 1 pixel per frame left71// - YVel: 4 pixels per frame up72CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_1, Object.XPos, Object.YPos)73Object[TempObjectPos].State = DROPROCK_FRAGMENT74Object[TempObjectPos].XPos -= 0x8000075Object[TempObjectPos].YPos -= 0x8000076Object[TempObjectPos].XVelocity = -0x1000077Object[TempObjectPos].YVelocity = -0x4000078Object[TempObjectPos].DrawOrder = 57980// Top right Fragment:81// - X: 8 pixels right82// - Y: 8 pixels up83// - XVel: 1 pixel per frame right84// - YVel: 4 pixels per frame up85CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_2, Object.XPos, Object.YPos)86Object[TempObjectPos].State = DROPROCK_FRAGMENT87Object[TempObjectPos].XPos += 0x8000088Object[TempObjectPos].YPos -= 0x8000089Object[TempObjectPos].XVelocity = 0x1000090Object[TempObjectPos].YVelocity = -0x4000091Object[TempObjectPos].DrawOrder = 59293// Bottom left Fragment:94// - X: 8 pixels right95// - Y: 8 pixels up96// - XVel: 2 pixels per frame left97// - YVel: 2 pixels per frame up98CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_3, Object.XPos, Object.YPos)99Object[TempObjectPos].State = DROPROCK_FRAGMENT100Object[TempObjectPos].XPos -= 0x80000101Object[TempObjectPos].YPos += 0x80000102Object[TempObjectPos].XVelocity = -0x20000103Object[TempObjectPos].YVelocity = -0x20000104Object[TempObjectPos].DrawOrder = 5105106// Bottom right Fragment:107// - X: 8 pixels right108// - Y: 8 pixels down109// - XVel: 2 pixels per frame right110// - YVel: 2 pixels per frame up111CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_4, Object.XPos, Object.YPos)112Object[TempObjectPos].State = DROPROCK_FRAGMENT113Object[TempObjectPos].XPos += 0x80000114Object[TempObjectPos].YPos += 0x80000115Object[TempObjectPos].XVelocity = 0x20000116Object[TempObjectPos].YVelocity = -0x20000117Object[TempObjectPos].DrawOrder = 5118119// And then carrying on from the Explosion SFX from a while ago, create an Explosion effect too now120CreateTempObject(TypeName[Explosion], 0, Object.XPos, Object.YPos)121Object[TempObjectPos].DrawOrder = 5122123end if124end if125break126127case DROPROCK_WAITFORRESPAWN128// This state is given to the Rock after it explodes,129// in order to make sure it doesn't warp back to its130// starting position right in front of the Player131132if Object.OutOfBounds == true133Object.YPos = Object.OriginsPosY134Object.Priority = PRIORITY_BOUNDS135Object.State = DROPROCK_IDLE136end if137break138139case DROPROCK_FRAGMENT140141// Update horizontal movements142Object.XPos += Object.XVelocity143144// Make the Fragment accelerate vertically at a rate of 0.25px/frame145Object.YVelocity += 0x4000146147// And then update vertical movements148Object.YPos += Object.YVelocity149150if Object.OutOfBounds == true151// Unload when no longer needed152Object.Type = TypeName[Blank Object]153end if154break155156end switch157158end sub159160161sub ObjectPlayerInteraction162163switch Object.State164case DROPROCK_IDLE165// First, act as a Box for the Player166PlayerObjectCollision(C_BOX, -16, -16, 16, 16)167168// Then, see if the Player has walked below the Rock169PlayerObjectCollision(C_TOUCH, -4, 0, 4, 96)170171if CheckResult == true172// If they have, then start Falling173174Object.OriginsPosY = Object.YPos175Object.Priority = PRIORITY_ACTIVE176Object.YVelocity = 0177Object.State = DROPROCK_FALLING178end if179180// [Fallthrough, to check if the Player has actually touched the rock]181182case DROPROCK_FALLING183184// Check Collision with Player185PlayerObjectCollision(C_BOX, -16, -16, 12, 16)186187// Did the Player hit their head on the bottom of this rock?188if CheckResult == PLAYER_COL_ROOF189// Explode!190191PlaySfx(SFX_G_EXPLOSION, 0)192193Object.State = DROPROCK_WAITFORRESPAWN194195CallFunction(Player_Hit)196197// Create all the Rock Fragments, since the Rock's been exploded198199// The initial info for each Fragment is listed as needed, in the following format:200// X: X offset from the Rock's base position201// Y: Y offset from the Rock's base position202// XVel: Starting X Velocity of the Fragment203// YVel: Starting Y Velocity of the Fragment204205// Top left Fragment:206// - X: 8 pixels left207// - Y: 8 pixels up208// - XVel: 1 pixel per frame right209// - YVel: 4 pixels per frame up210CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_1, Object.XPos, Object.YPos)211Object[TempObjectPos].State = DROPROCK_FRAGMENT212Object[TempObjectPos].XPos -= 0x80000213Object[TempObjectPos].YPos -= 0x80000214Object[TempObjectPos].XVelocity = -0x10000215Object[TempObjectPos].YVelocity = -0x40000216Object[TempObjectPos].DrawOrder = 5217218// Top right Fragment:219// - X: 8 pixels right220// - Y: 8 pixels up221// - XVel: 1 pixel per frame right222// - YVel: 4 pixels per frame up223CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_2, Object.XPos, Object.YPos)224Object[TempObjectPos].State = DROPROCK_FRAGMENT225Object[TempObjectPos].XPos += 0x80000226Object[TempObjectPos].YPos -= 0x80000227Object[TempObjectPos].XVelocity = 0x10000228Object[TempObjectPos].YVelocity = -0x40000229Object[TempObjectPos].DrawOrder = 5230231// Bottom left Fragment:232// - X: 8 pixels left233// - Y: 8 pixels down234// - XVel: 2 pixels per frame left235// - YVel: 3 pixels per frame up236CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_3, Object.XPos, Object.YPos)237Object[TempObjectPos].State = DROPROCK_FRAGMENT238Object[TempObjectPos].XPos -= 0x80000239Object[TempObjectPos].YPos += 0x80000240Object[TempObjectPos].XVelocity = -0x20000241Object[TempObjectPos].YVelocity = -0x30000242Object[TempObjectPos].DrawOrder = 5243244// Bottom right Fragment:245// - X: 8 pixels right246// - Y: 8 pixels down247// - XVel: 2 pixels per frame right248// - YVel: 3 pixels per frame up249CreateTempObject(TypeName[Drop Rock], ROCK_DEBRIS_4, Object.XPos, Object.YPos)250Object[TempObjectPos].State = DROPROCK_FRAGMENT251Object[TempObjectPos].XPos += 0x80000252Object[TempObjectPos].YPos += 0x80000253Object[TempObjectPos].XVelocity = 0x20000254Object[TempObjectPos].YVelocity = -0x30000255Object[TempObjectPos].DrawOrder = 5256CreateTempObject(TypeName[Explosion], 0, Object.XPos, Object.YPos)257Object[TempObjectPos].DrawOrder = 5258end if259break260261end switch262263end sub264265266sub ObjectDraw267268switch Object.State269case DROPROCK_IDLE270case DROPROCK_FALLING271// Draw the Rock Sprite272DrawSprite(0)273break274275// DROPROCK_WAITFORRESPAWN shouldn't draw anything,276// the Rock's meant to be invisible at that point277278case DROPROCK_FRAGMENT279// Draw the Fragment's given Frame280DrawSprite(Object.PropertyValue)281break282283end switch284285end sub286287288sub ObjectStartup289290LoadSpriteSheet("R5/Objects.gif")291292// Main Rock Frame293SpriteFrame(-16, -16, 32, 32, 92, 18)294295// The rest here are Rock Fragment Frames296297// Top Left Frame298SpriteFrame(-8, -8, 16, 16, 92, 18)299300// Top Right Frame301SpriteFrame(-8, -8, 16, 16, 108, 18)302303// Bottom Left Frame304SpriteFrame(-8, -8, 16, 16, 92, 34)305306// Bottom Right Frame307SpriteFrame(-8, -8, 16, 16, 108, 34)308309end sub310311312// ========================313// Editor Subs314// ========================315316sub RSDKDraw317if Editor.ShowGizmos == true318// Draw a downwards arrow to show that this Rock is of the falling variety319320TempValue0 = Object.YPos321TempValue0 += 0x300000322323Editor.DrawingOverlay = true324325DrawArrow(Object.XPos, Object.YPos, Object.XPos, TempValue0, 255, 255, 255)326327Editor.DrawingOverlay = false328end if329330DrawSprite(0)331end sub332333334sub RSDKLoad335LoadSpriteSheet("R5/Objects.gif")336SpriteFrame(-16, -16, 32, 32, 92, 18)337338// Although used by the Object, it's not to be set from the Editor339SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")340end sub341342343