Path: blob/master/Sonic 1/Scripts/Animals/Pocky.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Pocky 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 0x20000 : ANIMAL_XVEL25private alias -0x40000 : ANIMAL_YVEL2627// Player Aliases28private alias object.xpos : player.xpos2930// Path ID Aliases31private alias 0 : PATH_A323334// ========================35// Function Declarations36// ========================3738reserve function Pocky_DebugDraw39reserve function Pocky_DebugSpawn404142// ========================43// Function Definitions44// ========================4546private function Pocky_DebugDraw47DrawSprite(2)48end function495051private function Pocky_DebugSpawn52CreateTempObject(TypeName[Pocky], 0, object.xpos, object.ypos)5354GetBit(temp0, object.direction, 0)55if temp0 == FACING_RIGHT56object[tempObjectPos].state = ANIMAL_BOUNCING_FIXED57object[tempObjectPos].xvel = ANIMAL_XVEL58object[tempObjectPos].yvel = ANIMAL_YVEL5960Rand(checkResult, 32)61if checkResult < 1662object[tempObjectPos].direction = FACING_LEFT63FlipSign(object[tempObjectPos].xvel)64end if65else66object[tempObjectPos].state = ANIMAL_BOUNCING_FOLLOW67end if68end function697071// ========================72// Events73// ========================7475event ObjectUpdate76switch object.state77case ANIMAL_WAIT78if object.timer < object.delay79object.timer++80else81object.xvel = ANIMAL_XVEL8283if object.randomizeDir == true84object.drawOrder = 48586Rand(checkResult, 32)87if checkResult < 1688object.direction = FACING_LEFT89FlipSign(object.xvel)90end if91else92object.direction = FACING_LEFT93FlipSign(object.xvel)94end if9596object.yvel = ANIMAL_YVEL97object.state++98end if99break100101case ANIMAL_FALL102object.ypos += object.yvel103object.yvel += 0x3800104if object.yvel > 0105ObjectTileCollision(CSIDE_FLOOR, 0, 12, PATH_A)106if checkResult == true107object.yvel = ANIMAL_YVEL108object.state++109end if110end if111break112113case ANIMAL_BOUNCING_FOLLOW114if player[0].xpos < object.xpos115object.direction = FACING_LEFT116else117object.direction = FACING_RIGHT118end if119// [Fallthrough]120case ANIMAL_BOUNCING_PLACED121case ANIMAL_BOUNCING_FIXED122case ANIMAL_BOUNCING_FREE123object.xpos += object.xvel124object.ypos += object.yvel125object.yvel += 0x3800126127if object.yvel > 0128ObjectTileCollision(CSIDE_FLOOR, 0, 12, PATH_A)129if checkResult == true130if object.state == ANIMAL_BOUNCING_FIXED131if object.bounceDir == FACING_LEFT132FlipSign(object.xvel)133object.direction ^= FACING_LEFT134end if135136object.bounceDir ^= FACING_LEFT137end if138139object.yvel = ANIMAL_YVEL140end if141end if142break143144end switch145146if object.state < ANIMAL_BOUNCING_FIXED147if object.outOfBounds == true148object.type = TypeName[Blank Object]149end if150end if151end event152153154event ObjectDraw155switch object.state156case ANIMAL_WAIT157case ANIMAL_FALL158DrawSprite(2)159break160161case ANIMAL_BOUNCING_PLACED162case ANIMAL_BOUNCING_FIXED163case ANIMAL_BOUNCING_FOLLOW164case ANIMAL_BOUNCING_FREE165if object.yvel < 0166DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)167else168DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)169end if170break171172end switch173end event174175176event ObjectStartup177LoadSpriteSheet("Global/Items.gif")178SpriteFrame(-8, -12, 16, 24, 183, 26)179SpriteFrame(-8, -12, 16, 24, 183, 51)180SpriteFrame(-7, -12, 16, 24, 183, 1)181182foreach (TypeName[Pocky], arrayPos0, ALL_ENTITIES)183if object[arrayPos0].propertyValue == 1184object[arrayPos0].state = ANIMAL_BOUNCING_FIXED185object[arrayPos0].xvel = ANIMAL_XVEL186object[arrayPos0].yvel = ANIMAL_YVEL187188Rand(checkResult, 32)189if checkResult < 16190object[arrayPos0].direction = FACING_LEFT191FlipSign(object[arrayPos0].xvel)192end if193else194if object[arrayPos0].propertyValue == 2195object[arrayPos0].state = ANIMAL_BOUNCING_FOLLOW196end if197198if object[arrayPos0].propertyValue == 3199object[arrayPos0].state = ANIMAL_BOUNCING_FREE200object[arrayPos0].xvel = ANIMAL_XVEL201FlipSign(object[arrayPos0].xvel)202object[arrayPos0].direction = FACING_LEFT203end if204end if205206object[arrayPos0].propertyValue = 0207next208209SetTableValue(TypeName[Pocky], DebugMode_ObjCount, DebugMode_TypesTable)210SetTableValue(Pocky_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)211SetTableValue(Pocky_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)212DebugMode_ObjCount++213end event214215216// ========================217// Editor Events218// ========================219220event RSDKEdit221if editor.returnVariable == true222switch editor.variableID223case EDIT_VAR_PROPVAL // property value224checkResult = object.propertyValue225break226227case 0 // behaviour228checkResult = object.propertyValue229break230231end switch232else233switch editor.variableID234case EDIT_VAR_PROPVAL // property value235object.propertyValue = editor.variableValue236break237238case 0 // behaviour239object.propertyValue = editor.variableValue240break241242end switch243end if244end event245246247event RSDKDraw248DrawSprite(0)249end event250251252event RSDKLoad253LoadSpriteSheet("Global/Items.gif")254SpriteFrame(-7, -12, 16, 24, 183, 1)255256AddEditorVariable("behavior")257SetActiveVariable("behavior")258AddEnumVariable("Placed", 0)259AddEnumVariable("Fixed", 1)260AddEnumVariable("Follow", 2)261AddEnumVariable("Free", 3)262end event263264265