Path: blob/master/Sonic 2/Scripts/OOZ/Elevator.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Elevator Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value1 : object.startPos.y12private alias object.value2 : object.centerPos.y13private alias object.value3 : object.bounds.y14private alias object.value4 : object.collisionOffset.y15private alias object.value5 : object.stood1617// States18private alias 0 : ELEVATOR_AWAITSTOOD19private alias 1 : ELEVATOR_MOVING20private alias 2 : ELEVATOR_IDLE2122// Player Aliases23private alias object.ypos : player.ypos2425private alias object.value17 : debugMode.currentSelection262728// ========================29// Function Declarations30// ========================3132reserve function Elevator_DebugDraw33reserve function Elevator_DebugSpawn343536// ========================37// Static Values38// ========================3940private value Elevator_startDebugID = 0414243// ========================44// Function Definitions45// ========================4647private function Elevator_DebugDraw48temp0 = debugMode[0].currentSelection49temp0 -= Elevator_startDebugID50DrawSprite(temp0)51end function525354private function Elevator_DebugSpawn55CreateTempObject(TypeName[Elevator], 0, object.xpos, object.ypos)56object[tempObjectPos].startPos.y = object.ypos57object[tempObjectPos].centerPos.y = object.ypos58object[tempObjectPos].centerPos.y -= 0x42000059object[tempObjectPos].bounds.y = object.ypos60object[tempObjectPos].bounds.y -= 0x80000061object[tempObjectPos].frame = debugMode[0].currentSelection62object[tempObjectPos].frame -= Elevator_startDebugID63end function646566// ========================67// Events68// ========================6970event ObjectUpdate71temp6 = object.ypos72switch object.state73case ELEVATOR_AWAITSTOOD74if object.stood == true75object.state = ELEVATOR_MOVING76if object.priority != PRIORITY_XBOUNDS_DESTROY77object.priority = PRIORITY_ACTIVE78end if79end if80break8182case ELEVATOR_MOVING83if object.ypos >= object.centerPos.y84object.yvel -= 0x68085else86object.yvel += 0x68087end if88object.ypos += object.yvel8990if object.propertyValue == 091if object.ypos <= object.bounds.y92object.ypos = object.bounds.y93object.yvel = 094object.state = ELEVATOR_IDLE95end if96else97if object.ypos >= object.bounds.y98object.ypos = object.bounds.y99object.yvel = 0100object.state = ELEVATOR_IDLE101end if102end if103break104105case ELEVATOR_IDLE106break107108end switch109110object.stood = false111temp0 = object.ypos112temp6 &= 0xFFFF0000113object.collisionOffset.y = object.ypos114object.collisionOffset.y &= 0xFFFF0000115object.collisionOffset.y -= temp6116object.ypos = temp6117118foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)119if object.frame == 0120BoxCollisionTest(C_PLATFORM, object.entityPos, -64, -12, 64, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)121else122BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -12, 32, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)123end if124125if checkResult == true126player[currentPlayer].ypos += object.collisionOffset.y127object.stood = true128end if129next130object.ypos = temp0131132if object.outOfBounds == true133temp0 = object.ypos134object.ypos = object.startPos.y135if object.outOfBounds == true136object.state = ELEVATOR_AWAITSTOOD137if object.priority != PRIORITY_XBOUNDS_DESTROY138object.priority = PRIORITY_BOUNDS139end if140object.stood = false141object.yvel = 0142else143object.ypos = temp0144end if145end if146end event147148149event ObjectDraw150DrawSprite(object.frame)151end event152153154event ObjectStartup155LoadSpriteSheet("OOZ/Objects.gif")156SpriteFrame(-64, -12, 128, 24, 127, 1)157SpriteFrame(-32, -12, 64, 24, 141, 26)158159foreach (TypeName[Elevator], arrayPos0, ALL_ENTITIES)160object[arrayPos0].ypos += 0x40000161object[arrayPos0].startPos.y = object[arrayPos0].ypos162object[arrayPos0].centerPos.y = object[arrayPos0].ypos163object[arrayPos0].bounds.y = object[arrayPos0].ypos164165temp0 = object[arrayPos0].propertyValue166temp0 &= 0x7F167temp0 <<= 18168object[arrayPos0].propertyValue >>= 7169if object[arrayPos0].propertyValue == 1170object[arrayPos0].ypos -= temp0171object[arrayPos0].startPos.y -= temp0172object[arrayPos0].bounds.y += temp0173object[arrayPos0].centerPos.y += 0x20000174else175object[arrayPos0].ypos += temp0176object[arrayPos0].startPos.y += temp0177object[arrayPos0].bounds.y -= temp0178object[arrayPos0].centerPos.y -= 0x20000179end if180next181182temp0 = 0183Elevator_startDebugID = DebugMode_ObjCount184while temp0 < 2185SetTableValue(TypeName[Elevator], DebugMode_ObjCount, DebugMode_TypesTable)186SetTableValue(Elevator_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)187SetTableValue(Elevator_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)188DebugMode_ObjCount++189temp0++190loop191end event192193194// ========================195// Editor Events196// ========================197198event RSDKEdit199if editor.returnVariable == true200switch editor.variableID201case EDIT_VAR_PROPVAL // property value202checkResult = object.propertyValue203break204205case 0 // distance206checkResult = object.propertyValue207checkResult &= 0x7F208break209210case 1 // direction211GetBit(checkResult, object.propertyValue, 7)212break213214case 2 // size215checkResult = object.frame216break217218end switch219else220switch editor.variableID221case EDIT_VAR_PROPVAL // property value222object.propertyValue = editor.variableValue223break224225case 0 // distance226editor.variableValue &= 0x7F227object.propertyValue &= 0x80228229object.propertyValue |= editor.variableValue230break231232case 1 // direction233CheckNotEqual(editor.variableValue, false)234SetBit(object.propertyValue, 7, checkResult)235break236237case 2 // size238object.frame = editor.variableValue239break240241end switch242end if243end event244245246event RSDKDraw247DrawSprite(object.frame)248249if editor.showGizmos == true250object.inkEffect = INK_BLEND251252temp0 = object.propertyValue253temp0 &= 0x7F254temp0 <<= 18255256// Top Preview257temp1 = object.ypos258temp1 += 0x40000259temp1 += temp0260DrawSpriteFX(object.frame, FX_INK, object.xpos, temp1)261262// Bottom Preview263temp2 = object.ypos264temp2 += 0x40000265temp2 -= temp0266DrawSpriteFX(object.frame, FX_INK, object.xpos, temp2)267268// Draw an arrow showing the direction this Elevator will go269object.inkEffect = INK_NONE270if object.propertyValue >= 0x80 // See what the top bit has271DrawArrow(object.xpos, temp2, object.xpos, temp1, 0x00, 0xFF, 0x00)272else273DrawArrow(object.xpos, temp1, object.xpos, temp2, 0x00, 0xFF, 0x00)274end if275end if276end event277278279event RSDKLoad280LoadSpriteSheet("OOZ/Objects.gif")281SpriteFrame(-64, -12, 128, 24, 127, 1)282SpriteFrame(-32, -12, 64, 24, 141, 26)283284AddEditorVariable("distance")285SetActiveVariable("distance")286287AddEditorVariable("direction")288SetActiveVariable("direction")289AddEnumVariable("Up", 0)290AddEnumVariable("Down", 1)291292AddEditorVariable("size")293SetActiveVariable("size")294AddEnumVariable("Large", 0)295AddEnumVariable("Small", 1)296end event297298299