Path: blob/master/Sonic 2/Scripts/CPZ/ChemicalBall.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Chemical Ball 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.interval13private alias object.value2 : object.moveType14private alias object.value3 : object.distance15private alias object.value4 : object.acceleration16private alias object.value6 : object.newYVel17private alias object.value7 : object.startPos.x18private alias object.value8 : object.startPos.y1920// Player Aliases21private alias object.value17 : debugMode.currentSelection222324// ========================25// Function Declarations26// ========================2728reserve function ChemicalBall_HandleSetup29reserve function ChemicalBall_DebugDraw30reserve function ChemicalBall_DebugSpawn31reserve function ChemicalBall_TryPlayChemicalSfx323334// ========================35// Static Values36// ========================3738private value ChemicalBall_startDebugID = 0394041// ========================42// Function Definitions43// ========================4445private function ChemicalBall_HandleSetup46object[arrayPos0].xpos = object[arrayPos0].startPos.x47object[arrayPos0].ypos = object[arrayPos0].startPos.y48object[arrayPos0].timer = object[arrayPos0].interval4950if object[arrayPos0].direction == FLIP_NONE51object[arrayPos0].distance = 0x60000052object[arrayPos0].acceleration = 0xB0053else54object[arrayPos0].distance = -0x60000055object[arrayPos0].acceleration = -0xB0056end if5758object[arrayPos0].newYVel = -0x4800059object[arrayPos0].xvel = 060object[arrayPos0].yvel = -0x4800061object[arrayPos0].state = 06263if object[arrayPos0].priority != PRIORITY_XBOUNDS_DESTROY64object[arrayPos0].priority = PRIORITY_BOUNDS65end if66end function676869private function ChemicalBall_DebugDraw70DrawSprite(0)71end function727374private function ChemicalBall_DebugSpawn75temp0 = debugMode[0].currentSelection76temp0 -= ChemicalBall_startDebugID77CreateTempObject(TypeName[Chemical Ball], 0, object.xpos, object.ypos)7879arrayPos0 = object[tempObjectPos].entityPos80object[arrayPos0].startPos.x = object.xpos81object[arrayPos0].startPos.y = object.ypos82object[arrayPos0].moveType = temp083object[arrayPos0].moveType >>= 384object[arrayPos0].direction = object.direction85object[arrayPos0].interval = temp086object[arrayPos0].interval &= 787CallFunction(ChemicalBall_HandleSetup)88end function899091private function ChemicalBall_TryPlayChemicalSfx92temp0 = screen.xcenter93temp0 += 894temp1 = screen.ycenter95temp1 += 896CheckCameraProximity(object.ixpos, object.iypos, temp0, temp1)97if checkResult == true98PlaySfx(SfxName[Chemical Jump], false)99end if100end function101102103// ========================104// Events105// ========================106107event ObjectUpdate108object.priority = PRIORITY_ACTIVE109if object.state == 0110object.timer--111if object.timer < 0112object.state++113object.timer = 59114CallFunction(ChemicalBall_TryPlayChemicalSfx)115end if116else117object.xpos += object.xvel118object.ypos += object.yvel119object.yvel += 0x1800120121if object.moveType == 0122object.xvel += object.acceleration123if object.yvel == 0124FlipSign(object.acceleration)125end if126127if object.ypos >= object.startPos.y128object.yvel = object.newYVel129object.xvel = 0130object.state--131end if132else133if object.yvel == 0134object.xpos += object.distance135end if136137if object.yvel == 0x18000138CallFunction(ChemicalBall_TryPlayChemicalSfx)139end if140141if object.ypos == object.startPos.y142object.yvel = object.newYVel143object.xpos = object.startPos.x144FlipSign(object.acceleration)145CallFunction(ChemicalBall_TryPlayChemicalSfx)146end if147end if148end if149150temp0 = object.distance151temp0 >>= 1152temp0 += object.startPos.x153temp0 >>= 16154temp1 = screen.xcenter155temp1 += 192156CheckCameraProximity(temp0, 0, temp1, -1)157if checkResult == false158arrayPos0 = object.entityPos159CallFunction(ChemicalBall_HandleSetup)160end if161162foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)163BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)164if checkResult == true165CallFunction(Player_Hit)166end if167next168end event169170171event ObjectDraw172DrawSprite(0)173end event174175176event ObjectStartup177LoadSpriteSheet("CPZ/Objects.gif")178SpriteFrame(-8, -8, 16, 16, 207, 125)179180foreach (TypeName[Chemical Ball], arrayPos0, ALL_ENTITIES)181object[arrayPos0].startPos.x = object[arrayPos0].xpos182object[arrayPos0].startPos.y = object[arrayPos0].ypos183184GetBit(object[arrayPos0].moveType, object[arrayPos0].propertyValue, 7)185186GetBit(object[arrayPos0].direction, object[arrayPos0].propertyValue, 6)187188object[arrayPos0].interval = object[arrayPos0].propertyValue189object[arrayPos0].interval &= 0x3F190CallFunction(ChemicalBall_HandleSetup)191next192193temp0 = 0194ChemicalBall_startDebugID = DebugMode_ObjCount195while temp0 < 16196SetTableValue(TypeName[Chemical Ball], DebugMode_ObjCount, DebugMode_TypesTable)197SetTableValue(ChemicalBall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)198SetTableValue(ChemicalBall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)199DebugMode_ObjCount++200temp0++201loop202end event203204205// ========================206// Editor Events207// ========================208209event RSDKEdit210if editor.returnVariable == true211switch editor.variableID212case EDIT_VAR_PROPVAL // property value213checkResult = object.propertyValue214break215216case 0 // interval217checkResult = object.propertyValue218checkResult &= 0x3F219break220221case 1 // direction222GetBit(checkResult, object.propertyValue, 6)223break224225case 2 // type226GetBit(checkResult, object.propertyValue, 7)227break228229end switch230else231switch editor.variableID232case EDIT_VAR_PROPVAL // property value233object.propertyValue = editor.variableValue234break235236case 0 // interval237object.propertyValue = editor.variableValue238object.propertyValue &= 0x3F239break240241case 1 // direction242CheckNotEqual(editor.variableValue, 0)243SetBit(object.propertyValue, 6, checkResult)244break245246case 2 // type247CheckNotEqual(editor.variableValue, 0)248SetBit(object.propertyValue, 7, checkResult)249break250251end switch252end if253end event254255256event RSDKDraw257DrawSprite(0)258end event259260261event RSDKLoad262LoadSpriteSheet("CPZ/Objects.gif")263SpriteFrame(-8, -8, 16, 16, 207, 125)264265AddEditorVariable("interval")266SetActiveVariable("interval")267268AddEditorVariable("direction")269SetActiveVariable("direction")270AddEnumVariable("No Flip", 0)271AddEnumVariable("Flip X", 1)272273AddEditorVariable("type")274SetActiveVariable("type")275AddEnumVariable("Arc", 0)276AddEnumVariable("Vertical", 1)277end event278279280