Path: blob/master/Sonic 2/Scripts/MCZ/RotatingSpike.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Rotating Spike Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.swingAngle12private alias object.value1 : object.spinSpeed13private alias object.value2 : object.length14private alias object.value3 : object.amplitude15private alias object.value4 : object.spikePos.x16private alias object.value5 : object.spikePos.y1718private alias object.value17 : debugMode.currentSelection192021// ========================22// Function Declarations23// ========================2425reserve function RotatingSpike_DebugDraw26reserve function RotatingSpike_DebugSpawn272829// ========================30// Static Values31// ========================3233private value RotatingSpike_startDebugID = 0343536// ========================37// Function Definitions38// ========================3940private function RotatingSpike_DebugDraw41temp7 = debugMode[0].currentSelection42temp7 -= RotatingSpike_startDebugID4344temp6 = object.direction45temp6 <<= 846DrawSprite(0)4748temp0 = 049temp1 = 1650while temp0 < temp751Cos(temp2, temp6)52temp2 *= temp153temp2 <<= 754temp2 += object.xpos55Sin(temp3, temp6)56temp3 *= temp157temp3 <<= 758temp3 += object.ypos59DrawSpriteXY(1, temp2, temp3)60temp0++61temp1 += 1662loop63Cos(temp2, temp6)64temp2 *= temp165temp2 <<= 766temp2 += object.xpos6768Sin(temp3, temp6)69temp3 *= temp170temp3 <<= 771temp3 += object.ypos7273DrawSpriteXY(2, temp2, temp3)74end function757677private function RotatingSpike_DebugSpawn78CreateTempObject(TypeName[Rotating Spike], 0, object.xpos, object.ypos)7980object[tempObjectPos].swingAngle = object.direction81object[tempObjectPos].swingAngle <<= 16 // ObjectStartup shifts it by 15...8283if object.direction == FACING_RIGHT84object[tempObjectPos].spinSpeed = 0x10085else86object[tempObjectPos].spinSpeed = -0x10087end if8889object[tempObjectPos].length = debugMode[0].currentSelection90object[tempObjectPos].length -= RotatingSpike_startDebugID91object[tempObjectPos].length++9293object[tempObjectPos].amplitude = object[tempObjectPos].length94object[tempObjectPos].amplitude <<= 495end function969798// ========================99// Events100// ========================101102event ObjectUpdate103object.swingAngle += object.spinSpeed104object.swingAngle &= 0x1FFFF105temp0 = object.swingAngle106temp0 >>= 8107108// Calculate the spike ball's position109Cos(object.spikePos.x, temp0)110object.spikePos.x *= object.amplitude111object.spikePos.x <<= 7112object.spikePos.x += object.xpos113114Sin(object.spikePos.y, temp0)115object.spikePos.y *= object.amplitude116object.spikePos.y <<= 7117object.spikePos.y += object.ypos118119// Backup the object position and replace it with the spike ball's position for collision checks120temp0 = object.xpos121temp1 = object.ypos122object.xpos = object.spikePos.x123object.ypos = object.spikePos.y124125foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)126BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)127128if checkResult == true129CallFunction(Player_Hit)130end if131next132133// Restore that backed-up position from earlier134object.xpos = temp0135object.ypos = temp1136end event137138139event ObjectDraw140// Draw the post first141DrawSprite(0)142143// Then draw the chains144temp0 = 0145temp1 = 16146temp4 = object.swingAngle147temp4 >>= 8148while temp0 < object.length149Cos(temp2, temp4)150temp2 *= temp1151temp2 <<= 7152temp2 += object.xpos153154Sin(temp3, temp4)155temp3 *= temp1156temp3 <<= 7157temp3 += object.ypos158159DrawSpriteXY(1, temp2, temp3)160161temp0++162temp1 += 16163loop164temp1 -= 8165166// And finally draw the spike ball itself167DrawSpriteXY(2, object.spikePos.x, object.spikePos.y)168end event169170171event ObjectStartup172LoadSpriteSheet("MCZ/Objects.gif")173174SpriteFrame(-8, -8, 16, 16, 135, 148) // 0 - Post (same frame as Chain)175SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain176SpriteFrame(-16, -16, 32, 32, 103, 0) // 2 - Spike ball177178foreach (TypeName[Rotating Spike], arrayPos0, ALL_ENTITIES)179object[arrayPos0].swingAngle = object[arrayPos0].direction180object[arrayPos0].swingAngle <<= 15 // To make it around 256 or -256181182object[arrayPos0].direction = FLIP_NONE183184object[arrayPos0].spinSpeed = object[arrayPos0].propertyValue185object[arrayPos0].spinSpeed &= 0xF0186if object[arrayPos0].spinSpeed >= 0x80187object[arrayPos0].spinSpeed -= 0x100188end if189object[arrayPos0].spinSpeed <<= 4190191object[arrayPos0].length = object[arrayPos0].propertyValue192object[arrayPos0].length &= 0x0F193194object[arrayPos0].amplitude = object[arrayPos0].length195object[arrayPos0].amplitude <<= 4196next197198// Add the object to the debug item list a few times for different lengths199temp0 = 0200RotatingSpike_startDebugID = DebugMode_ObjCount201RotatingSpike_startDebugID--202while temp0 < 4203SetTableValue(TypeName[Rotating Spike], DebugMode_ObjCount, DebugMode_TypesTable)204SetTableValue(RotatingSpike_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)205SetTableValue(RotatingSpike_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)206DebugMode_ObjCount++207temp0++208loop209end event210211212// ========================213// Editor Events214// ========================215216event RSDKEdit217if editor.returnVariable == true218switch editor.variableID219case EDIT_VAR_PROPVAL // property value220checkResult = object.propertyValue221break222223case 0 // length224checkResult = object.propertyValue225checkResult &= 0x0F226break227228case 1 // spinSpeed229checkResult = object.propertyValue230checkResult &= 0xF0231checkResult >>= 4232break233234case 2 // initialDir235checkResult = object.direction236break237238end switch239else240switch editor.variableID241case EDIT_VAR_PROPVAL // property value242object.propertyValue = editor.variableValue243break244245case 0 // length246object.propertyValue &= 0xF0247editor.variableValue &= 0x0F248249object.propertyValue |= editor.variableValue250break251252case 1 // spinSpeed253object.propertyValue &= 0x0F254editor.variableValue &= 0x0F255editor.variableValue <<= 4256257object.propertyValue |= editor.variableValue258break259260case 2 // initialDir261object.direction = editor.variableValue262break263264end switch265end if266end event267268269event RSDKDraw270object.length = object.propertyValue271object.length &= 15272object.amplitude = object.length273object.amplitude <<= 4274275object.swingAngle = object.direction276object.swingAngle <<= 15277object.swingAngle &= 0x1FFFF278temp4 = object.swingAngle279temp4 >>= 8280281Cos(object.spikePos.x, temp4)282object.spikePos.x *= object.amplitude283object.spikePos.x <<= 7284object.spikePos.x += object.xpos285286Sin(object.spikePos.y, temp4)287object.spikePos.y *= object.amplitude288object.spikePos.y <<= 7289object.spikePos.y += object.ypos290291DrawSprite(0)292293temp0 = 0294temp1 = 16295while temp0 < object.length296Cos(temp2, temp4)297temp2 *= temp1298temp2 <<= 7299temp2 += object.xpos300301Sin(temp3, temp4)302temp3 *= temp1303temp3 <<= 7304temp3 += object.ypos305306DrawSpriteXY(1, temp2, temp3)307temp0++308temp1 += 16309loop310temp1 -= 8311312DrawSpriteXY(2, object.spikePos.x, object.spikePos.y)313end event314315316event RSDKLoad317LoadSpriteSheet("MCZ/Objects.gif")318SpriteFrame(-8, -8, 16, 16, 135, 148) // 0 - Post (same frame as Chain)319SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain320SpriteFrame(-16, -16, 32, 32, 103, 0) // 2 - Spike ball321322AddEditorVariable("length")323SetActiveVariable("length")324325AddEditorVariable("spinSpeed")326SetActiveVariable("spinSpeed")327328AddEditorVariable("initialDir")329SetActiveVariable("initialDir")330AddEnumVariable("Right", 0)331AddEnumVariable("Down", 1)332AddEnumVariable("Left", 2)333AddEnumVariable("Up", 3)334end event335336337