Path: blob/master/Sonic 1/Scripts/MZ/PushBlock.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Push Block 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.drawPos.x13private alias object.value2 : object.solidBoxL14private alias object.value3 : object.solidBoxR15private alias object.value4 : object.pushBoxL16private alias object.value5 : object.pushBoxR17private alias object.value6 : object.beingPushed18private alias object.value7 : object.startPos.x19private alias object.value8 : object.startPos.y20private alias object.value9 : object.pushBoundary21private alias object.value10 : object.activePlayers22private alias object.value11 : object.activePriority23private alias object.value12 : object.storedPriority2425private alias 0 : PUSHBLOCK_PUSHABLE26private alias 1 : PUSHBLOCK_MOVING27private alias 2 : PUSHBLOCK_FALLING28private alias 3 : PUSHBLOCK_INLAVA29private alias 4 : PUSHBLOCK_SINKING3031// Player Aliases32private alias object.xpos : player.xpos33private alias object.ypos : player.ypos34private alias object.ixpos : player.ixpos35private alias object.xvel : player.xvel36private alias object.speed : player.speed37private alias object.gravity : player.gravity38private alias object.pushing : player.pushing39private alias object.left : player.left40private alias object.right : player.right41private alias object.collisionRight : player.collisionRight42private alias object.collisionLeft : player.collisionLeft4344// Debug Mode Aliases45private alias object.value17 : debugMode.currentSelection4647// Chained Crusher Aliases48private alias object.value1 : chainedCrusher.crusherType49private alias object.value7 : chainedCrusher.dontPlaySfx5051private alias 0 : CHAINCRUSHER_TYPE_LARGE52private alias 1 : CHAINCRUSHER_TYPE_MED53private alias 2 : CHAINCRUSHER_TYPE_SMALL54private alias 3 : CHAINCRUSHER_TYPE_SMALL_ACTIVE5556// Tile Flag Aliases57private alias 1 : TILE_LAVA5859// Tile Info ID Aliases60private alias 8 : TILEINFO_ANGLEB6162// Path ID Aliases63private alias 0 : PATH_A646566// ========================67// Function Declarations68// ========================6970reserve function PushBlock_DebugDraw71reserve function PushBlock_DebugSpawn72reserve function PushBlock_HandlePushBounds73reserve function PushBlock_HandleObjectCollisions74reserve function PushBlock_HandleTileCollisions757677// ========================78// Static Values79// ========================8081private value PushBlock_startDebugID = 0828384// ========================85// Function Definitions86// ========================8788private function PushBlock_DebugDraw89temp0 = debugMode[0].currentSelection90temp0 -= PushBlock_startDebugID91DrawSprite(temp0)92end function939495private function PushBlock_DebugSpawn96CreateTempObject(TypeName[Push Block], 0, object.xpos, object.ypos)97object[tempObjectPos].beingPushed = false98object[tempObjectPos].frame = debugMode[0].currentSelection99object[tempObjectPos].frame -= PushBlock_startDebugID100if object[tempObjectPos].frame == 0101object[tempObjectPos].solidBoxL = -16102object[tempObjectPos].solidBoxR = 16103object[tempObjectPos].pushBoxL = -17104object[tempObjectPos].pushBoxR = 17105else106object[tempObjectPos].solidBoxL = -64107object[tempObjectPos].solidBoxR = 64108object[tempObjectPos].pushBoxL = -65109object[tempObjectPos].pushBoxR = 65110object[tempObjectPos].drawOrder = 5111end if112end function113114115private function PushBlock_HandlePushBounds116if object.floorSensorC == false117if object.floorSensorL == false118object.xvel = -0x40000119object.pushBoundary = object.xpos120object.pushBoundary &= 0xFFFF00000121object.state++122else123if object.floorSensorR == false124object.xvel = 0x40000125object.pushBoundary = object.xpos126object.pushBoundary &= 0xFFFF00000127object.pushBoundary += 0x100000128object.state++129end if130end if131end if132end function133134135private function PushBlock_HandleObjectCollisions136object.activePlayers = 0137temp2 = 0138object.xvel = 0139140foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)141CheckEqual(options.attractMode, true)142temp1 = checkResult143CheckEqual(currentPlayer, 1)144temp1 &= checkResult145146if player[currentPlayer].gravity == GRAVITY_GROUND147if player[currentPlayer].xvel < 0148BoxCollisionTest(C_TOUCH, object.entityPos, 0, -12, object.pushBoxR, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)149if checkResult == true150if player[currentPlayer].left == true151if temp1 == false152SetBit(object.activePlayers, temp2, true)153object.xvel -= 0x6000154object.beingPushed = true155end if156end if157158player[currentPlayer].xpos = player[currentPlayer].collisionRight159player[currentPlayer].xpos += object.solidBoxR160player[currentPlayer].xpos <<= 16161player[currentPlayer].xpos += object.drawPos.x162player[currentPlayer].xvel = 0163player[currentPlayer].speed = 0164player[currentPlayer].pushing = 2165end if166else167if player[currentPlayer].xvel > 0168BoxCollisionTest(C_TOUCH, object.entityPos, object.pushBoxL, -12, 0, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)169if checkResult == true170if player[currentPlayer].right == true171if temp1 == false172SetBit(object.activePlayers, temp2, true)173object.xvel += 0x6000174object.beingPushed = true175end if176end if177178player[currentPlayer].xpos = player[currentPlayer].collisionLeft179player[currentPlayer].xpos += object.solidBoxL180player[currentPlayer].xpos <<= 16181player[currentPlayer].xpos += object.drawPos.x182player[currentPlayer].xvel = 0183player[currentPlayer].speed = 0184player[currentPlayer].pushing = 2185end if186else187BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)188end if189end if190else191BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)192end if193194temp2++195next196197if object.xvel != 0198object.xpos += object.xvel199if object.xvel < 0200ObjectTileCollision(CSIDE_RWALL, object.solidBoxL, 0, PATH_A)201else202ObjectTileCollision(CSIDE_LWALL, object.solidBoxR, 0, PATH_A)203end if204CallFunction(PushBlock_HandlePushBounds)205206temp0 = oscillation207temp0 &= 31208if temp0 < 3209PlaySfx(SfxName[Push Block], false)210end if211212temp0 = object.xpos213temp0 &= 0xFFFF0000214if object.drawPos.x != temp0215// No code?216// This check statement exists in the scripts... but there's nothing that actually happens217end if218end if219220object.drawPos.x = object.xpos221object.drawPos.x &= 0xFFFF0000222temp2 = 0223foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)224GetBit(temp0, object.activePlayers, temp2)225if temp0 == true226if player[currentPlayer].xpos < object.xpos227player[currentPlayer].ixpos = player[currentPlayer].collisionRight228temp1 = object.solidBoxL229else230player[currentPlayer].ixpos = player[currentPlayer].collisionLeft231temp1 = object.solidBoxR232end if233234FlipSign(player[currentPlayer].xpos)235temp1 <<= 16236player[currentPlayer].xpos += temp1237player[currentPlayer].xpos += object.xpos238else239BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)240end if241242temp2++243next244end function245246247private function PushBlock_HandleTileCollisions248if object.beingPushed == true249if object.gravity == GRAVITY_AIR250object.yvel += 0x1800251object.ypos += object.yvel252253temp0 = object.solidBoxL254temp0 += 2255ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)256object.floorSensorL = checkResult257object.gravity = checkResult258259ObjectTileCollision(CSIDE_FLOOR, 0, 16, PATH_A)260object.floorSensorC = checkResult261object.gravity |= checkResult262263temp0 = object.solidBoxR264temp0 -= 2265ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)266object.floorSensorR = checkResult267object.gravity |= checkResult268else269object.yvel = 0270271temp0 = object.solidBoxL272temp0 += 2273ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)274object.floorSensorL = checkResult275object.gravity = checkResult276277ObjectTileGrip(CSIDE_FLOOR, 0, 16, PATH_A)278object.floorSensorC = checkResult279object.gravity |= checkResult280281temp0 = object.solidBoxR282temp0 -= 2283ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)284object.floorSensorR = checkResult285object.gravity |= checkResult286end if287object.gravity ^= GRAVITY_AIR288else289object.floorSensorL = true290object.floorSensorC = true291object.floorSensorR = true292end if293294// Bug Details: (applies to all the below cases)295// - The code after the ObjectTileCollision check affects *all* active crushers in the vicinity,296// even though it should probably only affect the crusher that the block is actually currently on297// - (This doesn't matter normally because there aren't any times in the base game where blocks and several crushers are near each other, but it's still something worth noting)298foreach (TypeName[Chained Crusher], arrayPos0, ACTIVE_ENTITIES)299switch chainedCrusher[arrayPos0].crusherType300case CHAINCRUSHER_TYPE_LARGE301BoxCollisionTest(C_PLATFORM, arrayPos0, -56, -12, 56, 12, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16)302object.beingPushed |= checkResult303ObjectTileCollision(CSIDE_ROOF, 0, -17, PATH_A)304if checkResult == true305// If the block's being squished, then let's move the crusher back down a bit306object.ypos -= 0x10000307object[arrayPos0].ypos = object.ypos308object[arrayPos0].ypos += 0x1D0000309chainedCrusher[arrayPos0].dontPlaySfx = true310end if311break312313case CHAINCRUSHER_TYPE_MED314BoxCollisionTest(C_PLATFORM, arrayPos0, -48, -12, 48, 12, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16)315object.beingPushed |= checkResult316ObjectTileCollision(CSIDE_ROOF, 0, -17, PATH_A)317if checkResult == true318// If the block's being squished, then let's move the crusher back down a bit319object.ypos -= 0x10000320object[arrayPos0].ypos = object.ypos321object[arrayPos0].ypos += 0x1D0000322chainedCrusher[arrayPos0].dontPlaySfx = true323end if324break325326case CHAINCRUSHER_TYPE_SMALL327BoxCollisionTest(C_PLATFORM, arrayPos0, -16, -12, 16, 12, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16)328object.beingPushed |= checkResult329ObjectTileCollision(CSIDE_ROOF, 0, -17, PATH_A)330if checkResult == true331// If the block's being squished, then let's move the crusher back down a bit332object.ypos -= 0x10000333object[arrayPos0].ypos = object.ypos334object[arrayPos0].ypos += 0x1D0000335chainedCrusher[arrayPos0].dontPlaySfx = true336end if337break338339// (nothing for CHAINCRUSHER_TYPE_SMALL_ACTIVE)340341end switch342next343end function344345346// ========================347// Events348// ========================349350event ObjectUpdate351temp6 = object.xpos352temp7 = object.ypos353switch object.state354case PUSHBLOCK_PUSHABLE355object.priority = object.activePriority356CallFunction(PushBlock_HandleObjectCollisions)357CallFunction(PushBlock_HandleTileCollisions)358break359360case PUSHBLOCK_MOVING361object.xpos += object.xvel362if object.xvel > 0363if object.xpos >= object.pushBoundary364object.xpos = object.pushBoundary365object.gravity = GRAVITY_AIR366object.state = PUSHBLOCK_FALLING367end if368else369if object.xpos <= object.pushBoundary370object.xpos = object.pushBoundary371object.gravity = GRAVITY_AIR372object.state = PUSHBLOCK_FALLING373end if374end if375break376377case PUSHBLOCK_FALLING378CallFunction(PushBlock_HandleTileCollisions)379if object.gravity == GRAVITY_GROUND380temp1 = object.iypos381temp1 += 12382Get16x16TileInfo(temp0, object.ixpos, temp1, TILEINFO_ANGLEB)383if temp0 == TILE_LAVA384object.state = PUSHBLOCK_INLAVA385if object.xvel > 0386object.xvel = 0x8000387else388object.xvel = -0x8000389end if390else391object.state = PUSHBLOCK_PUSHABLE392end if393end if394break395396case PUSHBLOCK_INLAVA397temp0 = object.xpos398temp0 -= object.drawPos.x399temp0 += object.xvel400temp0 &= 0xFFFF0000401if object.gravity == GRAVITY_AIR402temp1 = object.ypos403temp1 &= 0xFFFF0000404object.yvel += 0x1800405object.ypos += object.yvel406ObjectTileCollision(CSIDE_FLOOR, 0, 16, PATH_A)407if checkResult == true408object.yvel = 0409object.gravity = GRAVITY_GROUND410end if411temp2 = object.ypos412temp2 &= 0xFFFF0000413temp2 -= temp1414temp3 = object.ypos415object.ypos = temp1416else417temp2 = 0418end if419420object.xpos += object.xvel421if temp2 != 0422object.ypos = temp3423end if424425if object.xvel > 0426ObjectTileCollision(CSIDE_LWALL, 16, 12, PATH_A)427if checkResult == true428object.xvel = 0429object.timer = 0430object.state = PUSHBLOCK_SINKING431end if432else433ObjectTileCollision(CSIDE_RWALL, -16, 12, PATH_A)434if checkResult == true435object.xvel = 0436object.timer = 0437object.state = PUSHBLOCK_SINKING438end if439end if440break441442case PUSHBLOCK_SINKING443if object.timer < 320444object.timer++445temp0 = object.timer446temp0 &= 7447if temp0 == 0448object.ypos += 0x10000449end if450end if451break452453end switch454455temp0 = object.xpos456temp1 = object.ypos457temp4 = object.xpos458temp4 &= 0xFFFF0000459temp5 = object.ypos460temp5 &= 0xFFFF0000461object.xpos = temp6462object.ypos = temp7463temp6 &= 0xFFFF0000464temp7 &= 0xFFFF0000465temp4 -= temp6466temp5 -= temp7467468foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)469CheckNotEqual(player[currentPlayer].pushing, false)470temp2 = checkResult471CheckEqual(object.state, PUSHBLOCK_PUSHABLE)472temp2 &= checkResult473if temp2 == false474BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)475if checkResult == COL_TOP476player[currentPlayer].xpos += temp4477player[currentPlayer].ypos += temp5478end if479end if480next481482object.xpos = temp0483object.ypos = temp1484object.drawPos.x = object.xpos485object.drawPos.x &= 0xFFFF0000486487if object.outOfBounds == true488temp0 = object.xpos489temp1 = object.ypos490object.xpos = object.startPos.x491object.ypos = object.startPos.y492if object.outOfBounds == true493object.yvel = 0494object.beingPushed = false495object.priority = object.storedPriority496object.state = PUSHBLOCK_PUSHABLE497else498object.xpos = temp0499object.ypos = temp1500end if501end if502end event503504505event ObjectDraw506DrawSpriteXY(object.frame, object.drawPos.x, object.ypos)507end event508509510event ObjectStartup511LoadSpriteSheet("MZ/Objects.gif")512SpriteFrame(-16, -16, 32, 32, 159, 322)513SpriteFrame(-64, -16, 128, 32, 159, 322)514515foreach (TypeName[Push Block], arrayPos0, ALL_ENTITIES)516object[arrayPos0].frame = object[arrayPos0].propertyValue517object[arrayPos0].frame &= 1518if object[arrayPos0].frame == 0519object[arrayPos0].activePriority = PRIORITY_ACTIVE_SMALL520object[arrayPos0].storedPriority = PRIORITY_BOUNDS_SMALL521object[arrayPos0].priority = PRIORITY_BOUNDS_SMALL522else523object[arrayPos0].activePriority = PRIORITY_ACTIVE524object[arrayPos0].storedPriority = PRIORITY_BOUNDS525object[arrayPos0].priority = PRIORITY_BOUNDS526end if527528object[arrayPos0].startPos.x = object[arrayPos0].xpos529object[arrayPos0].startPos.y = object[arrayPos0].ypos530object[arrayPos0].beingPushed = false531532if object[arrayPos0].frame == 0533object[arrayPos0].solidBoxL = -16534object[arrayPos0].solidBoxR = 16535object[arrayPos0].pushBoxL = -17536object[arrayPos0].pushBoxR = 17537else538object[arrayPos0].solidBoxL = -64539object[arrayPos0].solidBoxR = 64540object[arrayPos0].pushBoxL = -65541object[arrayPos0].pushBoxR = 65542object[arrayPos0].drawOrder = 5543end if544next545546temp0 = 0547PushBlock_startDebugID = DebugMode_ObjCount548while temp0 < 2549SetTableValue(TypeName[Push Block], DebugMode_ObjCount, DebugMode_TypesTable)550SetTableValue(PushBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)551SetTableValue(PushBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)552DebugMode_ObjCount++553temp0++554loop555end event556557558// ========================559// Editor Events560// ========================561562event RSDKEdit563if editor.returnVariable == true564switch editor.variableID565case EDIT_VAR_PROPVAL // property value566checkResult = object.propertyValue567checkResult &= 1568break569570case 0 // frameID571checkResult = object.propertyValue572checkResult &= 1573break574575end switch576else577switch editor.variableID578case EDIT_VAR_PROPVAL // property value579object.propertyValue = editor.variableValue580object.propertyValue &= 1581break582583case 0 // frameID584object.propertyValue = editor.variableValue585object.propertyValue &= 1586break587588end switch589end if590end event591592593event RSDKDraw594GetBit(object.frame, object.propertyValue, 0)595DrawSprite(object.frame)596end event597598599event RSDKLoad600LoadSpriteSheet("MZ/Objects.gif")601SpriteFrame(-16, -16, 32, 32, 159, 322)602SpriteFrame(-64, -16, 128, 32, 159, 322)603604AddEditorVariable("frameID")605SetActiveVariable("frameID")606AddEnumVariable("Small", 0)607AddEnumVariable("Long", 1)608end event609610611