Path: blob/master/Sonic 2/Scripts/CNZ/HFlipper.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: H Flipper 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.heightArrayTop13private alias object.value2 : object.heightArrayBottom14private alias object.value3 : object.sensorPosM15private alias object.value4 : object.sensorPosL16private alias object.value5 : object.sensorPosR17private alias object.value6 : object.sensorHeightM18private alias object.value7 : object.sensorHeightL19private alias object.value8 : object.sensorHeightR20private alias object.value9 : object.hitboxT21private alias object.value10 : object.hitboxB2223// States24private alias 0 : HFLIPPER_IDLE25private alias 1 : HFLIPPER_ACTIVATED2627// Player Aliases28private alias object.state : player.state29private alias object.xpos : player.xpos30private alias object.ypos : player.ypos31private alias object.ixpos : player.ixpos32private alias object.iypos : player.iypos33private alias object.xvel : player.xvel34private alias object.yvel : player.yvel35private alias object.speed : player.speed36private alias object.gravity : player.gravity37private alias object.prevAnimation : player.prevAnimation38private alias object.animation : player.animation39private alias object.controlLock : player.controlLock40private alias object.scrollTracking : player.scrollTracking41private alias object.collisionLeft : player.collisionLeft42private alias object.collisionRight : player.collisionRight43private alias object.collisionBottom : player.collisionBottom44private alias object.jumpPress : player.jumpPress4546private alias object.value1 : player.timer47private alias object.value30 : player.jumpOffset484950// ========================51// Function Declarations52// ========================5354reserve function HFlipper_DebugDraw55reserve function HFlipper_DebugSpawn56reserve function HFlipper_LaunchPlayer575859// ========================60// Tables61// ========================6263private table HFlipper_heightArrayT_Right64-8, -8, -8, -8, -9, -9, -9, -9, -9, -9, -9, -8, -8, -7, -7, -6, -6, -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 1165end table6667private table HFlipper_heightArrayB_Right685, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 1869end table7071private table HFlipper_heightArrayT_Left7211, 10, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8, -9, -9, -9, -9, -9, -9, -9, -8, -8, -8, -873end table7475private table HFlipper_heightArrayB_Left7618, 18, 18, 18, 18, 18, 18, 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 577end table787980// ========================81// Function Definitions82// ========================8384private function HFlipper_DebugDraw85DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)86end function878889private function HFlipper_DebugSpawn90CreateTempObject(TypeName[H Flipper], 0, object.xpos, object.ypos)91object[tempObjectPos].direction = object.direction92if object[tempObjectPos].direction == FACING_RIGHT93object[tempObjectPos].heightArrayTop = HFlipper_heightArrayT_Right94object[tempObjectPos].heightArrayBottom = HFlipper_heightArrayB_Right95else96object[tempObjectPos].heightArrayTop = HFlipper_heightArrayT_Left97object[tempObjectPos].heightArrayBottom = HFlipper_heightArrayB_Left98end if99end function100101102private function HFlipper_LaunchPlayer103temp0 = player[currentPlayer].ixpos104temp0 -= object.ixpos105if object.direction == FLIP_X106FlipSign(temp0)107end if108temp0 += 35109110temp2 = temp0111if temp2 > 64112temp2 = 64113end if114temp2 <<= 5115temp2 += 0x800116FlipSign(temp2)117118temp3 = temp0119temp3 >>= 2120temp3 += 64121122Sin256(temp0, temp3)123Cos256(temp1, temp3)124temp0 *= temp2125temp1 *= temp2126127player[currentPlayer].yvel = temp0128if object.direction == FLIP_X129FlipSign(temp1)130end if131player[currentPlayer].speed = temp1132player[currentPlayer].xvel = temp1133end function134135136// ========================137// Events138// ========================139140event ObjectUpdate141switch object.state142default143case HFLIPPER_IDLE144break145146case HFLIPPER_ACTIVATED147object.frame = object.timer148object.frame >>= 2149object.frame++150if object.timer < 12151object.timer++152else153object.timer = 0154object.frame = 0155object.state = HFLIPPER_IDLE156end if157break158159end switch160161foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)162CheckEqual(player[currentPlayer].state, Player_State_Death)163temp0 = checkResult164CheckEqual(player[currentPlayer].state, Player_State_GotHit)165temp0 |= checkResult166if temp0 == false167object.sensorPosL = player[currentPlayer].xpos168object.sensorPosL -= object.xpos169object.sensorPosL >>= 16170171object.sensorPosM = object.sensorPosL172object.sensorPosM += player[currentPlayer].collisionLeft173174object.sensorPosR = object.sensorPosL175object.sensorPosR += player[currentPlayer].collisionRight176177object.sensorPosM += 24178179if object.sensorPosM < 0180object.sensorPosM = 0181end if182183if object.sensorPosM > 47184object.sensorPosM = 47185end if186187object.sensorPosL += 24188if object.sensorPosL < 0189object.sensorPosL = 0190end if191192if object.sensorPosL > 47193object.sensorPosL = 47194end if195196object.sensorPosR += 24197if object.sensorPosR < 0198object.sensorPosR = 0199end if200201if object.sensorPosR > 47202object.sensorPosR = 47203end if204205GetTableValue(object.sensorHeightM, object.sensorPosM, object.heightArrayTop)206GetTableValue(object.sensorHeightL, object.sensorPosL, object.heightArrayTop)207GetTableValue(object.sensorHeightR, object.sensorPosR, object.heightArrayTop)208209object.hitboxT = object.sensorHeightM210if object.sensorHeightL < object.hitboxT211object.hitboxT = object.sensorHeightL212end if213214if object.sensorHeightR < object.hitboxT215object.hitboxT = object.sensorHeightR216end if217218GetTableValue(object.sensorHeightM, object.sensorPosM, object.heightArrayBottom)219GetTableValue(object.sensorHeightL, object.sensorPosL, object.heightArrayBottom)220GetTableValue(object.sensorHeightR, object.sensorPosR, object.heightArrayBottom)221222object.hitboxB = object.sensorHeightM223if object.sensorHeightL > object.hitboxB224object.hitboxB = object.sensorHeightL225end if226227if object.sensorHeightR > object.hitboxB228object.hitboxB = object.sensorHeightR229end if230231if player[currentPlayer].state != Player_State_Static232BoxCollisionTest(C_SOLID, object.entityPos, -24, object.hitboxT, 24, object.hitboxB, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)233if checkResult == COL_BOTTOM234CheckEqual(player[currentPlayer].state, Player_State_Climb)235temp0 = checkResult236CheckEqual(player[currentPlayer].state, Player_State_GlideLeft)237temp0 |= checkResult238CheckEqual(player[currentPlayer].state, Player_State_GlideRight)239temp0 |= checkResult240CheckEqual(player[currentPlayer].state, Player_State_Fly)241temp0 |= checkResult242CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)243temp0 |= checkResult244CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)245temp0 |= checkResult246if temp0 == false247#platform: USE_STANDALONE248player[currentPlayer].state = Player_State_Air249#endplatform250#platform: USE_ORIGINS251player[currentPlayer].state = Player_State_Air_NoDropDash252#endplatform253player[currentPlayer].gravity = GRAVITY_AIR254end if255end if256257temp0 = 4258else259temp0 = 12260end if261262object.hitboxT -= temp0263object.hitboxB = object.hitboxT264object.hitboxB += 8265BoxCollisionTest(C_TOUCH, object.entityPos, -24, object.hitboxT, 24, object.hitboxB, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)266if checkResult == true267player[currentPlayer].ypos = object.hitboxT268player[currentPlayer].ypos += temp0269player[currentPlayer].ypos -= player[currentPlayer].collisionBottom270player[currentPlayer].ypos <<= 16271player[currentPlayer].ypos += object.ypos272if object.state == HFLIPPER_IDLE273if object.direction == FLIP_X274BoxCollisionTest(C_TOUCH, object.entityPos, -26, -12, 20, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)275else276BoxCollisionTest(C_TOUCH, object.entityPos, -20, -12, 26, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)277end if278279if checkResult == true280CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)281temp0 = checkResult282CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)283temp0 |= checkResult284if temp0 == false285player[currentPlayer].state = Player_State_Roll286player[currentPlayer].animation = ANI_JUMPING287end if288289player[currentPlayer].scrollTracking = false290player[currentPlayer].gravity = GRAVITY_GROUND291player[currentPlayer].controlLock = 8292if player[currentPlayer].jumpPress == true293CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)294temp0 = checkResult295CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)296temp0 |= checkResult297if temp0 == false298#platform: USE_STANDALONE299player[currentPlayer].state = Player_State_Air300#endplatform301#platform: USE_ORIGINS302player[currentPlayer].state = Player_State_Air_NoDropDash303#endplatform304end if305306player[currentPlayer].gravity = 1307player[currentPlayer].timer = 0308player[currentPlayer].controlLock = 0309CallFunction(HFlipper_LaunchPlayer)310object.state = HFLIPPER_ACTIVATED311StopSfx(SfxName[Jump])312PlaySfx(SfxName[Flipper], false)313else314player[currentPlayer].speed = object.xvel315player[currentPlayer].xvel = object.xvel316player[currentPlayer].yvel = 0317end if318else319CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)320temp0 = checkResult321CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)322temp0 |= checkResult323if temp0 == false324#platform: USE_STANDALONE325player[currentPlayer].state = Player_State_Air326#endplatform327#platform: USE_ORIGINS328player[currentPlayer].state = Player_State_Air_NoDropDash329#endplatform330end if331332player[currentPlayer].gravity = 1333player[currentPlayer].timer = 0334end if335336player[currentPlayer].animation = ANI_JUMPING337if player[currentPlayer].prevAnimation != ANI_JUMPING338player[currentPlayer].iypos -= player[currentPlayer].jumpOffset339end if340else341CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)342temp0 = checkResult343CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)344temp0 |= checkResult345if temp0 == false346#platform: USE_STANDALONE347player[currentPlayer].state = Player_State_Air348#endplatform349#platform: USE_ORIGINS350player[currentPlayer].state = Player_State_Air_NoDropDash351#endplatform352end if353354CallFunction(HFlipper_LaunchPlayer)355player[currentPlayer].gravity = 1356player[currentPlayer].timer = 0357end if358end if359end if360next361end event362363364event ObjectDraw365DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)366end event367368369event ObjectStartup370CheckCurrentStageFolder("Zone04")371if checkResult == true372LoadSpriteSheet("CNZ/Objects.gif")373SpriteFrame(-25, -9, 47, 26, 26, 185)374SpriteFrame(-24, -8, 48, 16, 26, 212)375SpriteFrame(-25, -17, 47, 26, 26, 229)376SpriteFrame(-24, -8, 48, 16, 26, 212)377else378LoadSpriteSheet("MBZ/Objects.gif")379SpriteFrame(-25, -9, 47, 26, 189, 402)380SpriteFrame(-24, -8, 48, 16, 189, 429)381SpriteFrame(-25, -17, 47, 26, 189, 446)382SpriteFrame(-24, -8, 48, 16, 189, 429)383end if384385foreach (TypeName[H Flipper], arrayPos0, ALL_ENTITIES)386object[arrayPos0].direction = object[arrayPos0].propertyValue387if object[arrayPos0].direction == FLIP_NONE388object[arrayPos0].heightArrayTop = HFlipper_heightArrayT_Right389object[arrayPos0].heightArrayBottom = HFlipper_heightArrayB_Right390object[arrayPos0].xvel = 0x10000391else392object[arrayPos0].heightArrayTop = HFlipper_heightArrayT_Left393object[arrayPos0].heightArrayBottom = HFlipper_heightArrayB_Left394object[arrayPos0].xvel = -0x10000395end if396next397398SetTableValue(TypeName[H Flipper], DebugMode_ObjCount, DebugMode_TypesTable)399SetTableValue(HFlipper_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)400SetTableValue(HFlipper_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)401DebugMode_ObjCount++402end event403404405// ========================406// Editor Events407// ========================408409event RSDKEdit410if editor.returnVariable == true411switch editor.variableID412case EDIT_VAR_PROPVAL // property value413checkResult = object.propertyValue414break415416case 0 // direction417checkResult = object.propertyValue418break419420end switch421else422switch editor.variableID423case EDIT_VAR_PROPVAL // property value424object.propertyValue = editor.variableValue425break426427case 0 // direction428object.propertyValue = editor.variableValue429break430431end switch432end if433end event434435436event RSDKDraw437object.direction = object.propertyValue438object.direction &= 1439DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)440end event441442443event RSDKLoad444CheckCurrentStageFolder("Zone04")445if checkResult == true446LoadSpriteSheet("CNZ/Objects.gif")447SpriteFrame(-25, -9, 47, 26, 26, 185)448else449LoadSpriteSheet("MBZ/Objects.gif")450SpriteFrame(-25, -9, 47, 26, 189, 402)451end if452453// Flippers also have FLIP_X attr set too sometimes but that's unused454AddEditorVariable("direction")455SetActiveVariable("direction")456AddEnumVariable("Right", 0)457AddEnumVariable("Left", 1)458end event459460461