Path: blob/master/Sonic 2/Scripts/Animals/Locky.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Locky Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.propertyValue : object.delay1213private alias object.value0 : object.timer // its this in ANIMAL_WAIT14private alias object.value0 : object.bounceDir // its this in every other state15private alias object.value1 : object.randomizeDir1617private alias 0 : ANIMAL_WAIT18private alias 1 : ANIMAL_FALL19private alias 2 : ANIMAL_BOUNCING_PLACED20private alias 3 : ANIMAL_BOUNCING_FIXED21private alias 4 : ANIMAL_BOUNCING_FOLLOW22private alias 5 : ANIMAL_BOUNCING_FREE2324private alias 0x28000 : ANIMAL_XVEL25private alias -0x30000 : ANIMAL_YVEL2627// Player Aliases28private alias object.xpos : player.xpos2930// Path ID Aliases31private alias 0 : PATH_A323334// ========================35// Function Declarations36// ========================3738reserve function Locky_DebugDraw39reserve function Locky_DebugSpawn404142// ========================43// Function Definitions44// ========================4546private function Locky_DebugDraw47DrawSprite(2)48end function495051private function Locky_DebugSpawn52CreateTempObject(TypeName[Locky], 0, object.xpos, object.ypos)53GetBit(temp0, object.direction, 0)54if temp0 == FACING_RIGHT55object[tempObjectPos].state = ANIMAL_BOUNCING_FIXED56object[tempObjectPos].xvel = ANIMAL_XVEL57object[tempObjectPos].yvel = ANIMAL_YVEL5859Rand(checkResult, 32)60if checkResult < 1661object[tempObjectPos].direction = FACING_LEFT62FlipSign(object[tempObjectPos].xvel)63end if64else65object[tempObjectPos].state = ANIMAL_BOUNCING_FOLLOW66end if67end function686970// ========================71// Events72// ========================7374event ObjectUpdate75switch object.state76case ANIMAL_WAIT77if object.timer < object.delay78object.timer++79else80object.xvel = ANIMAL_XVEL81if object.randomizeDir == true82object.drawOrder = 48384Rand(checkResult, 32)85if checkResult < 1686object.direction = FACING_LEFT87FlipSign(object.xvel)88end if89else90object.direction = FACING_LEFT91FlipSign(object.xvel)92end if9394object.yvel = -0x4000095object.state++96end if97break9899case ANIMAL_FALL100object.ypos += object.yvel101object.yvel += 0x3800102103if object.yvel > 0104ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)105if checkResult == true106object.yvel = ANIMAL_YVEL107object.state++108end if109end if110break111112case ANIMAL_BOUNCING_FOLLOW113if player[0].xpos < object.xpos114object.direction = FACING_LEFT115else116object.direction = FACING_RIGHT117end if118// Fall through119case ANIMAL_BOUNCING_PLACED120case ANIMAL_BOUNCING_FIXED121case ANIMAL_BOUNCING_FREE122object.xpos += object.xvel123object.ypos += object.yvel124object.yvel += 0x3800125if object.yvel > 0126ObjectTileCollision(CSIDE_FLOOR, 0, 8, PATH_A)127if checkResult == true128if object.state == ANIMAL_BOUNCING_FIXED129if object.bounceDir == FACING_LEFT130FlipSign(object.xvel)131object.direction ^= FACING_LEFT132end if133134object.bounceDir ^= FACING_LEFT135end if136137object.yvel = ANIMAL_YVEL138end if139end if140141object.frame = object.animationTimer142object.frame >>= 1143object.animationTimer++144object.animationTimer &= 3145break146147end switch148149if object.state < ANIMAL_BOUNCING_FIXED150if object.outOfBounds == true151object.type = TypeName[Blank Object]152end if153end if154end event155156157event ObjectDraw158switch object.state159case ANIMAL_WAIT160case ANIMAL_FALL161DrawSprite(2)162break163164case ANIMAL_BOUNCING_PLACED165case ANIMAL_BOUNCING_FIXED166case ANIMAL_BOUNCING_FOLLOW167case ANIMAL_BOUNCING_FREE168DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)169break170171end switch172end event173174175event ObjectStartup176LoadSpriteSheet("Global/Items2.gif")177SpriteFrame(-8, -8, 16, 15, 32, 239)178SpriteFrame(-8, -7, 16, 15, 49, 239)179SpriteFrame(-7, -12, 15, 24, 34, 213)180181foreach (TypeName[Locky], arrayPos0, ALL_ENTITIES)182if object[arrayPos0].propertyValue == 1183object[arrayPos0].state = ANIMAL_BOUNCING_FIXED184object[arrayPos0].xvel = ANIMAL_XVEL185object[arrayPos0].yvel = ANIMAL_YVEL186187Rand(checkResult, 32)188if checkResult < 16189object[arrayPos0].direction = FACING_LEFT190FlipSign(object[arrayPos0].xvel)191end if192else193if object[arrayPos0].propertyValue == 2194object[arrayPos0].state = ANIMAL_BOUNCING_FOLLOW195end if196197if object[arrayPos0].propertyValue == 3198object[arrayPos0].state = ANIMAL_BOUNCING_FREE199object[arrayPos0].xvel = ANIMAL_XVEL200FlipSign(object[arrayPos0].xvel)201object[arrayPos0].direction = FACING_LEFT202end if203end if204205object[arrayPos0].propertyValue = 0206next207208SetTableValue(TypeName[Locky], DebugMode_ObjCount, DebugMode_TypesTable)209SetTableValue(Locky_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)210SetTableValue(Locky_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)211DebugMode_ObjCount++212end event213214215// ========================216// Editor Events217// ========================218219event RSDKEdit220if editor.returnVariable == true221switch editor.variableID222case EDIT_VAR_PROPVAL // property value223checkResult = object.propertyValue224break225226case 0 // behavior227checkResult = object.propertyValue228break229230end switch231else232switch editor.variableID233case EDIT_VAR_PROPVAL // property value234object.propertyValue = editor.variableValue235break236237case 0 // behavior238object.propertyValue = editor.variableValue239break240241end switch242end if243end event244245246event RSDKDraw247DrawSprite(0)248end event249250251event RSDKLoad252LoadSpriteSheet("Global/Items2.gif")253SpriteFrame(-7, -12, 15, 24, 34, 213)254255AddEditorVariable("behavior")256SetActiveVariable("behavior")257AddEnumVariable("Placed", 0)258AddEnumVariable("Fixed", 1)259AddEnumVariable("Follow", 2)260AddEnumVariable("Free", 3)261end event262263264