Path: blob/master/Sonic 1/Scripts/Enemies/Crabmeat.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Crabmeat Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.startPos.x13private alias object.value2 : object.startPos.y14private alias object.value3 : object.canShoot1516private alias 0 : CRABMEAT_MOVING17private alias 1 : CRABMEAT_IDLE18private alias 2 : CRABMEAT_SHOOT19private alias 3 : CRABMEAT_SHOOTDELAY2021private alias 0 : CRABMEAT_ANI_MOVING22private alias 1 : CRABMEAT_ANI_SHOOT23private alias 2 : CRABMEAT_ANI_IDLE2425// Player Aliases26private alias object.value40 : player.hitboxLeft27private alias object.value38 : player.hitboxTop28private alias object.value41 : player.hitboxRight29private alias object.value39 : player.hitboxBottom3031// Path ID Aliases32private alias 0 : PATH_A333435// ========================36// Function Declarations37// ========================3839reserve function Crabmeat_DebugDraw40reserve function Crabmeat_DebugSpawn414243// ========================44// Function Definitions45// ========================4647private function Crabmeat_DebugDraw48DrawSprite(0)49end function505152private function Crabmeat_DebugSpawn53CreateTempObject(TypeName[Crabmeat], 0, object.xpos, object.ypos)54object[tempObjectPos].startPos.x = object.xpos55object[tempObjectPos].startPos.y = object.ypos5657GetBit(temp0, object.direction, 0)58if temp0 == FLIP_NONE59object[tempObjectPos].direction = FLIP_X60object[tempObjectPos].xvel = 0x800061else62object[tempObjectPos].direction = FLIP_X63object[tempObjectPos].xvel = -0x800064end if6566object[tempObjectPos].canShoot = false67end function686970// ========================71// Events72// ========================7374event ObjectUpdate75switch object.state76case CRABMEAT_MOVING77object.priority = PRIORITY_ACTIVE7879if object.timer < 12780object.timer++81object.xpos += object.xvel82if object.xvel > 083ObjectTileGrip(CSIDE_FLOOR, 14, 15, PATH_A)84else85ObjectTileGrip(CSIDE_FLOOR, -14, 15, PATH_A)86end if8788if checkResult == false89if object.canShoot == true90object.state = CRABMEAT_SHOOT91else92object.state = CRABMEAT_IDLE93object.canShoot = true94end if95object.timer = 096object.animation = CRABMEAT_ANI_SHOOT97end if98ObjectTileGrip(CSIDE_FLOOR, 0, 15, PATH_A)99else100if object.canShoot == true101object.state = CRABMEAT_SHOOT102else103object.state = CRABMEAT_IDLE104object.canShoot = true105end if106107object.timer = 0108object.animation = CRABMEAT_ANI_SHOOT109end if110break111112case CRABMEAT_IDLE113if object.timer < 59114object.timer++115else116object.timer = 0117object.state = CRABMEAT_MOVING118object.animation = CRABMEAT_ANI_MOVING119object.animationTimer = 0120FlipSign(object.xvel)121end if122break123124case CRABMEAT_SHOOT125if object.timer < 59126object.timer++127else128CreateTempObject(TypeName[Crabmeat Shot], 0, object.xpos, object.ypos)129object[tempObjectPos].xpos -= 0x100000130object[tempObjectPos].xvel = -0x10000131object[tempObjectPos].yvel = -0x40000132133CreateTempObject(TypeName[Crabmeat Shot], 0, object.xpos, object.ypos)134object[tempObjectPos].xpos += 0x100000135object[tempObjectPos].xvel = 0x10000136object[tempObjectPos].yvel = -0x40000137138object.timer = 0139object.state++140object.animation = CRABMEAT_ANI_IDLE141end if142break143144case CRABMEAT_SHOOTDELAY145if object.timer < 59146object.timer++147else148object.timer = 0149object.state = CRABMEAT_MOVING150object.animation = CRABMEAT_ANI_MOVING151object.animationTimer = 0152FlipSign(object.xvel)153end if154break155156end switch157158if object.outOfBounds == true159temp0 = object.xpos160temp1 = object.ypos161object.xpos = object.startPos.x162object.ypos = object.startPos.y163if object.outOfBounds == true164if object.propertyValue == 1165object.direction = FLIP_X166object.xvel = 0x8000167else168object.direction = FLIP_X169object.xvel = -0x8000170end if171172object.canShoot = false173object.state = CRABMEAT_MOVING174object.timer = 0175object.priority = PRIORITY_BOUNDS176object.animation = CRABMEAT_ANI_MOVING177object.animationTimer = 0178else179object.xpos = temp0180object.ypos = temp1181end if182end if183184foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)185BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)186if checkResult == true187CallFunction(Player_BadnikBreak)188end if189next190191switch object.animation192case CRABMEAT_ANI_MOVING193object.frame = object.animationTimer194object.frame >>= 4195object.animationTimer++196object.animationTimer %= 48197break198199case CRABMEAT_ANI_SHOOT200object.frame = 0201break202203case CRABMEAT_ANI_IDLE204object.frame = 3205break206207end switch208end event209210211event ObjectDraw212DrawSprite(object.frame)213end event214215216event ObjectStartup217CheckCurrentStageFolder("Zone01")218if checkResult == true219LoadSpriteSheet("GHZ/Objects.gif")220SpriteFrame(-21, -16, 42, 31, 138, 157)221SpriteFrame(-22, -16, 44, 31, 98, 189)222SpriteFrame(-22, -16, 44, 31, 98, 221)223SpriteFrame(-24, -15, 48, 30, 143, 189)224end if225226CheckCurrentStageFolder("Zone03")227if checkResult == true228LoadSpriteSheet("SYZ/Objects.gif")229SpriteFrame(-21, -16, 42, 31, 184, 1)230SpriteFrame(-22, -16, 44, 31, 184, 34)231SpriteFrame(-22, -16, 44, 31, 184, 66)232SpriteFrame(-24, -15, 48, 30, 184, 173)233end if234235CheckCurrentStageFolder("Zone07")236if checkResult == true237LoadSpriteSheet("MBZ/Objects.gif")238SpriteFrame(-21, -16, 42, 31, 168, 81)239SpriteFrame(-22, -16, 44, 31, 211, 81)240SpriteFrame(-22, -16, 44, 31, 211, 113)241SpriteFrame(-24, -15, 48, 30, 162, 114)242end if243244foreach (TypeName[Crabmeat], arrayPos0, ALL_ENTITIES)245object[arrayPos0].startPos.x = object[arrayPos0].xpos246object[arrayPos0].startPos.y = object[arrayPos0].ypos247if object[arrayPos0].propertyValue == 1248object[arrayPos0].direction = FLIP_X249object[arrayPos0].xvel = 0x8000250else251object[arrayPos0].direction = FLIP_X252object[arrayPos0].xvel = -0x8000253end if254255object[arrayPos0].canShoot = false256next257258SetTableValue(TypeName[Crabmeat], DebugMode_ObjCount, DebugMode_TypesTable)259SetTableValue(Crabmeat_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)260SetTableValue(Crabmeat_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)261DebugMode_ObjCount++262end event263264265// ========================266// Editor Events267// ========================268269event RSDKEdit270if editor.returnVariable == true271switch editor.variableID272case EDIT_VAR_PROPVAL // property value273checkResult = object.propertyValue274break275276case 0 // direction277checkResult = object.propertyValue278break279280end switch281else282switch editor.variableID283case EDIT_VAR_PROPVAL // property value284object.propertyValue = editor.variableValue285break286287case 0 // direction288object.propertyValue = editor.variableValue289break290291end switch292end if293end event294295296event RSDKDraw297DrawSprite(0)298end event299300301event RSDKLoad302// Make sure we have a fall-back, in case the current folder isn't actually a valid one303temp0 = false304305CheckCurrentStageFolder("Zone03")306temp0 |= checkResult307if checkResult == true308LoadSpriteSheet("SYZ/Objects.gif")309SpriteFrame(-21, -16, 42, 31, 184, 1)310end if311312CheckCurrentStageFolder("Zone07")313temp0 |= checkResult314if checkResult == true315LoadSpriteSheet("MBZ/Objects.gif")316SpriteFrame(-21, -16, 42, 31, 168, 81)317end if318319if temp0 == false320// We use GHZ's sprites as the fallback, "Zone01" (GHZ's folder) will come here too321LoadSpriteSheet("GHZ/Objects.gif")322SpriteFrame(-21, -16, 42, 31, 138, 157)323end if324325AddEditorVariable("direction")326SetActiveVariable("direction")327AddEnumVariable("Left", 0)328AddEnumVariable("Right", 1)329end event330331332