Path: blob/master/Sonic 2/Scripts/HTZ/Lift.txt
1479 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Lift Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.distTimer // Movement distance, represented as a timer for how long the object should go for12private alias object.value1 : object.collisionOffset.y13private alias object.value2 : object.originPos.x14private alias object.value3 : object.originPos.y1516private alias 0 : LIFT_WAITING17private alias 1 : LIFT_MOVING18private alias 2 : LIFT_FALLING19private alias 3 : LIFT_FALLEN2021// Player Aliases22private alias object.xpos : player.xpos23private alias object.ypos : player.ypos242526// ========================27// Function Declarations28// ========================2930reserve function Lift_DebugDraw31reserve function Lift_DebugSpawn323334// ========================35// Function Definitions36// ========================3738private function Lift_DebugDraw39DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)40DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)41end function424344private function Lift_DebugSpawn45CreateTempObject(TypeName[Lift], 0, object.xpos, object.ypos)46object[tempObjectPos].drawOrder = 547object[tempObjectPos].direction = object.direction48end function495051// ========================52// Events53// ========================5455event ObjectUpdate56// Flag, for if this Lift should check for OOB after57temp7 = false5859switch object.state60case LIFT_WAITING61foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)62BoxCollisionTest(C_PLATFORM, object.entityPos, -32, 41, 32, 57, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)63if checkResult == true64object.state = LIFT_MOVING65object.priority = PRIORITY_ACTIVE66end if67next68break6970case LIFT_MOVING71foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)72BoxCollisionTest(C_PLATFORM, object.entityPos, -32, 41, 32, 57, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)73if checkResult == true74if object.direction == FLIP_X75player[currentPlayer].xpos -= 0x2000076else77player[currentPlayer].xpos += 0x2000078end if79player[currentPlayer].ypos += 0x1000080end if81next8283if object.direction == FLIP_X84object.xpos -= 0x2000085else86object.xpos += 0x2000087end if8889object.ypos += 0x1000090temp0 = oscillation91temp0 &= 1592if temp0 == 093PlaySfx(SfxName[Lift Tick], false)94end if9596object.distTimer--97if object.distTimer == 098object.collisionOffset.y = object.ypos99object.priority = PRIORITY_ACTIVE100object.state = LIFT_FALLING101end if102break103104case LIFT_FALLING105// Backup the object's ypos, since it'll need to be changed soon106temp0 = object.ypos107108// Setup object values for collision checks109object.ypos = object.collisionOffset.y110temp1 = object.collisionOffset.y111temp1 &= 0xFFFF0000112object.collisionOffset.y += object.yvel113object.yvel += 0x3800114temp2 = object.collisionOffset.y115temp2 &= 0xFFFF0000116temp2 -= temp1117foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)118BoxCollisionTest(C_PLATFORM, object.entityPos, -32, 41, 32, 57, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)119if checkResult == true120player[currentPlayer].ypos += temp2121end if122next123124if object.outOfBounds == true125object.state = LIFT_FALLEN126else127// Set this flag to exlcude this object from OOB checks128temp7 = true129end if130131// And now it's safe to restore the object's ypos132object.ypos = temp0133break134135case LIFT_FALLEN136// Interesting note - in most cases whenever an object has an empty state, there's simply no case jump destination for it137// In this case, however, it looks like something may have been here after all...138break139140end switch141142if temp7 == false // Don't do this if the lift is still moving143if object.outOfBounds == true144temp0 = object.xpos145temp1 = object.ypos146object.xpos = object.originPos.x147object.ypos = object.originPos.y148if object.outOfBounds == true149object.yvel = 0150object.distTimer = object.propertyValue151object.distTimer <<= 3152object.priority = PRIORITY_BOUNDS153object.state = LIFT_WAITING154else155object.xpos = temp0156object.ypos = temp1157end if158end if159end if160end event161162163event ObjectDraw164switch object.state165case LIFT_WAITING166case LIFT_MOVING167DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)168DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)169break170171case LIFT_FALLING172DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)173DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)174DrawSpriteFX(3, FX_FLIP, object.xpos, object.collisionOffset.y)175break176177case LIFT_FALLEN178DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)179DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)180break181182end switch183end event184185186event ObjectStartup187CheckCurrentStageFolder("Zone05")188189if checkResult == true190LoadSpriteSheet("HTZ/Objects.gif")191SpriteFrame(-28, -63, 56, 90, 102, 1) // 0 - Holding vines frame192SpriteFrame(-28, 27, 56, 13, 109, 198) // 1 - Loose Vines Frame193SpriteFrame(-32, 27, 64, 21, 109, 212) // 2 - Platform frame, attached to vines194SpriteFrame(-32, 27, 64, 21, 109, 234) // 3 - Loose Platform Frame195else196LoadSpriteSheet("MBZ/Objects.gif")197SpriteFrame(-28, -63, 56, 90, 73, 848)198SpriteFrame(-28, 27, 56, 13, 73, 939)199SpriteFrame(-32, 27, 64, 21, 1, 953)200SpriteFrame(-32, 27, 64, 21, 65, 953)201end if202203foreach (TypeName[Lift], arrayPos0, ALL_ENTITIES)204object[arrayPos0].originPos.x = object[arrayPos0].xpos205object[arrayPos0].originPos.y = object[arrayPos0].ypos206object[arrayPos0].drawOrder = 5207object[arrayPos0].distTimer = object[arrayPos0].propertyValue208object[arrayPos0].distTimer <<= 3209next210211SetTableValue(TypeName[Lift], DebugMode_ObjCount, DebugMode_TypesTable)212SetTableValue(Lift_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)213SetTableValue(Lift_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)214DebugMode_ObjCount++215end event216217218// ========================219// Editor Events220// ========================221222event RSDKDraw223DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)224DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)225226if editor.showGizmos == true227editor.drawingOverlay = true228229// Show a ghost of the lift's destination230231object.inkEffect = INK_BLEND232233temp0 = object.propertyValue234temp0 <<= 3235temp1 = object.xpos236temp2 = object.ypos237temp3 = 0x20000238239if object.direction == FLIP_X240FlipSign(temp3)241end if242243while temp0 > 0244temp1 += temp3245temp2 += 0x10000246temp0--247loop248249DrawSpriteFX(0, FX_INK, temp1, temp2)250DrawSpriteFX(1, FX_INK, temp1, temp2)251252object.inkEffect = INK_NONE253254// Here -> dest255DrawArrow(object.xpos, object.ypos, temp1, temp2, 0xFF, 0xFF, 0x00)256257editor.drawingOverlay = false258end if259end event260261262event RSDKLoad263CheckCurrentStageFolder("Zone05")264if checkResult == true265LoadSpriteSheet("HTZ/Objects.gif")266SpriteFrame(-28, -63, 56, 90, 102, 1) // Vines267SpriteFrame(-32, 27, 64, 21, 109, 212) // Platform268else269LoadSpriteSheet("MBZ/Objects.gif")270SpriteFrame(-28, -63, 56, 90, 73, 848) // Vines271SpriteFrame(-32, 27, 64, 21, 1, 953) // Platform272end if273274SetVariableAlias(ALIAS_VAR_PROPVAL, "distance")275end event276277278