Path: blob/master/Sonic 2/Scripts/MCZ/SwingSpikes.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Swing Spikes Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.propertyValue : object.length1213private alias object.value0 : object.timer14private alias object.value1 : object.drawPos.x15private alias object.value2 : object.drawPos.y16private alias object.value3 : object.collisionOffset.x17private alias object.value4 : object.collisionOffset.y18private alias object.value5 : object.moveDir19private alias object.value6 : object.swingAngle2021private alias 0 : SWINGSPIKES_AWAITPLAYER22private alias 1 : SWINGSPIKES_MOVEDELAY23private alias 2 : SWINGSPIKES_MOVING24private alias 3 : SWINGSPIKES_FINISHEDMOVE25private alias 4 : SWINGSPIKES_RETURN2627// Player Aliases28private alias object.xpos : player.xpos29private alias object.ypos : player.ypos303132// ========================33// Function Declarations34// ========================3536reserve function SwingSpikes_DebugDraw37reserve function SwingSpikes_DebugSpawn383940// ========================41// Function Definitions42// ========================4344private function SwingSpikes_DebugDraw45DrawSprite(0)46end function474849private function SwingSpikes_DebugSpawn50CreateTempObject(TypeName[Swing Spikes], 8, object.xpos, object.ypos)51object[tempObjectPos].moveDir = object.direction52if object[tempObjectPos].moveDir == FACING_RIGHT53// Rotating clockwise54object[tempObjectPos].swingAngle = 0x800055else56// Rotating counter-clockwise57object[tempObjectPos].swingAngle = 0x000058end if59end function606162// ========================63// Events64// ========================6566event ObjectUpdate67switch object.state68case SWINGSPIKES_AWAITPLAYER69foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)70BoxCollisionTest(C_TOUCH, object.entityPos, -30, 0, 30, 128, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)71if checkResult == true72object.state = SWINGSPIKES_MOVEDELAY7374if object.priority != PRIORITY_XBOUNDS_DESTROY75object.priority = PRIORITY_ACTIVE76end if77end if78next79break8081case SWINGSPIKES_MOVEDELAY82object.timer++83if object.timer == 6084object.timer = 085object.state++86end if87break8889case SWINGSPIKES_MOVING90object.speed += 891if object.moveDir == 092object.swingAngle -= object.speed9394if object.swingAngle <= 0x400095object.speed = 096object.swingAngle = 0x400097object.state++98end if99else100object.swingAngle += object.speed101102if object.swingAngle >= 0x4000103object.speed = 0104object.swingAngle = 0x4000105object.state++106end if107end if108break109110case SWINGSPIKES_FINISHEDMOVE111object.timer++112if object.timer == 60113object.timer = 0114object.state++115end if116break117118case SWINGSPIKES_RETURN119object.speed += 8120if object.moveDir == 0121object.swingAngle += object.speed122123if object.swingAngle >= 0x8000124object.speed = 0125object.swingAngle = 0x8000126object.state = SWINGSPIKES_MOVEDELAY127end if128else129object.swingAngle -= object.speed130131if object.swingAngle <= 0132object.speed = 0133object.swingAngle = 0x0000134object.state = SWINGSPIKES_MOVEDELAY135end if136end if137break138139end switch140141// Backup object position142temp2 = object.xpos143temp3 = object.ypos144145// Get the "actual" angle for the upcoming trigonometry calculations146object.angle = object.swingAngle147object.angle >>= 7148149temp1 = object.length150temp1++151temp1 <<= 4152temp1 -= 8153object.xpos = object.drawPos.x154object.ypos = object.drawPos.y155156// Calculate pplatform X Pos157Cos(object.collisionOffset.x, object.angle)158object.collisionOffset.x *= temp1159object.collisionOffset.x <<= 7160object.collisionOffset.x += temp2161object.collisionOffset.x &= 0xFFFF0000162object.drawPos.x = object.collisionOffset.x163object.collisionOffset.x -= object.xpos164165// And then calculate pplatform Y Pos166Sin(object.collisionOffset.y, object.angle)167object.collisionOffset.y *= temp1168object.collisionOffset.y <<= 7169object.collisionOffset.y += temp3170object.collisionOffset.y &= 0xFFFF0000171object.drawPos.y = object.collisionOffset.y172object.collisionOffset.y -= object.ypos173174foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)175BoxCollisionTest(C_SOLID2, object.entityPos, -30, -8, 30, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)176switch checkResult177case COL_TOP178player[currentPlayer].xpos += object.collisionOffset.x179player[currentPlayer].ypos += object.collisionOffset.y180break181182case COL_LEFT183CallFunction(Player_Hit)184break185186case COL_RIGHT187CallFunction(Player_Hit)188break189190end switch191next192193// Restore the object's position194object.xpos = temp2195object.ypos = temp3196197if object.outOfBounds == true198if object.priority != PRIORITY_XBOUNDS_DESTROY199object.priority = PRIORITY_BOUNDS200201if object.moveDir == FACING_RIGHT202object.swingAngle = 0x8000203else204object.swingAngle = 0x0000205end if206end if207end if208end event209210211event ObjectDraw212// Draw all the chains first213temp0 = 0214temp1 = 16215while temp0 < object.length216Cos(temp2, object.angle)217temp2 *= temp1218temp2 <<= 7219temp2 += object.xpos220Sin(temp3, object.angle)221temp3 *= temp1222temp3 <<= 7223temp3 += object.ypos224DrawSpriteXY(1, temp2, temp3)225temp0++226temp1 += 16227loop228temp1 -= 8229230// Calculate where to draw the platform231Cos(object.drawPos.x, object.angle)232object.drawPos.x *= temp1233object.drawPos.x <<= 7234object.drawPos.x += object.xpos235object.drawPos.x &= 0xFFFF0000236237Sin(object.drawPos.y, object.angle)238object.drawPos.y *= temp1239object.drawPos.y <<= 7240object.drawPos.y += object.ypos241object.drawPos.y &= 0xFFFF0000242243// Rock base244DrawSprite(0)245246// Platform247DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)248end event249250251event ObjectStartup252LoadSpriteSheet("MCZ/Objects.gif")253254SpriteFrame(-12, -12, 23, 33, 152, 131) // 0 - Rock frame255SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain frame256SpriteFrame(-31, -8, 62, 16, 30, 32) // 2 - Platform frame257258foreach (TypeName[Swing Spikes], arrayPos0, ALL_ENTITIES)259if object[arrayPos0].propertyValue > 0260object[arrayPos0].propertyValue--261end if262263// Spin direction is the 4th bit in the property value264// Many Swing Spikes objects in the scene have the FlipX attr too, though that isn't used in-game265object[arrayPos0].moveDir = object[arrayPos0].propertyValue266object[arrayPos0].moveDir >>= 3267object[arrayPos0].moveDir &= 1268if object[arrayPos0].moveDir == 0269object[arrayPos0].swingAngle = 0x8000270else271object[arrayPos0].swingAngle = 0x0000272end if273274// First three bits in property value are chain length275object[arrayPos0].propertyValue &= 7276object[arrayPos0].propertyValue++277next278279SetTableValue(TypeName[Swing Spikes], DebugMode_ObjCount, DebugMode_TypesTable)280SetTableValue(SwingSpikes_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)281SetTableValue(SwingSpikes_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)282DebugMode_ObjCount++283end event284285286// ========================287// Editor Events288// ========================289290event RSDKEdit291if editor.returnVariable == true292switch editor.variableID293case EDIT_VAR_PROPVAL // property value294checkResult = object.propertyValue295break296297case 0 // length298checkResult = object.propertyValue299checkResult &= 7300break301302case 1 // swingDir303GetBit(checkResult, object.propertyValue, 4)304break305306end switch307else308switch editor.variableID309case EDIT_VAR_PROPVAL // property value310object.propertyValue = editor.variableValue311break312313case 0 // length314temp0 = 7315Not(temp0)316object.propertyValue &= temp0317editor.variableValue &= 7318319object.propertyValue |= editor.variableValue320break321322case 1 // swingDir323CheckNotEqual(editor.variableValue, 0)324SetBit(object.propertyValue, 4, checkResult)325break326327end switch328end if329end event330331332event RSDKDraw333GetBit(temp0, object.propertyValue, 4)334if temp0 == 0335temp6 = 0x3e336else337temp6 = 0x00338end if339340temp7 = object.propertyValue341temp7 &= 7342343// Draw all the chains first344temp0 = 0345temp1 = 16346while temp0 < temp7347Cos(temp2, temp6)348temp2 *= temp1349temp2 <<= 7350temp2 += object.xpos351Sin(temp3, temp6)352353temp3 *= temp1354temp3 <<= 7355temp3 += object.ypos356357DrawSpriteXY(1, temp2, temp3)358359temp0++360temp1 += 16361loop362temp1 -= 8363364// Calculate where to draw the platform365Cos(temp2, temp6)366temp2 *= temp1367temp2 <<= 7368temp2 += object.xpos369temp2 &= 0xFFFF0000370371Sin(temp3, temp6)372temp3 *= temp1373temp3 <<= 7374temp3 += object.ypos375temp3 &= 0xFFFF0000376377// Rock base378DrawSprite(0)379380// Platform381DrawSpriteXY(2, temp2, temp3)382end event383384385event RSDKLoad386LoadSpriteSheet("MCZ/Objects.gif")387SpriteFrame(-12, -12, 23, 33, 152, 131)388SpriteFrame(-8, -8, 16, 16, 135, 148)389SpriteFrame(-31, -8, 62, 16, 30, 32)390391AddEditorVariable("length")392SetActiveVariable("length")393394AddEditorVariable("swingDir")395SetActiveVariable("swingDir")396AddEnumVariable("left", 0)397AddEnumVariable("right", 1)398end event399400401