Path: blob/master/Sonic 1/Scripts/SYZ/Push Block.txt
1483 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.value1 : object.drawPos.x12private alias object.value2 : object.solidBoxL13private alias object.value3 : object.solidBoxR14private alias object.value4 : object.pushBoxL15private alias object.value5 : object.pushBoxR16private alias object.value6 : object.beingPushed17private alias object.value7 : object.startPos.x18private alias object.value8 : object.startPos.y19private alias object.value9 : object.pushBoundary20private alias object.value10 : object.activePlayers2122private alias 0 : PUSHBLOCK_PUSHABLE23private alias 1 : PUSHBLOCK_MOVING24private alias 2 : PUSHBLOCK_FALLING2526// Player Aliases27private alias object.xpos : player.xpos28private alias object.ypos : player.ypos29private alias object.ixpos : player.ixpos30private alias object.xvel : player.xvel31private alias object.speed : player.speed32private alias object.left : player.left33private alias object.right : player.right34private alias object.pushing : player.pushing35private alias object.gravity : player.gravity36private alias object.collisionLeft : player.collisionLeft37private alias object.collisionRight : player.collisionRight3839// Path ID Aliases40private alias 0 : PATH_A414243// ========================44// Function Declarations45// ========================4647reserve function PushBlock_DebugDraw48reserve function PushBlock_DebugSpawn49reserve function PushBlock_HandlePushBounds50reserve function PushBlock_HandleObjectCollisions51reserve function PushBlock_HandleTileCollisions525354// ========================55// Function Definitions56// ========================5758private function PushBlock_DebugDraw59DrawSprite(0)60end function616263private function PushBlock_DebugSpawn64CreateTempObject(TypeName[Push Block], 0, object.xpos, object.ypos)65object[tempObjectPos].beingPushed = false6667if object[tempObjectPos].frame == 068object[tempObjectPos].solidBoxL = -1669object[tempObjectPos].solidBoxR = 1670object[tempObjectPos].pushBoxL = -1771object[tempObjectPos].pushBoxR = 1772else73object[tempObjectPos].solidBoxL = -6474object[tempObjectPos].solidBoxR = 6475object[tempObjectPos].pushBoxL = -6576object[tempObjectPos].pushBoxR = 657778object[tempObjectPos].drawOrder = 579end if80end function818283private function PushBlock_HandlePushBounds84if object.floorSensorC == false85if object.floorSensorL == false86object.xvel = -0x4000087object.pushBoundary = object.xpos88object.pushBoundary &= 0xFFFF0000089object.state++90else91if object.floorSensorR == false92object.xvel = 0x4000093object.pushBoundary = object.xpos94object.pushBoundary &= 0xFFFF0000095object.pushBoundary += 0x10000096object.state++97end if98end if99end if100end function101102103private function PushBlock_HandleObjectCollisions104object.activePlayers = 0105temp2 = 0106object.xvel = 0107108foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)109CheckEqual(options.attractMode, true)110temp1 = checkResult111CheckEqual(currentPlayer, 1)112temp1 &= checkResult113114if player[currentPlayer].gravity == GRAVITY_GROUND115if player[currentPlayer].xvel < 0116BoxCollisionTest(C_TOUCH, object.entityPos, 0, -12, object.pushBoxR, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)117if checkResult == true118if player[currentPlayer].left == true119if temp1 == false120SetBit(object.activePlayers, temp2, true)121object.xvel -= 0x6000122object.beingPushed = true123end if124end if125126player[currentPlayer].xpos = player[currentPlayer].collisionRight127player[currentPlayer].xpos += object.solidBoxR128player[currentPlayer].xpos <<= 16129player[currentPlayer].xpos += object.drawPos.x130player[currentPlayer].xvel = 0131player[currentPlayer].speed = 0132player[currentPlayer].pushing = 2133end if134else135if player[currentPlayer].xvel > 0136BoxCollisionTest(C_TOUCH, object.entityPos, object.pushBoxL, -12, 0, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)137if checkResult == true138if player[currentPlayer].right == true139if temp1 == false140SetBit(object.activePlayers, temp2, true)141object.xvel += 0x6000142object.beingPushed = true143end if144end if145146player[currentPlayer].xpos = player[currentPlayer].collisionLeft147player[currentPlayer].xpos += object.solidBoxL148player[currentPlayer].xpos <<= 16149player[currentPlayer].xpos += object.drawPos.x150player[currentPlayer].xvel = 0151player[currentPlayer].speed = 0152player[currentPlayer].pushing = 2153end if154else155BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)156end if157end if158else159BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)160end if161162temp2++163next164165if object.xvel != 0166object.xpos += object.xvel167if object.xvel < 0168ObjectTileCollision(CSIDE_RWALL, object.solidBoxL, 0, PATH_A)169else170ObjectTileCollision(CSIDE_LWALL, object.solidBoxR, 0, PATH_A)171end if172173if checkResult == false174temp0 = oscillation175temp0 &= 31176if temp0 < 3177PlaySfx(SfxName[Push Block], false)178end if179end if180181CallFunction(PushBlock_HandlePushBounds)182temp0 = object.xpos183temp0 &= 0xFFFF0000184if object.drawPos.x != temp0185// No code? ok...186// (in other zones this plays the PushBlock SFX here)187end if188end if189190object.drawPos.x = object.xpos191object.drawPos.x &= 0xFFFF0000192temp2 = 0193foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)194GetBit(temp0, object.activePlayers, temp2)195if temp0 == true196if player[currentPlayer].xpos < object.xpos197player[currentPlayer].ixpos = player[currentPlayer].collisionRight198temp1 = object.solidBoxL199else200player[currentPlayer].ixpos = player[currentPlayer].collisionLeft201temp1 = object.solidBoxR202end if203204FlipSign(player[currentPlayer].xpos)205temp1 <<= 16206player[currentPlayer].xpos += temp1207player[currentPlayer].xpos += object.xpos208else209BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)210end if211212temp2++213next214end function215216217private function PushBlock_HandleTileCollisions218if object.beingPushed == true219if object.gravity == GRAVITY_AIR220object.yvel += 0x1800221object.ypos += object.yvel222temp0 = object.solidBoxL223temp0 += 2224ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)225object.floorSensorL = checkResult226object.gravity = checkResult227228ObjectTileCollision(CSIDE_FLOOR, 0, 16, PATH_A)229object.floorSensorC = checkResult230object.gravity |= checkResult231232temp0 = object.solidBoxR233temp0 -= 2234ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)235object.floorSensorR = checkResult236object.gravity |= checkResult237else238object.yvel = 0239temp0 = object.solidBoxL240temp0 += 2241ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)242243object.floorSensorL = checkResult244object.gravity = checkResult245ObjectTileGrip(CSIDE_FLOOR, 0, 16, PATH_A)246247object.floorSensorC = checkResult248object.gravity |= checkResult249250temp0 = object.solidBoxR251temp0 -= 2252ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)253object.floorSensorR = checkResult254object.gravity |= checkResult255end if256object.gravity ^= 1257else258object.floorSensorL = true259object.floorSensorC = true260object.floorSensorR = true261end if262end function263264265// ========================266// Events267// ========================268269event ObjectUpdate270temp6 = object.xpos271temp7 = object.ypos272273switch object.state274case PUSHBLOCK_PUSHABLE275object.priority = PRIORITY_ACTIVE276CallFunction(PushBlock_HandleObjectCollisions)277CallFunction(PushBlock_HandleTileCollisions)278break279280case PUSHBLOCK_MOVING281object.xpos += object.xvel282if object.xvel > 0283if object.xpos >= object.pushBoundary284object.xpos = object.pushBoundary285object.xvel = 0286object.gravity = GRAVITY_AIR287object.state = PUSHBLOCK_FALLING288end if289else290if object.xpos <= object.pushBoundary291object.xpos = object.pushBoundary292object.xvel = 0293object.gravity = GRAVITY_AIR294object.state = PUSHBLOCK_FALLING295end if296end if297break298299case PUSHBLOCK_FALLING300CallFunction(PushBlock_HandleTileCollisions)301if object.gravity == GRAVITY_GROUND302object.state = PUSHBLOCK_PUSHABLE303end if304break305306end switch307308temp0 = object.xpos309temp1 = object.ypos310temp4 = object.xpos311temp4 &= 0xFFFF0000312temp5 = object.ypos313temp5 &= 0xFFFF0000314object.xpos = temp6315object.ypos = temp7316temp6 &= 0xFFFF0000317temp7 &= 0xFFFF0000318temp4 -= temp6319temp5 -= temp7320foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)321CheckNotEqual(player[currentPlayer].pushing, false)322temp2 = checkResult323CheckEqual(object.state, PUSHBLOCK_PUSHABLE)324temp2 &= checkResult325if temp2 == 0326BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)327if checkResult == COL_TOP328player[currentPlayer].xpos += temp4329player[currentPlayer].ypos += temp5330end if331end if332next333object.xpos = temp0334object.ypos = temp1335336object.drawPos.x = object.xpos337object.drawPos.x &= 0xFFFF0000338if object.outOfBounds == true339temp0 = object.xpos340temp1 = object.ypos341object.xpos = object.startPos.x342object.ypos = object.startPos.y343if object.outOfBounds == true344object.yvel = 0345object.beingPushed = false346object.priority = PRIORITY_BOUNDS347object.state = PUSHBLOCK_PUSHABLE348else349object.xpos = temp0350object.ypos = temp1351end if352end if353end event354355356event ObjectDraw357DrawSpriteXY(object.frame, object.drawPos.x, object.ypos)358end event359360361event ObjectStartup362LoadSpriteSheet("SYZ/Objects.gif")363SpriteFrame(-16, -16, 32, 32, 119, 34)364SpriteFrame(-16, -16, 32, 32, 119, 34) // Supposed to be 128x32 frame, SYZ doesn't need it though (do note, this script is copied from the MZ PushBlock script where the large variant *is* used)365366foreach (TypeName[Push Block], arrayPos0, ALL_ENTITIES)367object[arrayPos0].frame = object[arrayPos0].propertyValue368object[arrayPos0].frame &= 1369object[arrayPos0].startPos.x = object[arrayPos0].xpos370object[arrayPos0].startPos.y = object[arrayPos0].ypos371object[arrayPos0].beingPushed = false372if object[arrayPos0].frame == 0373object[arrayPos0].solidBoxL = -16374object[arrayPos0].solidBoxR = 16375object[arrayPos0].pushBoxL = -17376object[arrayPos0].pushBoxR = 17377else378object[arrayPos0].solidBoxL = -64379object[arrayPos0].solidBoxR = 64380object[arrayPos0].pushBoxL = -65381object[arrayPos0].pushBoxR = 65382end if383next384385SetTableValue(TypeName[Push Block], DebugMode_ObjCount, DebugMode_TypesTable)386SetTableValue(PushBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)387SetTableValue(PushBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)388DebugMode_ObjCount++389end event390391392// ========================393// Editor Events394// ========================395396event RSDKEdit397if editor.returnVariable == true398switch editor.variableID399case EDIT_VAR_PROPVAL // property value400checkResult = object.propertyValue401checkResult &= 1402break403404case 0 // type405checkResult = object.propertyValue406checkResult &= 1407break408409end switch410else411switch editor.variableID412case EDIT_VAR_PROPVAL // property value413object.propertyValue = editor.variableValue414object.propertyValue &= 1415break416417case 0 // type418object.propertyValue = editor.variableValue419object.propertyValue &= 1420break421422end switch423end if424end event425426427event RSDKDraw428DrawSprite(0)429end event430431432event RSDKLoad433LoadSpriteSheet("SYZ/Objects.gif")434SpriteFrame(-16, -16, 32, 32, 119, 34)435SpriteFrame(-16, -16, 32, 32, 119, 34)436437AddEditorVariable("frameID")438SetActiveVariable("frameID")439AddEnumVariable("Small", 0)440// Not used I dont think, it's meant to be a long block but the spriteFrame isn't even setup properly so...441// Update: its not used its a leftover from the marble zone PushBlock object LOL442// AddEnumVariable("Long", 1)443end event444445446