Path: blob/master/Sonic 2/Scripts/MPZ/SpearBlock.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Spear Block 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.spearPos.x13private alias object.value2 : object.spearPos.y1415// States16private alias 0 : SPEARBLOCK_SPEARSRETRACTED17private alias 1 : SPEARBLOCK_EXTENDSPEARS18private alias 2 : SPEARBLOCK_SPEARSEXTENDED19private alias 3 : SPEARBLOCK_RETRACTSPEARS2021// Player Aliases22private alias object.value17 : debugMode.currentSelection232425// ========================26// Function Declarations27// ========================2829reserve function SpearBlock_Setup30reserve function SpearBlock_DebugDraw31reserve function SpearBlock_DebugSpawn3233// ========================34// Static Values35// ========================3637private value SpearBlock_startDebugID = 0383940// ========================41// Function Definitions42// ========================4344private function SpearBlock_Setup45object[arrayPos0].spearPos.x = 046object[arrayPos0].spearPos.y = 047object[arrayPos0].timer = 048object[arrayPos0].state = 049object[arrayPos0].priority = PRIORITY_BOUNDS50end function515253private function SpearBlock_DebugDraw54DrawSprite(4)55end function565758private function SpearBlock_DebugSpawn59temp0 = debugMode[0].currentSelection60temp0 -= SpearBlock_startDebugID61CreateTempObject(TypeName[Spear Block], temp0, object.xpos, object.ypos)6263arrayPos0 = object[tempObjectPos].entityPos64CallFunction(SpearBlock_Setup)65end function666768// ========================69// Events70// ========================7172event ObjectUpdate73switch object.state74case SPEARBLOCK_SPEARSRETRACTED75temp0 = oscillation76temp0 &= 0x7F77if temp0 == 078temp0 = oscillation79temp0 >>= 780temp0 += object.propertyValue81temp0 &= 382object.frame = temp08384// Note - the `Spear` SFX doesn't exist in MBZ, so this'll error and play the Jump sound (ID 0) instead85PlaySfx(SfxName[Spear], false)8687object.priority = PRIORITY_ACTIVE88object.timer = 489object.state = SPEARBLOCK_EXTENDSPEARS90end if91break9293case SPEARBLOCK_EXTENDSPEARS94switch object.frame95case 096object.spearPos.y -= 0x8000097break9899case 1100object.spearPos.x += 0x80000101break102103case 2104object.spearPos.y += 0x80000105break106107case 3108object.spearPos.x -= 0x80000109break110111end switch112113object.timer--114if object.timer == 0115object.state = 2116end if117break118119case SPEARBLOCK_SPEARSEXTENDED120temp0 = oscillation121temp0 &= 0x3F122if temp0 == 0123// Note - the `Spear` SFX doesn't exist in MBZ's sound list, so this'll error and play the Jump sound (ID 0) instead124PlaySfx(SfxName[Spear], false)125126object.priority = PRIORITY_ACTIVE127object.timer = 4128object.state = SPEARBLOCK_RETRACTSPEARS129end if130break131132case SPEARBLOCK_RETRACTSPEARS133switch object.frame134case 0135object.spearPos.y += 0x80000136break137138case 1139object.spearPos.x -= 0x80000140break141142case 2143object.spearPos.y -= 0x80000144break145146case 3147object.spearPos.x += 0x80000148break149150end switch151152object.timer--153if object.timer == 0154object.state = SPEARBLOCK_SPEARSRETRACTED155end if156break157158end switch159160temp0 = object.xpos161temp1 = object.ypos162foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)163BoxCollisionTest(C_SOLID, object.entityPos, -16, -16, 16, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)164165object.xpos += object.spearPos.x166object.ypos += object.spearPos.y167switch object.frame168case 0169case 2170BoxCollisionTest(C_TOUCH, object.entityPos, -4, -16, 4, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)171break172173case 1174case 3175BoxCollisionTest(C_TOUCH, object.entityPos, -16, -4, 16, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)176break177178end switch179180if checkResult == true181CallFunction(Player_Hit)182end if183184object.xpos = temp0185object.ypos = temp1186next187188if object.outOfBounds == true189arrayPos0 = object.entityPos190CallFunction(SpearBlock_Setup)191end if192end event193194195event ObjectDraw196temp0 = object.xpos197temp0 += object.spearPos.x198temp1 = object.ypos199temp1 += object.spearPos.y200DrawSpriteXY(object.frame, temp0, temp1)201202DrawSprite(4)203end event204205206event ObjectStartup207CheckCurrentStageFolder("Zone09")208if checkResult == true209LoadSpriteSheet("MPZ/Objects.gif")210SpriteFrame(-4, -16, 8, 32, 34, 102)211SpriteFrame(-16, -4, 32, 8, 34, 84)212SpriteFrame(-4, -16, 8, 32, 43, 102)213SpriteFrame(-16, -4, 32, 8, 34, 93)214SpriteFrame(-16, -16, 32, 32, 52, 102)215else216LoadSpriteSheet("MBZ/Objects.gif")217SpriteFrame(-4, -16, 8, 32, 859, 615)218SpriteFrame(-16, -4, 32, 8, 893, 648)219SpriteFrame(-4, -16, 8, 32, 868, 615)220SpriteFrame(-16, -4, 32, 8, 893, 657)221SpriteFrame(-16, -16, 32, 32, 926, 541)222end if223224foreach (TypeName[Spear Block], arrayPos0, ALL_ENTITIES)225CallFunction(SpearBlock_Setup)226next227228temp0 = 0229SpearBlock_startDebugID = DebugMode_ObjCount230while temp0 < 4231SetTableValue(TypeName[Spear Block], DebugMode_ObjCount, DebugMode_TypesTable)232SetTableValue(SpearBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)233SetTableValue(SpearBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)234DebugMode_ObjCount++235temp0++236loop237end event238239240// ========================241// Editor Events242// ========================243244event RSDKEdit245if editor.returnVariable == true246switch editor.variableID247case EDIT_VAR_PROPVAL // property value248checkResult = object.propertyValue249break250251case 0 // spearDir252checkResult = object.propertyValue253break254255end switch256else257switch editor.variableID258case EDIT_VAR_PROPVAL // property value259object.propertyValue = editor.variableValue260break261262case 0 // spearDir263object.propertyValue = editor.variableValue264break265266end switch267end if268end event269270271event RSDKDraw272arrayPos0 = object.entityPos273CallFunction(SpearBlock_Setup)274275object.frame = object.propertyValue276object.frame &= 3277switch object.frame278case 0279object.spearPos.y -= 0x200000280break281282case 1283object.spearPos.x += 0x200000284break285286case 2287object.spearPos.y += 0x200000288break289290case 3291object.spearPos.x -= 0x200000292break293294end switch295296temp0 = object.xpos297temp0 += object.spearPos.x298temp1 = object.ypos299temp1 += object.spearPos.y300DrawSpriteXY(object.frame, temp0, temp1)301302DrawSprite(4)303end event304305306event RSDKLoad307CheckCurrentStageFolder("Zone09")308if checkResult == true309LoadSpriteSheet("MPZ/Objects.gif")310SpriteFrame(-4, -16, 8, 32, 34, 102)311SpriteFrame(-16, -4, 32, 8, 34, 84)312SpriteFrame(-4, -16, 8, 32, 43, 102)313SpriteFrame(-16, -4, 32, 8, 34, 93)314SpriteFrame(-16, -16, 32, 32, 52, 102)315else316LoadSpriteSheet("MBZ/Objects.gif")317SpriteFrame(-4, -16, 8, 32, 859, 615)318SpriteFrame(-16, -4, 32, 8, 893, 648)319SpriteFrame(-4, -16, 8, 32, 868, 615)320SpriteFrame(-16, -4, 32, 8, 893, 657)321SpriteFrame(-16, -16, 32, 32, 926, 541)322end if323324AddEditorVariable("spearDir")325SetActiveVariable("spearDir")326AddEnumVariable("Up", 0)327AddEnumVariable("Right", 1)328AddEnumVariable("Down", 2)329AddEnumVariable("Left", 3)330end event331332333