Path: blob/master/Sonic 2/Scripts/MCZ/SpikedLedge.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Spiked Ledge 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.originX13private alias object.value2 : object.collisionOffset.x1415private alias 0 : SPIKEDLEDGE_WAITING16private alias 1 : SPIKEDLEDGE_MOVING17private alias 2 : SPIKEDLEDGE_MOVED1819// Player Aliases20private alias object.xpos : player.xpos2122private alias object.value42 : player.prevGravity232425// ========================26// Function Declarations27// ========================2829reserve function SpikedLedge_DebugDraw30reserve function SpikedLedge_DebugSpawn313233// ========================34// Function Definitions35// ========================3637private function SpikedLedge_DebugDraw38DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)39end function404142private function SpikedLedge_DebugSpawn43CreateTempObject(TypeName[Spiked Ledge], 0, object.xpos, object.ypos)44object[tempObjectPos].direction = object.direction45if object.direction == FACING_RIGHT46object[tempObjectPos].xvel = -0x1000047else48object[tempObjectPos].xvel = 0x1000049end if50end function515253// ========================54// Events55// ========================5657event ObjectUpdate58switch object.state59case SPIKEDLEDGE_WAITING60foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)61if player[currentPlayer].prevGravity == 062// Check if the ledge should advance if the player is in range63if object.direction == FLIP_NONE64BoxCollisionTest(C_TOUCH, object.entityPos, -192, -16, -64, -14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)65else66BoxCollisionTest(C_TOUCH, object.entityPos, 64, -16, 192, -14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)67end if68else69checkResult = false70end if7172if checkResult == true73if object.priority != PRIORITY_XBOUNDS_DESTROY74object.priority = PRIORITY_ACTIVE75end if7677object.state = SPIKEDLEDGE_MOVING78object.collisionOffset.x = object.xvel79end if80next81break8283case SPIKEDLEDGE_MOVING84object.xpos += object.xvel85object.timer++86if object.timer == 12887object.timer = 088object.collisionOffset.x = 089object.state++90end if91break9293case SPIKEDLEDGE_MOVED94break9596end switch9798foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)99BoxCollisionTest(C_SOLID2, object.entityPos, -64, -16, 64, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)100switch checkResult101case COL_TOP102// Move the player along with the Ledge103player[currentPlayer].xpos += object.collisionOffset.x104break105106case COL_LEFT107if object.direction == FLIP_NONE108// Spikes on the left109CallFunction(Player_Hit)110end if111break112113case COL_RIGHT114if object.direction == FLIP_X115// Spikes on the right116CallFunction(Player_Hit)117end if118break119120end switch121next122123if object.outOfBounds == true124// If the object's out of bounds, then only unload it if its origin position is OOB as well125temp0 = object.xpos126object.xpos = object.originX127if object.outOfBounds == true128if object.priority != PRIORITY_XBOUNDS_DESTROY129object.priority = PRIORITY_BOUNDS130end if131132// Reset the object133object.collisionOffset.x = 0134object.state = SPIKEDLEDGE_WAITING135else136object.xpos = temp0137end if138end if139end event140141142event ObjectDraw143DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)144end event145146147event ObjectStartup148LoadSpriteSheet("MCZ/Objects.gif")149SpriteFrame(-64, -16, 128, 32, 1, 99)150151foreach (TypeName[Spiked Ledge], arrayPos0, ALL_ENTITIES)152object[arrayPos0].originX = object[arrayPos0].xpos153154object[arrayPos0].direction = object[arrayPos0].propertyValue155object[arrayPos0].direction &= FLIP_X156157if object[arrayPos0].direction == FLIP_NONE158object[arrayPos0].xvel = -0x10000159else160object[arrayPos0].xvel = 0x10000161end if162next163164SetTableValue(TypeName[Spiked Ledge], DebugMode_ObjCount, DebugMode_TypesTable)165SetTableValue(SpikedLedge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)166SetTableValue(SpikedLedge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)167DebugMode_ObjCount++168end event169170171// ========================172// Editor Events173// ========================174175event RSDKEdit176if editor.returnVariable == true177switch editor.variableID178case EDIT_VAR_PROPVAL // property value179checkResult = object.propertyValue180break181182case 0 // direction183checkResult = object.propertyValue184checkResult &= 1185break186187end switch188else189switch editor.variableID190case EDIT_VAR_PROPVAL // property value191object.propertyValue = editor.variableValue192break193194case 0 // direction195object.propertyValue = editor.variableValue196object.propertyValue &= 1197break198199end switch200end if201end event202203204event RSDKDraw205GetBit(object.direction, object.propertyValue, 0)206DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)207208if editor.showGizmos == true209if object.direction == FLIP_NONE210temp0 = -128211else212temp0 = 128213end if214temp0 += object.ixpos215216// Two alternate takes here, which one to do?217// One doesn't even play kindly with flipping...218219object.inkEffect = INK_BLEND220DrawSpriteFX(0, FX_INK, temp0, object.ypos)221222temp0 -= 64223temp1 = object.iypos; temp1 -= 16224DrawRectOutline(temp0, temp1, 128, 32, 255, 0, 0, 255)225end if226end event227228229event RSDKLoad230LoadSpriteSheet("MCZ/Objects.gif")231SpriteFrame(-64, -16, 128, 32, 1, 99)232233AddEditorVariable("direction")234SetActiveVariable("direction")235AddEnumVariable("Left", 0)236AddEnumVariable("Right", 1)237end event238239240