Path: blob/master/Sonic 2/Scripts/MPZ/SteamPiston.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Steam Piston 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.startPos.y13private alias object.value2 : object.stoodPlayers14private alias object.value31 : object.wrapOffset.y1516// States17private alias 0 : STEAMPISTON_CLOSED18private alias 1 : STEAMPISTON_OPENING19private alias 2 : STEAMPISTON_OPENED20private alias 3 : STEAMPISTON_CLOSING2122// Animations23private alias 0 : STEAMPISTON_ANI_CLOSED24private alias 1 : STEAMPISTON_ANI_ACTIVE2526// Player Aliases27private alias object.state : player.state28private alias object.ypos : player.ypos29private alias object.yvel : player.yvel30private alias object.gravity : player.gravity31private alias object.frame : player.frame32private alias object.prevAnimation : player.prevAnimation33private alias object.animationSpeed : player.animationSpeed34private alias object.animation : player.animation35private alias object.pushing : player.pushing36private alias object.collisionMode : player.collisionMode37private alias object.tileCollisions : player.tileCollisions3839private alias object.value1 : player.timer40private alias object.value25 : player.gravityStrength414243// ========================44// Function Declarations45// ========================4647reserve function SteamPiston_DebugDraw48reserve function SteamPiston_DebugSpawn495051// ========================52// Function Definitions53// ========================5455private function SteamPiston_DebugDraw56DrawSprite(8)57end function585960private function SteamPiston_DebugSpawn61CreateTempObject(TypeName[Steam Piston], object.direction, object.xpos, object.ypos) // this obj's prop val doesn't really matter62object[tempObjectPos].ypos += 0x10000063object[tempObjectPos].startPos.y = object.ypos64end function656667// ========================68// Events69// ========================7071event ObjectUpdate72temp7 = 073switch object.state74case STEAMPISTON_CLOSED75temp0 = oscillation76temp0 &= 0x7F77if temp0 == 078object.priority = PRIORITY_ACTIVE79object.timer = 280object.state = STEAMPISTON_OPENING81end if82break8384case STEAMPISTON_OPENING85object.ypos -= 0x8000086temp7 = -0x800008788object.timer--89if object.timer == 090object.state = STEAMPISTON_OPENED91object.frame = 092object.animation = STEAMPISTON_ANI_ACTIVE93end if94break9596case STEAMPISTON_OPENED97temp0 = oscillation98temp0 &= 0x3F99if temp0 == 0100object.priority = PRIORITY_ACTIVE101object.timer = 2102object.state = STEAMPISTON_CLOSING103end if104break105106case STEAMPISTON_CLOSING107object.ypos += 0x80000108temp7 = 0x80000109110object.timer--111if object.timer == 0112object.state = STEAMPISTON_CLOSED113end if114break115116end switch117118if object.animation == STEAMPISTON_ANI_ACTIVE119object.frame = object.animationTimer120object.frame >>= 3121122object.animationTimer++123if object.frame == 7124object.animationTimer = 0125object.animation = STEAMPISTON_ANI_CLOSED126end if127end if128129temp2 = 0130foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)131GetBit(temp0, object.stoodPlayers, temp2)132if temp0 == true133player[currentPlayer].ypos += temp7134end if135136SetBit(object.stoodPlayers, temp2, false)137BoxCollisionTest(C_SOLID, object.entityPos, -16, -16, 16, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)138if checkResult == COL_TOP139SetBit(object.stoodPlayers, temp2, true)140if object.state == STEAMPISTON_OPENING141#platform: USE_STANDALONE142// Technically not a bug, but this value is a bit bigger compared to the Genesis version,143// causing issues like a piston in Act 3 launching you straight into a group of spikes144player[currentPlayer].yvel = -0xA0000145#endplatform146#platform: USE_ORIGINS147// Origins Plus fixed the above issue148player[currentPlayer].yvel = -0x9B000149#endplatform150151player[currentPlayer].yvel -= player[currentPlayer].gravityStrength152#platform: USE_STANDALONE153player[currentPlayer].state = Player_State_Air154#endplatform155#platform: USE_ORIGINS156player[currentPlayer].state = Player_State_Air_NoDropDash157#endplatform158player[currentPlayer].tileCollisions = true159player[currentPlayer].gravity = 1160player[currentPlayer].timer = 0161player[currentPlayer].collisionMode = 0162player[currentPlayer].pushing = 0163player[currentPlayer].animation = ANI_TWIRL164player[currentPlayer].prevAnimation = ANI_TWIRL165player[currentPlayer].frame = 0166player[currentPlayer].animationSpeed = 40167PlaySfx(SfxName[Spring], false)168end if169else170if object.frame == 3171BoxCollisionTest(C_TOUCH, object.entityPos, -50, -4, -30, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)172if checkResult == true173CallFunction(Player_Hit)174else175BoxCollisionTest(C_TOUCH, object.entityPos, 30, -4, 50, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)176if checkResult == true177CallFunction(Player_Hit)178end if179end if180end if181end if182183temp2++184next185186if object.outOfBounds == true187object.ypos = object.startPos.y188object.ypos += object.wrapOffset.y189object.timer = 0190object.stoodPlayers = 0191object.animation = STEAMPISTON_ANI_CLOSED192object.animationTimer = 0193object.priority = PRIORITY_BOUNDS194object.state = STEAMPISTON_CLOSED195end if196end event197198199event ObjectDraw200DrawSprite(8)201202if object.animation == STEAMPISTON_ANI_ACTIVE203object.direction = FLIP_X204object.xpos -= 0x280000205DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)206207object.direction = FLIP_NONE208object.xpos += 0x500000209DrawSprite(object.frame)210211object.xpos -= 0x280000212end if213end event214215216event ObjectStartup217LoadSpriteSheet("MPZ/Objects.gif")218SpriteFrame(-24, 1, 8, 4, 102, 98)219SpriteFrame(-24, -1, 14, 8, 102, 103)220SpriteFrame(-20, -3, 15, 13, 102, 112)221SpriteFrame(-16, -4, 23, 16, 118, 92)222SpriteFrame(-8, -4, 23, 16, 119, 109)223SpriteFrame(-3, -4, 22, 14, 143, 96)224SpriteFrame(9, -2, 14, 12, 143, 111)225SpriteFrame(9, -2, 1, 1, 143, 111)226SpriteFrame(-16, -16, 32, 32, 166, 93)227228foreach (TypeName[Steam Piston], arrayPos0, ALL_ENTITIES)229object[arrayPos0].ypos += 0x100000230object[arrayPos0].startPos.y = object[arrayPos0].ypos231next232233SetTableValue(TypeName[Steam Piston], DebugMode_ObjCount, DebugMode_TypesTable)234SetTableValue(SteamPiston_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)235SetTableValue(SteamPiston_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)236DebugMode_ObjCount++237end event238239240// ========================241// Editor Events242// ========================243244event RSDKDraw245DrawSprite(8)246end event247248249event RSDKLoad250LoadSpriteSheet("MPZ/Objects.gif")251SpriteFrame(-24, 1, 8, 4, 102, 98)252SpriteFrame(-24, -1, 14, 8, 102, 103)253SpriteFrame(-20, -3, 15, 13, 102, 112)254SpriteFrame(-16, -4, 23, 16, 118, 92)255SpriteFrame(-8, -4, 23, 16, 119, 109)256SpriteFrame(-3, -4, 22, 14, 143, 96)257SpriteFrame(9, -2, 14, 12, 143, 111)258SpriteFrame(9, -2, 1, 1, 143, 111)259SpriteFrame(-16, -16, 32, 32, 166, 93)260261// Despite them all having Property Values of 1 for some reason, the value isn't actually used262// (The value *was* used in the original game, though, where it dictated the behaviour of the piston)263SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")264end event265266267