Path: blob/main/Scripts/R7/SpikeBallLauncher.txt
1319 views
//---------------Sonic CD Spike Launcher Script---------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.Timer67// Position is an offset relative to the base Spike Launcher Object, in world-space8#alias Object.Value1 : Object.SpikeBallPosition9#alias Object.Value2 : Object.SpikeBallVelocity1011#alias 0 : SPIKELAUNCHER_INIT12#alias 1 : SPIKELAUNCHER_RAISING13#alias 2 : SPIKELAUNCHER_PAUSE14#alias 3 : SPIKELAUNCHER_THROWN15#alias 4 : SPIKELAUNCHER_CATCHING1617// Priority18#alias 0 : PRIORITY_BOUNDS19#alias 1 : PRIORITY_ACTIVE2021// Property Values22#alias 0 : LAUNCH_DIR_UP23#alias 1 : LAUNCH_DIR_DOWN24#alias 2 : LAUNCH_DIR_LEFT25#alias 3 : LAUNCH_DIR_RIGHT262728sub ObjectMain2930switch Object.State31case SPIKELAUNCHER_INIT32// Set the object to always be active33Object.Priority = PRIORITY_ACTIVE3435// Give it a bit of time before starting the object's main routine proper36if Object.Timer < 15037Object.Timer++38else39Object.Timer = 040Object.SpikeBallPosition = 041Object.State++42end if43break4445case SPIKELAUNCHER_RAISING46// Start by poking the Spike Ball out of the Launcher's face, half a pixel per frame at a time47if Object.Timer < 3248Object.Timer++49Object.SpikeBallPosition -= 0x800050else51Object.Timer = 052Object.State++53end if54break5556case SPIKELAUNCHER_PAUSE57// Now, pause for a moment before shooting the Spike Ball away58if Object.Timer < 3059Object.Timer++60else61Object.Timer = 06263// Initial velocity of 6 pixels per frame64Object.SpikeBallVelocity = -0x600006566Object.State++67end if68break6970case SPIKELAUNCHER_THROWN71if Object.SpikeBallPosition < 072// Apply a gravity of 0.25 pixels to the Spike Ball every frame73Object.SpikeBallVelocity += 0x40007475// And then actually add the Velocity to the Spike Ball's position76Object.SpikeBallPosition += Object.SpikeBallVelocity77else78Object.State++79end if80break8182case SPIKELAUNCHER_CATCHING83if Object.Timer < 4084Object.Timer++85else86Object.Timer = 087Object.SpikeBallPosition = 088Object.State = SPIKELAUNCHER_RAISING89end if90break9192end switch9394if Object.OutOfBounds == true9596// Reset the object and give it normal priority9798Object.State = SPIKELAUNCHER_INIT99Object.Timer = 0100Object.Priority = PRIORITY_BOUNDS101102end if103104end sub105106107sub ObjectPlayerInteraction108109// Only check for Spike Ball collisions if it's a state where the Spike ball is actually visible110switch Object.State111case SPIKELAUNCHER_RAISING112case SPIKELAUNCHER_PAUSE113case SPIKELAUNCHER_THROWN114115// First, backup the base object's position116TempValue0 = Object.XPos117TempValue1 = Object.YPos118119// Then, add the corresponding offset based on the Spike Ball's position120switch Object.PropertyValue121case LAUNCH_DIR_UP122// Upwards123Object.YPos += Object.SpikeBallPosition124break125126case LAUNCH_DIR_DOWN127// Downwards128Object.YPos -= Object.SpikeBallPosition129break130131case LAUNCH_DIR_LEFT132// Left133Object.XPos += Object.SpikeBallPosition134break135136case LAUNCH_DIR_RIGHT137// Right138Object.XPos -= Object.SpikeBallPosition139break140141end switch142143// Check collision with the player & hurt them if needed144PlayerObjectCollision(C_TOUCH, -12, -12, 12, 12)145if CheckResult == true146CallFunction(Player_Hit)147end if148149// Restore the object's base position150Object.XPos = TempValue0151Object.YPos = TempValue1152153// No break is used here, although it doesn't matter too much anyway since there's nothing afterwards154155end switch156157end sub158159160161sub ObjectDraw162163if Object.DrawOrder == 3164// Drawing the Spike Ball...165166switch Object.State167case SPIKELAUNCHER_RAISING168case SPIKELAUNCHER_PAUSE169case SPIKELAUNCHER_THROWN170switch Object.PropertyValue171case LAUNCH_DIR_UP172// Upwards173TempValue0 = Object.YPos174TempValue0 += Object.SpikeBallPosition175DrawSpriteXY(4, Object.XPos, TempValue0)176break177178case LAUNCH_DIR_DOWN179// Downwards180TempValue0 = Object.YPos181TempValue0 -= Object.SpikeBallPosition182DrawSpriteXY(4, Object.XPos, TempValue0)183break184185case LAUNCH_DIR_LEFT186// Facing left187TempValue0 = Object.XPos188TempValue0 += Object.SpikeBallPosition189DrawSpriteXY(4, TempValue0, Object.YPos)190break191192case LAUNCH_DIR_RIGHT193// Facing right194TempValue0 = Object.XPos195TempValue0 -= Object.SpikeBallPosition196DrawSpriteXY(4, TempValue0, Object.YPos)197break198199end switch // Object.PropertyValue200201// No break is used here, as it's not needed202203end switch // Object.State204205// Add the Object to Draw List 4 so that its other half can draw above the Spike Ball206SetDrawListEntityRef(Object.EntityNo, 4, Screen.DrawListSize[4])207Screen.DrawListSize[4]++208Object.DrawOrder = 4209210else211// Drawing the Spike Ball Launcher itself...212213// The object's direction is stored in its Property Value, which also happens to align with the correct Sprite Frames214DrawSprite(Object.PropertyValue)215216// Reset the object's Draw Order back to 3 so that this whole process can be done again next frame217Object.DrawOrder = 3218end if219220end sub221222223224sub ObjectStartup225226LoadSpriteSheet("R7/Objects.gif")227228// Upwards Launcher Frame229SpriteFrame(-16, -16, 32, 16, 133, 1)230231// Downwards Launcher Frame232SpriteFrame(-16, 0, 32, 16, 166, 1)233234// Left-facing Launcher Frame235SpriteFrame(-16, -16, 16, 32, 1, 166)236237// Right-facing Launcher Frame238SpriteFrame(0, -16, 16, 32, 17, 166)239240// Spike Ball Frame241SpriteFrame(-16, -16, 32, 32, 1, 199)242243end sub244245246// ========================247// Editor Subs248// ========================249250sub RSDKEdit251if Editor.ReturnVariable == true252switch Editor.VariableID253case EDIT_VAR_PROPVAL // Property Value254CheckResult = Object.PropertyValue255break256case 0 // Direction257CheckResult = Object.PropertyValue258break259end switch260else261switch Editor.VariableID262case EDIT_VAR_PROPVAL // Property Value263Object.PropertyValue = Editor.VariableValue264break265case 0 // Direction266Object.PropertyValue = Editor.VariableValue267break268end switch269end if270end sub271272273sub RSDKDraw274DrawSprite(4)275DrawSprite(Object.PropertyValue)276277if Editor.ShowGizmos == true278Editor.DrawingOverlay = true279280TempValue0 = Object.XPos281TempValue1 = Object.YPos282283switch Object.PropertyValue284case 0285default286TempValue1 -= 0x300000; break;287case 1288TempValue1 += 0x300000; break;289case 2290TempValue0 -= 0x300000; break;291case 3292TempValue0 += 0x300000; break;293end switch294295DrawArrow(Object.XPos, Object.YPos, TempValue0, TempValue1, 255, 255, 255)296297Editor.DrawingOverlay = false298end if299end sub300301302sub RSDKLoad303LoadSpriteSheet("R7/Objects.gif")304SpriteFrame(-16, -16, 32, 16, 133, 1)305SpriteFrame(-16, 0, 32, 16, 166, 1)306SpriteFrame(-16, -16, 16, 32, 1, 166)307SpriteFrame(0, -16, 16, 32, 17, 166)308SpriteFrame(-16, -16, 32, 32, 1, 199)309310AddEditorVariable("Direction")311SetActiveVariable("Direction")312AddEnumVariable("Up", 0)313AddEnumVariable("Down", 1)314AddEnumVariable("Left", 2)315AddEnumVariable("Right", 3)316end sub317318319