Path: blob/master/Sonic 2/Scripts/Animals/Ricky.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Ricky 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 -0x38000 : ANIMAL_YVEL2627// Player Aliases28private alias object.xpos : player.xpos2930// Path ID Aliases31private alias 0 : PATH_A323334// ========================35// Function Declarations36// ========================3738reserve function Ricky_DebugDraw39reserve function Ricky_DebugSpawn404142// ========================43// Function Definitions44// ========================4546private function Ricky_DebugDraw47DrawSprite(2)48end function495051private function Ricky_DebugSpawn52CreateTempObject(TypeName[Ricky], 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_FREE168if object.yvel < 0169DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)170else171DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)172end if173break174175end switch176end event177178179event ObjectStartup180LoadSpriteSheet("Global/Items2.gif")181SpriteFrame(-12, -8, 24, 16, 223, 196)182SpriteFrame(-10, -7, 22, 15, 200, 197)183SpriteFrame(-7, -12, 15, 24, 159, 213)184185foreach (TypeName[Ricky], arrayPos0, ALL_ENTITIES)186if object[arrayPos0].propertyValue == 1187object[arrayPos0].state = ANIMAL_BOUNCING_FIXED188object[arrayPos0].xvel = ANIMAL_XVEL189object[arrayPos0].yvel = ANIMAL_YVEL190191Rand(checkResult, 32)192if checkResult < 16193object[arrayPos0].direction = FACING_LEFT194FlipSign(object[arrayPos0].xvel)195end if196else197if object[arrayPos0].propertyValue == 2198object[arrayPos0].state = ANIMAL_BOUNCING_FOLLOW199end if200201if object[arrayPos0].propertyValue == 3202object[arrayPos0].state = ANIMAL_BOUNCING_FREE203object[arrayPos0].xvel = ANIMAL_XVEL204FlipSign(object[arrayPos0].xvel)205object[arrayPos0].direction = FACING_LEFT206end if207end if208209object[arrayPos0].propertyValue = 0210next211212SetTableValue(TypeName[Ricky], DebugMode_ObjCount, DebugMode_TypesTable)213SetTableValue(Ricky_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)214SetTableValue(Ricky_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)215DebugMode_ObjCount++216end event217218219// ========================220// Editor Events221// ========================222223event RSDKEdit224if editor.returnVariable == true225switch editor.variableID226case EDIT_VAR_PROPVAL // property value227checkResult = object.propertyValue228break229230case 0 // behavior231checkResult = object.propertyValue232break233234end switch235else236switch editor.variableID237case EDIT_VAR_PROPVAL // property value238object.propertyValue = editor.variableValue239break240241case 0 // behavior242object.propertyValue = editor.variableValue243break244245end switch246end if247end event248249250event RSDKDraw251DrawSprite(0)252end event253254255event RSDKLoad256LoadSpriteSheet("Global/Items2.gif")257SpriteFrame(-7, -12, 15, 24, 159, 213)258259AddEditorVariable("behavior")260SetActiveVariable("behavior")261AddEnumVariable("Placed", 0)262AddEnumVariable("Fixed", 1)263AddEnumVariable("Follow", 2)264AddEnumVariable("Free", 3)265end event266267268