Path: blob/master/Sonic 1/Scripts/Enemies/Bomb.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Bomb 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.fusePos1516private alias 0 : BOMB_WALK17private alias 1 : BOMB_IDLE18private alias 2 : BOMB_EXPLODE1920private alias 0 : BOMB_ANI_WALK21private alias 1 : BOMB_ANI_IDLE22private alias 2 : BOMB_ANI_EXPLODING232425// ========================26// Function Declarations27// ========================2829reserve function Bomb_DebugDraw30reserve function Bomb_DebugSpawn313233// ========================34// Function Definitions35// ========================3637private function Bomb_DebugDraw38DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)39DrawSpriteFX(8, FX_FLIP, object.xpos, object.ypos)40end function414243private function Bomb_DebugSpawn44CreateTempObject(TypeName[Bomb], 0, object.xpos, object.ypos)45object[tempObjectPos].startPos.x = object[tempObjectPos].xpos46object[tempObjectPos].startPos.y = object[tempObjectPos].ypos47object[tempObjectPos].xvel = -0x10004849temp0 = object.direction50object[tempObjectPos].direction = temp051temp0 &= FLIP_X52if temp0 == FLIP_X53FlipSign(object[tempObjectPos].xvel)54end if5556object[tempObjectPos].timer = 0x60057object[tempObjectPos].animation = BOMB_ANI_WALK58object[tempObjectPos].frame = 059end function606162// ========================63// Events64// ========================6566event ObjectUpdate67switch object.state68case BOMB_WALK69object.priority = PRIORITY_ACTIVE70object.timer--71if object.timer == 072object.timer = 18073object.animation = BOMB_ANI_IDLE74object.animationTimer = 075object.frame = 476object.state = BOMB_IDLE77else78object.xpos += object.xvel79end if80break8182case BOMB_IDLE83object.timer--84if object.timer == 085object.timer = 0x60086object.animation = BOMB_ANI_WALK87object.animationTimer = 088object.frame = 089FlipSign(object.xvel)90object.direction ^= FLIP_X91object.state = BOMB_WALK92end if93break9495case BOMB_EXPLODE96object.fusePos += 0x100097object.timer--98if object.timer == 099ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, object.xpos, object.ypos)100CreateTempObject(TypeName[Explosion], 0, object.xpos, object.ypos)101102CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)103object[tempObjectPos].xvel = -0x20000104object[tempObjectPos].yvel = -0x30000105106CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)107object[tempObjectPos].xvel = -0x10000108object[tempObjectPos].yvel = -0x20000109110CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)111object[tempObjectPos].xvel = 0x20000112object[tempObjectPos].yvel = -0x30000113114CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)115object[tempObjectPos].xvel = 0x10000116object[tempObjectPos].yvel = -0x20000117118PlaySfx(SfxName[Explosion], false)119end if120break121122end switch123124if object.outOfBounds == true125temp0 = object.xpos126temp1 = object.ypos127object.xpos = object.startPos.x128object.ypos = object.startPos.y129if object.outOfBounds == true130object.xvel = -0x1000131temp0 = object.propertyValue132object.direction = temp0133temp0 &= FLIP_X134if temp0 == FLIP_X135FlipSign(object.xvel)136end if137object.timer = 0x600138object.animation = BOMB_ANI_WALK139object.frame = 0140object.priority = PRIORITY_BOUNDS141object.state = BOMB_WALK142else143object.xpos = temp0144object.ypos = temp1145end if146end if147148foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)149if object.state != BOMB_EXPLODE150BoxCollisionTest(C_TOUCH, object.entityPos, -96, -96, 96, 96, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)151if checkResult == true152object.animation = BOMB_ANI_EXPLODING153object.frame = 6154object.timer = 144155object.fusePos = 0156object.state = BOMB_EXPLODE157end if158end if159160BoxCollisionTest(C_TOUCH, object.entityPos, -12, -18, 12, 18, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)161if checkResult == true162CallFunction(Player_Hit)163end if164next165166switch object.animation167case BOMB_ANI_WALK168if object.animationTimer == 20169object.animationTimer = 0170object.frame++171object.frame &= 3172end if173object.animationTimer++174break175176case BOMB_ANI_IDLE177case BOMB_ANI_EXPLODING178if object.animationTimer == 20179object.animationTimer = 0180object.frame ^= 1181end if182object.animationTimer++183break184185end switch186end event187188189event ObjectDraw190if object.state == BOMB_EXPLODE191temp0 = object.timer192temp0 >>= 2193temp0 &= 1194temp0 += 8195temp1 = object.ypos196197// Get the Y-Flip bit198GetBit(temp2, object.direction, 1)199if temp2 == FLIP_NONE200// FLIP_NONE or FLIP_X (aka upright)201temp1 += object.fusePos202else203// FLIP_Y or FLIP_XY (aka on a roof)204temp1 -= object.fusePos205end if206207DrawSpriteFX(temp0, FX_FLIP, object.xpos, temp1)208end if209DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)210end event211212213event ObjectStartup214// Load sprites depending on current scene folder215216CheckCurrentStageFolder("Zone05")217if checkResult == true218LoadSpriteSheet("SLZ/Objects.gif")219SpriteFrame(-10, -21, 20, 37, 53, 131)220SpriteFrame(-10, -22, 20, 38, 28, 131)221SpriteFrame(-10, -21, 20, 37, 3, 131)222SpriteFrame(-10, -22, 20, 38, 53, 92)223SpriteFrame(-11, -21, 23, 37, 2, 92)224SpriteFrame(-11, -21, 23, 37, 27, 92)225SpriteFrame(-11, -9, 23, 25, 2, 170)226SpriteFrame(-11, -9, 23, 25, 27, 170)227SpriteFrame(-3, -23, 6, 14, 51, 170)228SpriteFrame(-4, -25, 8, 16, 58, 170)229end if230231CheckCurrentStageFolder("Zone06")232if checkResult == true233LoadSpriteSheet("SBZ/Objects.gif")234SpriteFrame(-10, -21, 20, 37, 52, 40)235SpriteFrame(-10, -22, 20, 38, 27, 40)236SpriteFrame(-10, -21, 20, 37, 2, 40)237SpriteFrame(-10, -22, 20, 38, 52, 1)238SpriteFrame(-11, -21, 23, 37, 1, 1)239SpriteFrame(-11, -21, 23, 37, 26, 1)240SpriteFrame(-11, -9, 23, 25, 1, 79)241SpriteFrame(-11, -9, 23, 25, 26, 79)242SpriteFrame(-3, -23, 6, 14, 50, 79)243SpriteFrame(-4, -25, 8, 16, 57, 79)244end if245246// Unused stuff from the "MBZ" Zone247CheckCurrentStageFolder("Zone07")248if checkResult == true249LoadSpriteSheet("MBZ/Objects.gif")250SpriteFrame(-10, -21, 20, 37, 53, 328)251SpriteFrame(-10, -22, 20, 38, 28, 328)252SpriteFrame(-10, -21, 20, 37, 3, 328)253SpriteFrame(-10, -22, 20, 38, 53, 289)254SpriteFrame(-11, -21, 23, 37, 2, 289)255SpriteFrame(-11, -21, 23, 37, 27, 289)256SpriteFrame(-11, -9, 23, 25, 2, 367)257SpriteFrame(-11, -9, 23, 25, 27, 367)258SpriteFrame(-3, -23, 6, 14, 51, 367)259SpriteFrame(-4, -25, 8, 16, 58, 367)260end if261262foreach (TypeName[Bomb], arrayPos0, ALL_ENTITIES)263object[arrayPos0].startPos.x = object[arrayPos0].xpos264object[arrayPos0].startPos.y = object[arrayPos0].ypos265object[arrayPos0].xvel = -0x1000266temp0 = object[arrayPos0].propertyValue267object[arrayPos0].direction = temp0268temp0 &= FLIP_X269if temp0 == FLIP_X270FlipSign(object[arrayPos0].xvel)271end if272object[arrayPos0].timer = 0x600273object[arrayPos0].animation = BOMB_ANI_WALK274object[arrayPos0].frame = 0275next276277// Add the object to the debug item list278SetTableValue(TypeName[Bomb], DebugMode_ObjCount, DebugMode_TypesTable)279SetTableValue(Bomb_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)280SetTableValue(Bomb_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)281DebugMode_ObjCount++282end event283284285// ========================286// Editor Events287// ========================288289event RSDKEdit290if editor.returnVariable == true291switch editor.variableID292case EDIT_VAR_PROPVAL // property value293checkResult = object.propertyValue294break295296case 0 // direction297checkResult = object.propertyValue298break299300end switch301else302switch editor.variableID303case EDIT_VAR_PROPVAL // property value304object.propertyValue = editor.variableValue305break306307case 0 // direction308object.propertyValue = editor.variableValue309break310311end switch312end if313end event314315316event RSDKDraw317object.direction = object.propertyValue318DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)319end event320321322event RSDKLoad323// Make sure we have a fall-back, in case the current folder isn't actually a valid one324temp0 = false325326CheckCurrentStageFolder("Zone06")327temp0 |= checkResult328if checkResult == true329LoadSpriteSheet("SBZ/Objects.gif")330SpriteFrame(-10, -21, 20, 37, 52, 40)331SpriteFrame(-10, -22, 20, 38, 27, 40)332SpriteFrame(-10, -21, 20, 37, 2, 40)333SpriteFrame(-10, -22, 20, 38, 52, 1)334SpriteFrame(-11, -21, 23, 37, 1, 1)335SpriteFrame(-11, -21, 23, 37, 26, 1)336SpriteFrame(-11, -9, 23, 25, 1, 79)337SpriteFrame(-11, -9, 23, 25, 26, 79)338SpriteFrame(-3, -23, 6, 14, 50, 79)339SpriteFrame(-4, -25, 8, 16, 57, 79)340end if341342CheckCurrentStageFolder("Zone07")343temp0 |= checkResult344if checkResult == true345LoadSpriteSheet("MBZ/Objects.gif")346SpriteFrame(-10, -21, 20, 37, 53, 328)347SpriteFrame(-10, -22, 20, 38, 28, 328)348SpriteFrame(-10, -21, 20, 37, 3, 328)349SpriteFrame(-10, -22, 20, 38, 53, 289)350SpriteFrame(-11, -21, 23, 37, 2, 289)351SpriteFrame(-11, -21, 23, 37, 27, 289)352SpriteFrame(-11, -9, 23, 25, 2, 367)353SpriteFrame(-11, -9, 23, 25, 27, 367)354SpriteFrame(-3, -23, 6, 14, 51, 367)355SpriteFrame(-4, -25, 8, 16, 58, 367)356end if357358if temp0 == false359// We use SLZ's sprites as the fallback, "Zone05" (SLZ's folder) will come here too360LoadSpriteSheet("SLZ/Objects.gif")361SpriteFrame(-10, -21, 20, 37, 53, 131)362SpriteFrame(-10, -22, 20, 38, 28, 131)363SpriteFrame(-10, -21, 20, 37, 3, 131)364SpriteFrame(-10, -22, 20, 38, 53, 92)365SpriteFrame(-11, -21, 23, 37, 2, 92)366SpriteFrame(-11, -21, 23, 37, 27, 92)367SpriteFrame(-11, -9, 23, 25, 2, 170)368SpriteFrame(-11, -9, 23, 25, 27, 170)369SpriteFrame(-3, -23, 6, 14, 51, 170)370SpriteFrame(-4, -25, 8, 16, 58, 170)371end if372373AddEditorVariable("direction")374SetActiveVariable("direction")375AddEnumVariable("Left", 0)376AddEnumVariable("Right", 1)377AddEnumVariable("Left (Flip Y)", 2)378AddEnumVariable("Right (Flip Y)", 3)379end event380381382