Path: blob/main/Scripts/R7/Kanabun.txt
1319 views
//------------------Sonic CD Kanabun Script-------------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.Timer6#alias Object.Value1 : Object.Angle7#alias Object.Value2 : Object.StartPosX8#alias Object.Value3 : Object.StartPosY9#alias Object.Value4 : Object.Depth10#alias Object.Value5 : Object.ReturnDrawOrder1112#alias Object.PropertyValue : Object.Quality1314// States15#alias 0 : KANABUN_FLYL16#alias 1 : KANABUN_FLYR17#alias 2 : KANABUN_OFFSCREEN1819// Badnik Quality / Property Values20#alias 0 : GOOD_QUALITY21#alias 1 : BAD_QUALITY22#alias 2 : HIGH_LAYER_GOOD2324// Priority25#alias 0 : PRIORITY_BOUNDS26#alias 1 : PRIORITY_ACTIVE272829sub ObjectMain30if Object.OutOfBounds == true31Object.State = KANABUN_OFFSCREEN32Object.Timer = 033Object.Angle = 25634Object.Direction = FACING_RIGHT35Object.XPos = Object.StartPosX36Object.YPos = Object.StartPosY37end if3839// The different Kanabun types have their own main update routines40// However, their main State Switches are exactly the same, it's only the small bit of code after that differs between the two4142if Object.Quality == GOOD_QUALITY43switch Object.State44case KANABUN_FLYL45// This Kanabun is initially given always-active priority, in order for its OOB state to work properly46Object.Priority = PRIORITY_ACTIVE4748// Move left at a rate of 0.25 pixels per frame49Object.XPos -= 0x40005051Object.Timer++52if Object.Timer == 25653// Turn around5455Object.State = KANABUN_FLYR56Object.Direction = FACING_LEFT57end if58break5960case KANABUN_FLYR61// When entering this state, it is assumed that Object.Timer is already 2566263// Move right, still at a rate of 0.25 pixels per frame64Object.XPos += 0x40006566Object.Timer--67if Object.Timer == 068// Turn back around again6970Object.State = KANABUN_FLYL71Object.Direction = FACING_RIGHT72end if73break7475case KANABUN_OFFSCREEN76// Buffer state to hold the Kanabun if it went off-screen77if Object.OutOfBounds == true78Object.State = KANABUN_FLYL7980// It's safe to give it normal priority again81Object.Priority = PRIORITY_BOUNDS82end if83break8485end switch8687// Update the Kanabun's movement angle88Object.Angle += 489Object.Angle &= 5119091// And animate it, too92Object.Frame = Object.AnimationTimer93Object.Frame >>= 19495Object.AnimationTimer++96Object.AnimationTimer &= 397else98switch Object.State99case KANABUN_FLYL100// Give the Kanabun active priority so that its offscreen state will work fine when needed101//(or else the object will go offscreen and immediately pause, not returning to its original position)102Object.Priority = PRIORITY_ACTIVE103104// Go left at a rate of 0.25 pixels per frame105Object.XPos -= 0x4000106107Object.Timer++108if Object.Timer == 256109// Turn the other way110Object.State = KANABUN_FLYR111Object.Direction = FACING_LEFT112end if113break114115case KANABUN_FLYR116// Object.Timer is assumed to be 256 when going into this state117118// Go right at a rate of 0.25 pixels per frame119Object.XPos += 0x4000120121Object.Timer--122if Object.Timer == 0123// Turn the right way again124Object.State = KANABUN_FLYL125Object.Direction = FACING_RIGHT126end if127break128129case KANABUN_OFFSCREEN130// Buffer state to hold the Kanabun if it went off-screen131if Object.OutOfBounds == true132Object.State = KANABUN_FLYL133134// And give the object normal priority again, too135Object.Priority = PRIORITY_BOUNDS136end if137break138139end switch140141Object.Angle += 2142Object.Angle &= 511143144Object.Frame = Object.AnimationTimer145Object.Frame >>= 2146Object.Frame += 6147148Object.AnimationTimer++149Object.AnimationTimer &= 7150end if151152// Make the Kanabun move around, vertically153// Object.Depth is 0, 2, or 4, based on how into the background the Kanabun is154// 0 for FG, 4 for furthest in the BG155// These also correspond to Sprite Frames, with smaller sprites156157Sin(Object.YPos, Object.Angle)158if Object.Angle < 128159Object.DrawOrder = 5160161Object.Depth = 0162if Object.YPos < -384163Object.Depth = 2164end if165166if Object.YPos > 384167Object.Depth = 2168end if169else170if Object.Angle > 384171Object.DrawOrder = 5172173Object.Depth = 0174if Object.YPos < -384175Object.Depth = 2176end if177178if Object.YPos > 384179Object.Depth = 2180end if181else182Object.DrawOrder = Object.ReturnDrawOrder183184Object.Depth = 4185if Object.YPos < -384186Object.Depth = 2187end if188189if Object.YPos > 384190Object.Depth = 2191end if192end if193end if194195Object.Frame += Object.Depth196197Object.YPos <<= 13198Object.YPos += Object.StartPosY199200// See if the Kanabun should become a Flower instead201CallFunction(StageSetup_CheckGoodFuture)202203end sub204205206sub ObjectPlayerInteraction207if Object.State < KANABUN_OFFSCREEN208if Object.Depth == 0209// If in the Foreground, then act as a normal badnik210#platform: Use_Standalone211PlayerObjectCollision(C_TOUCH, -14, -14, 14, 14)212#endplatform213#platform: Use_Origins214PlayerObjectCollision(C_ENEMY, -14, -14, 14, 14)215#endplatform216if CheckResult == true217CallFunction(Player_BadnikBreak)218end if219else220// If in the BG, only interact with the player if the player is curled221// (Don't want to damage them unfairly!)222223if Player.Animation == ANI_JUMPING224#platform: Use_Standalone225PlayerObjectCollision(C_TOUCH, -14, -14, 14, 14)226#endplatform227#platform: Use_Origins228PlayerObjectCollision(C_ENEMY, -14, -14, 14, 14)229#endplatform230if CheckResult == true231CallFunction(Player_BadnikBreak)232end if233end if234end if235end if236237end sub238239240sub ObjectDraw241if Object.State < KANABUN_OFFSCREEN242DrawSpriteFX(Object.Frame, FX_FLIP, Object.XPos, Object.YPos)243end if244end sub245246247sub ObjectStartup248LoadSpriteSheet("R7/Objects.gif")249250// All these Sprite Frames are in sets of 2 for all the depth levels of the Kanabun251252// "Good" Kanabun Frames253254// Nearest to the screen255SpriteFrame(-16, -16, 32, 32, 1, 100)256SpriteFrame(-16, -16, 32, 32, 1, 133)257258// Middle depth to the screen259SpriteFrame(-12, -12, 24, 24, 34, 71)260SpriteFrame(-12, -12, 27, 27, 62, 43)261262// Furthest away from the screen263SpriteFrame(-12, -12, 24, 24, 59, 71)264SpriteFrame(-12, -12, 24, 24, 84, 71)265266// "Bad" Kanabun Frames267268// Closest to the screen269SpriteFrame(-16, -16, 32, 32, 1, 34)270SpriteFrame(-16, -16, 32, 32, 1, 67)271272// Somewhat away from the screen273SpriteFrame(-12, -12, 24, 24, 34, 18)274SpriteFrame(-12, -12, 27, 27, 34, 43)275276// Farthest away from the screen277SpriteFrame(-12, -12, 24, 24, 59, 18)278SpriteFrame(-12, -12, 24, 24, 84, 18)279280// Find all Kanabun objects in the level281ArrayPos0 = 32282while ArrayPos0 < 1056283if Object[ArrayPos0].Type == TypeName[Kanabun]284285// Make the Kanabun start halfway across its movement cycle, right in the middle286Object[ArrayPos0].Angle = 256287288// Store the Kanabun's starating position, not only for object resetting but also for Y movement calculations289Object[ArrayPos0].StartPosX = Object[ArrayPos0].XPos290Object[ArrayPos0].StartPosY = Object[ArrayPos0].YPos291292// And setup where the Kanabun's gonna fly back to, only the Good variant can go back to the higher layer293if Object[ArrayPos0].Quality == HIGH_LAYER_GOOD294Object[ArrayPos0].Quality = GOOD_QUALITY295Object[ArrayPos0].ReturnDrawOrder = 3296else297Object[ArrayPos0].ReturnDrawOrder = 2298end if299end if300301ArrayPos0++302loop303304end sub305306307// ========================308// Editor Subs309// ========================310311sub RSDKEdit312if Editor.ReturnVariable == true313switch Editor.VariableID314case EDIT_VAR_PROPVAL // Property Value315CheckResult = Object.PropertyValue316break317case 0 // Condition318CheckResult = Object.PropertyValue319break320end switch321else322switch Editor.VariableID323case EDIT_VAR_PROPVAL // Property Value324Object.PropertyValue = Editor.VariableValue325break326case 0 // Condition327Object.PropertyValue = Editor.VariableValue328break329end switch330end if331end sub332333334sub RSDKDraw335DrawSprite(Object.PropertyValue)336end sub337338339sub RSDKLoad340LoadSpriteSheet("R7/Objects.gif")341SpriteFrame(-16, -16, 32, 32, 1, 100)342SpriteFrame(-16, -16, 32, 32, 1, 34)343SpriteFrame(-16, -16, 32, 32, 1, 100)344345AddEditorVariable("Condition")346SetActiveVariable("Condition")347AddEnumVariable("Good", GOOD_QUALITY)348AddEnumVariable("Bad", BAD_QUALITY)349AddEnumVariable("Good (Return to high layer)", HIGH_LAYER_GOOD)350end sub351352353