Path: blob/master/Sonic 1/Scripts/SBZ/Buzzsaw.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Buzzsaw Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.startPos.x12private alias object.value1 : object.startPos.y1314// Player Aliases15private alias object.xpos : player.xpos16private alias object.ypos : player.ypos1718private alias object.value17 : debugMode.currentSelection192021// ========================22// Function Declarations23// ========================2425reserve function Buzzsaw_DebugDraw26reserve function Buzzsaw_DebugSpawn27reserve function Buzzsaw_ProcessCollisions28reserve function Buzzsaw_IsOnScreen29reserve function Buzzsaw_ProcessLogic303132// ========================33// Static Values34// ========================3536private value Buzzsaw_startDebugID = 0373839// ========================40// Function Definitions41// ========================4243private function Buzzsaw_DebugDraw44temp0 = debugMode[0].currentSelection45temp0 -= Buzzsaw_startDebugID46temp0--47DrawSprite(temp0)48end function495051private function Buzzsaw_DebugSpawn52CreateTempObject(TypeName[Buzzsaw], 0, object.xpos, object.ypos)53object[tempObjectPos].startPos.x = object.xpos54object[tempObjectPos].startPos.y = object.ypos55object[tempObjectPos].inkEffect = INK_ALPHA56object[tempObjectPos].propertyValue = debugMode[0].currentSelection57object[tempObjectPos].propertyValue -= Buzzsaw_startDebugID58end function596061private function Buzzsaw_ProcessCollisions62object.animationTimer--63if object.animationTimer < 064object.animationTimer = 265object.frame ^= 166end if6768foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)69BoxCollisionTest(C_TOUCH, object.entityPos, -24, -24, 24, 24, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)70if checkResult == true71CallFunction(Player_Hit)72end if73next74end function757677private function Buzzsaw_IsOnScreen78checkResult = false79temp0 = camera[0].xpos80temp0 -= object.ixpos81temp0 -= 882Abs(temp0)83if temp0 <= screen.xcenter84temp0 = camera[0].ypos85temp0 -= object.iypos86temp0 -= 3287Abs(temp0)88if temp0 <= screen.ycenter89checkResult = true90end if91end if92end function939495private function Buzzsaw_ProcessLogic96if object.alpha < 0x10097object.alpha += 0x1098end if99100object.xpos += object.xvel101CallFunction(Buzzsaw_ProcessCollisions)102103// Out of bounds?104if object.outOfBounds == true105106// Check if at least main X is in bounds107temp0 = object.xpos108object.xpos = object.startPos.x109110// Still out of bounds?111if object.outOfBounds == true112// Reset stuff113object.xpos = object.startPos.x114object.xvel = 0115object.state = 0116object.alpha = 0117object.animationTimer = 0118object.priority = PRIORITY_BOUNDS119else120// Main X is in bounds, return to the previous X pos and stay active121object.xpos = temp0122end if123end if124end function125126127// ========================128// Events129// ========================130131event ObjectUpdate132switch object.propertyValue133case 0134// Static variant, do nothing135break136137case 1 // Horizontally moving variant138GetTableValue(temp0, 6, StageSetup_oscillationTable)139GetBit(temp1, object.direction, 0)140if temp1 == FLIP_X141FlipSign(temp0)142temp0 += 0x6000143end if144temp0 <<= 8145object.xpos = object.startPos.x146object.xpos -= temp0147CallFunction(Buzzsaw_ProcessCollisions)148149temp0 = oscillation150temp0 &= 15151if temp0 == 0152CallFunction(Buzzsaw_IsOnScreen)153if checkResult == true154PlaySfx(SfxName[Buzzsaw], false)155end if156end if157break158159case 2 // Vertically moving variant160GetTableValue(temp0, 2, StageSetup_oscillationTable)161GetBit(temp1, object.direction, 0)162if temp1 == FLIP_X163FlipSign(temp0)164temp0 += 0x8000165end if166temp0 <<= 8167object.ypos = object.startPos.y168object.ypos -= temp0169CallFunction(Buzzsaw_ProcessCollisions)170171GetTableValue(temp0, 2, StageSetup_oscillationTable)172temp0 >>= 8173if temp0 == 24174CallFunction(Buzzsaw_IsOnScreen)175if checkResult == true176PlaySfx(SfxName[Buzzsaw], false)177end if178end if179break180181case 3 // Stray (Moving Right)182if object.state == 0183foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)184if object.state == 0185temp0 = player[currentPlayer].xpos186temp0 -= 0xC00000187if temp0 >= 0188temp0 -= object.xpos189if temp0 >= 0190temp0 = player[currentPlayer].ypos191temp0 -= 0x800000192if temp0 < object.ypos193temp0 += 0x1000000194if temp0 >= object.ypos195object.state = 1196object.xvel = 0x60000197object.frame = 2198object.priority = PRIORITY_ACTIVE199PlaySfx(SfxName[Buzzsaw], false)200end if201end if202end if203end if204end if205next206else207CallFunction(Buzzsaw_ProcessLogic)208end if209break210211case 4 // Stray (Moving Left)212if object.state == 0213foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)214if object.state == 0215temp0 = player[currentPlayer].xpos216temp0 += 0xE00000217temp0 -= object.xpos218if temp0 < 0219temp0 = player[currentPlayer].ypos220temp0 -= 0x800000221if temp0 < object.ypos222temp0 += 0x1000000223if temp0 >= object.ypos224object.state = 1225object.xvel = -0x60000226object.frame = 2227object.priority = PRIORITY_ACTIVE228PlaySfx(SfxName[Buzzsaw], false)229end if230end if231end if232end if233next234else235CallFunction(Buzzsaw_ProcessLogic)236end if237break238239end switch240end event241242243event ObjectDraw244if object.propertyValue < 3245DrawSprite(object.frame)246else247if object.state != 0248DrawSpriteFX(object.frame, FX_INK, object.xpos, object.ypos)249end if250end if251end event252253254event ObjectStartup255LoadSpriteSheet("SBZ/Objects.gif")256SpriteFrame(-32, -60, 64, 92, 189, 1)257SpriteFrame(-32, -60, 64, 92, 254, 1)258SpriteFrame(-32, -32, 64, 64, 319, 50)259SpriteFrame(-32, -32, 64, 64, 384, 50)260261foreach (TypeName[Buzzsaw], arrayPos0, ALL_ENTITIES)262object[arrayPos0].startPos.x = object[arrayPos0].xpos263object[arrayPos0].startPos.y = object[arrayPos0].ypos264object[arrayPos0].inkEffect = INK_ALPHA265next266267temp0 = 0268Buzzsaw_startDebugID = DebugMode_ObjCount269Buzzsaw_startDebugID--270while temp0 < 3271SetTableValue(TypeName[Buzzsaw], DebugMode_ObjCount, DebugMode_TypesTable)272SetTableValue(Buzzsaw_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)273SetTableValue(Buzzsaw_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)274DebugMode_ObjCount++275temp0++276loop277end event278279280// ========================281// Editor Events282// ========================283284event RSDKEdit285if editor.returnVariable == true286switch editor.variableID287case EDIT_VAR_PROPVAL // property value288checkResult = object.propertyValue289break290291case 0 // type292checkResult = object.propertyValue293break294295end switch296else297switch editor.variableID298case EDIT_VAR_PROPVAL // property value299object.propertyValue = editor.variableValue300break301302case 0 // type303object.propertyValue = editor.variableValue304break305306end switch307end if308end event309310311event RSDKDraw312DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)313end event314315316event RSDKLoad317LoadSpriteSheet("SBZ/Objects.gif")318SpriteFrame(-32, -60, 64, 92, 189, 1)319SpriteFrame(-32, -60, 64, 92, 189, 1)320SpriteFrame(-32, -60, 64, 92, 189, 1)321SpriteFrame(-32, -32, 64, 64, 319, 50)322SpriteFrame(-32, -32, 64, 64, 319, 50)323324AddEditorVariable("type")325SetActiveVariable("type")326AddEnumVariable("None", 0)327AddEnumVariable("Move Horizontally", 1)328AddEnumVariable("Move Vertically", 2)329AddEnumVariable("Stray Buzzsaw (From Left)", 3)330AddEnumVariable("Stray Buzzsaw (From Right)", 4)331end event332333334