Path: blob/master/Sonic 2/Scripts/Mission/RotatingSpike.txt
1478 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Rotating Spike Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// This Object is used in Mission "Tails Doggy Paddle Challenge" - M046 - Mission_Zone038// It's an identical copy of MCZ's Rotating Spike object, it's even using the Sprites/MCZ/ version of the MCZ sheet instead of the Sprites/ARZ/ copy introduced in Origins910// ========================11// Aliases12// ========================1314private alias object.value0 : object.swingAngle15private alias object.value1 : object.spinSpeed16private alias object.value2 : object.length17private alias object.value3 : object.amplitude18private alias object.value4 : object.spikePos.x19private alias object.value5 : object.spikePos.y2021private alias object.value17 : debugMode.currentSelection222324// ========================25// Function Declarations26// ========================2728reserve function RotatingSpike_DebugDraw29reserve function RotatingSpike_DebugSpawn303132// ========================33// Static Values34// ========================3536private value RotatingSpike_startDebugID = 0373839// ========================40// Function Definitions41// ========================4243private function RotatingSpike_DebugDraw44temp7 = debugMode[0].currentSelection45temp7 -= RotatingSpike_startDebugID4647temp6 = object.direction48temp6 <<= 849DrawSprite(0)5051temp0 = 052temp1 = 1653while temp0 < temp754Cos(temp2, temp6)55temp2 *= temp156temp2 <<= 757temp2 += object.xpos58Sin(temp3, temp6)59temp3 *= temp160temp3 <<= 761temp3 += object.ypos62DrawSpriteXY(1, temp2, temp3)63temp0++64temp1 += 1665loop66Cos(temp2, temp6)67temp2 *= temp168temp2 <<= 769temp2 += object.xpos7071Sin(temp3, temp6)72temp3 *= temp173temp3 <<= 774temp3 += object.ypos7576DrawSpriteXY(2, temp2, temp3)77end function787980private function RotatingSpike_DebugSpawn81CreateTempObject(TypeName[Rotating Spike], 0, object.xpos, object.ypos)8283object[tempObjectPos].swingAngle = object.direction84object[tempObjectPos].swingAngle <<= 168586if object.direction == FACING_RIGHT87object[tempObjectPos].spinSpeed = -0x10088else89object[tempObjectPos].spinSpeed = -0x10090end if9192object[tempObjectPos].length = debugMode[0].currentSelection93object[tempObjectPos].length -= RotatingSpike_startDebugID94object[tempObjectPos].length++9596object[tempObjectPos].amplitude = object[tempObjectPos].length97object[tempObjectPos].amplitude <<= 498end function99100101// ========================102// Events103// ========================104105event ObjectUpdate106object.swingAngle += object.spinSpeed107object.swingAngle &= 0x1FFFF108temp0 = object.swingAngle109temp0 >>= 8110111// Calculate the spike ball's position112Cos(object.spikePos.x, temp0)113object.spikePos.x *= object.amplitude114object.spikePos.x <<= 7115object.spikePos.x += object.xpos116117Sin(object.spikePos.y, temp0)118object.spikePos.y *= object.amplitude119object.spikePos.y <<= 7120object.spikePos.y += object.ypos121122// Backup the object position and replace it with the spike ball's position for collision checks123temp0 = object.xpos124temp1 = object.ypos125object.xpos = object.spikePos.x126object.ypos = object.spikePos.y127128foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)129BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)130131if checkResult == true132CallFunction(Player_Hit)133end if134next135136// Restore that backed-up position from earlier137object.xpos = temp0138object.ypos = temp1139end event140141142event ObjectDraw143// Draw the static wood post first144DrawSprite(0)145146// Then draw the chains147temp0 = 0148temp1 = 16149temp4 = object.swingAngle150temp4 >>= 8151while temp0 < object.length152Cos(temp2, temp4)153temp2 *= temp1154temp2 <<= 7155temp2 += object.xpos156157Sin(temp3, temp4)158temp3 *= temp1159temp3 <<= 7160temp3 += object.ypos161162DrawSpriteXY(1, temp2, temp3)163164temp0++165temp1 += 16166loop167temp1 -= 8168169// And finally draw the spike ball itself170DrawSpriteXY(2, object.spikePos.x, object.spikePos.y)171end event172173174event ObjectStartup175LoadSpriteSheet("MCZ/Objects.gif")176177SpriteFrame(-8, -8, 16, 16, 135, 148) // 0 - Wood block post178SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain179SpriteFrame(-16, -16, 32, 32, 103, 0) // 2 - Spike ball180181foreach (TypeName[Rotating Spike], arrayPos0, ALL_ENTITIES)182object[arrayPos0].swingAngle = object[arrayPos0].direction183object[arrayPos0].swingAngle <<= 15 // To make it around 256 or -256184185object[arrayPos0].direction = FACING_RIGHT186187object[arrayPos0].spinSpeed = object[arrayPos0].propertyValue188object[arrayPos0].spinSpeed &= 0xF0189if object[arrayPos0].spinSpeed >= 0x80190object[arrayPos0].spinSpeed -= 0x100191end if192object[arrayPos0].spinSpeed <<= 4193194object[arrayPos0].length = object[arrayPos0].propertyValue195object[arrayPos0].length &= 0x0F196197object[arrayPos0].amplitude = object[arrayPos0].length198object[arrayPos0].amplitude <<= 4199next200201// Add the object to the debug item list a few times for different lengths202temp0 = 0203RotatingSpike_startDebugID = DebugMode_ObjCount204RotatingSpike_startDebugID--205while temp0 < 4206SetTableValue(TypeName[Rotating Spike], DebugMode_ObjCount, DebugMode_TypesTable)207SetTableValue(RotatingSpike_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)208SetTableValue(RotatingSpike_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)209DebugMode_ObjCount++210temp0++211loop212end event213214215// ========================216// Editor Events217// ========================218219event RSDKEdit220if editor.returnVariable == true221switch editor.variableID222case EDIT_VAR_PROPVAL // property value223checkResult = object.propertyValue224break225226case 0 // length227checkResult = object.propertyValue228checkResult &= 0x0F229break230231case 1 // spinSpeed232checkResult = object.propertyValue233checkResult &= 0xF0234checkResult >>= 4235break236237end switch238else239switch editor.variableID240case EDIT_VAR_PROPVAL // property value241object.propertyValue = editor.variableValue242break243244case 0 // length245object.propertyValue &= 0xF0246editor.variableValue &= 0x0F247248object.propertyValue |= editor.variableValue249break250251case 1 // spinSpeed252object.propertyValue &= 0x0F253editor.variableValue &= 0x0F254editor.variableValue <<= 4255256object.propertyValue |= editor.variableValue257break258259end switch260end if261end event262263264event RSDKDraw265object.length = object.propertyValue266object.length &= 15267object.amplitude = object.length268object.amplitude <<= 4269270object.swingAngle = object.direction271object.swingAngle <<= 15272object.swingAngle &= 0x1FFFF273temp0 = object.swingAngle274temp0 >>= 8275276Cos(object.spikePos.x, temp0)277object.spikePos.x *= object.amplitude278object.spikePos.x <<= 7279object.spikePos.x += object.xpos280281Sin(object.spikePos.y, temp0)282object.spikePos.y *= object.amplitude283object.spikePos.y <<= 7284object.spikePos.y += object.ypos285286DrawSprite(0)287288temp0 = 0289temp1 = 16290temp4 = object.swingAngle291temp4 >>= 8292while temp0 < object.length293Cos(temp2, temp4)294temp2 *= temp1295temp2 <<= 7296temp2 += object.xpos297Sin(temp3, temp4)298temp3 *= temp1299temp3 <<= 7300temp3 += object.ypos301DrawSpriteXY(1, temp2, temp3)302temp0++303temp1 += 16304loop305temp1 -= 8306307DrawSpriteXY(2, object.spikePos.x, object.spikePos.y)308end event309310311event RSDKLoad312LoadSpriteSheet("MCZ/Objects.gif")313SpriteFrame(-8, -8, 16, 16, 135, 148) // 0 - Wood block post314SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain315SpriteFrame(-16, -16, 32, 32, 103, 0) // 2 - Spike ball316317AddEditorVariable("length")318SetActiveVariable("length")319320AddEditorVariable("spinSpeed")321SetActiveVariable("spinSpeed")322end event323324325