Path: blob/master/Sonic 1/Scripts/LZ/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.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.activePlayers2223private alias 0 : PUSHBLOCK_PUSHABLE24private alias 1 : PUSHBLOCK_MOVING25private alias 2 : PUSHBLOCK_FALLING2627// Player Aliases28private alias object.xpos : player.xpos29private alias object.ypos : player.ypos30private alias object.ixpos : player.ixpos31private alias object.xvel : player.xvel32private alias object.speed : player.speed33private alias object.left : player.left34private alias object.right : player.right35private alias object.pushing : player.pushing36private alias object.gravity : player.gravity37private alias object.collisionLeft : player.collisionLeft38private alias object.collisionRight : player.collisionRight3940private alias object.value17 : debugMode.currentSelection4142// Path ID Aliases43private alias 0 : PATH_A444546// ========================47// Function Declarations48// ========================4950reserve function PushBlock_DebugDraw51reserve function PushBlock_DebugSpawn52reserve function PushBlock_HandlePushBounds53reserve function PushBlock_HandleObjectCollisions54reserve function PushBlock_HandleTileCollisions555657// ========================58// Static Values59// ========================6061private value PushBlock_startDebugID = 0626364// ========================65// Function Definitions66// ========================6768private function PushBlock_DebugDraw69temp0 = debugMode[0].currentSelection70temp0 -= PushBlock_startDebugID71DrawSprite(temp0)72end function737475private function PushBlock_DebugSpawn76CreateTempObject(TypeName[Push Block], 0, object.xpos, object.ypos)77object[tempObjectPos].beingPushed = false78object[tempObjectPos].frame = debugMode[0].currentSelection79object[tempObjectPos].frame -= PushBlock_startDebugID80if object[tempObjectPos].frame == 081object[tempObjectPos].solidBoxL = -1682object[tempObjectPos].solidBoxR = 1683object[tempObjectPos].pushBoxL = -1784object[tempObjectPos].pushBoxR = 1785else86object[tempObjectPos].solidBoxL = -6487object[tempObjectPos].solidBoxR = 6488object[tempObjectPos].pushBoxL = -6589object[tempObjectPos].pushBoxR = 659091object[tempObjectPos].drawOrder = 592end if93end function949596private function PushBlock_HandlePushBounds97if object.floorSensorC == false98if object.floorSensorL == false99object.xvel = -0x40000100object.pushBoundary = object.xpos101object.pushBoundary &= 0xFFFF00000102object.state++103else104if object.floorSensorR == false105object.xvel = 0x40000106object.pushBoundary = object.xpos107object.pushBoundary &= 0xFFFF00000108object.pushBoundary += 0x100000109object.state++110end if111end if112end if113end function114115116private function PushBlock_HandleObjectCollisions117object.activePlayers = 0118temp2 = 0119object.xvel = 0120foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)121CheckEqual(options.attractMode, true)122temp1 = checkResult123CheckEqual(currentPlayer, 1)124temp1 &= checkResult125126if player[currentPlayer].gravity == GRAVITY_GROUND127if player[currentPlayer].xvel < 0128BoxCollisionTest(C_TOUCH, object.entityPos, 0, -12, object.pushBoxR, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)129if checkResult == true130if player[currentPlayer].left == true131if temp1 == false132SetBit(object.activePlayers, temp2, true)133object.xvel -= 0x6000134object.beingPushed = true135end if136end if137player[currentPlayer].xpos = player[currentPlayer].collisionRight138player[currentPlayer].xpos += object.solidBoxR139player[currentPlayer].xpos <<= 16140player[currentPlayer].xpos += object.drawPos.x141player[currentPlayer].xvel = 0142player[currentPlayer].speed = 0143player[currentPlayer].pushing = 2144end if145else146if player[currentPlayer].xvel > 0147BoxCollisionTest(C_TOUCH, object.entityPos, object.pushBoxL, -12, 0, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)148if checkResult == true149if player[currentPlayer].right == true150if temp1 == false151SetBit(object.activePlayers, temp2, true)152object.xvel += 0x6000153object.beingPushed = true154end if155end if156157player[currentPlayer].xpos = player[currentPlayer].collisionLeft158player[currentPlayer].xpos += object.solidBoxL159player[currentPlayer].xpos <<= 16160player[currentPlayer].xpos += object.drawPos.x161player[currentPlayer].xvel = 0162player[currentPlayer].speed = 0163player[currentPlayer].pushing = 2164end if165else166BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)167end if168end if169else170BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)171end if172173temp2++174next175176if object.xvel != 0177object.xpos += object.xvel178if object.xvel < 0179ObjectTileCollision(CSIDE_RWALL, object.solidBoxL, 0, PATH_A)180else181ObjectTileCollision(CSIDE_LWALL, object.solidBoxR, 0, PATH_A)182end if183184CallFunction(PushBlock_HandlePushBounds)185temp0 = object.xpos186temp0 &= 0xFFFF0000187if object.drawPos.x != temp0188temp0 = oscillation189temp0 &= 31190if temp0 < 3191PlaySfx(SfxName[Push Block], false)192end if193end if194end if195196object.drawPos.x = object.xpos197object.drawPos.x &= 0xFFFF0000198temp2 = 0199foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)200GetBit(temp0, object.activePlayers, temp2)201if temp0 == true202if player[currentPlayer].xpos < object.xpos203player[currentPlayer].ixpos = player[currentPlayer].collisionRight204temp1 = object.solidBoxL205else206player[currentPlayer].ixpos = player[currentPlayer].collisionLeft207temp1 = object.solidBoxR208end if209210FlipSign(player[currentPlayer].xpos)211temp1 <<= 16212player[currentPlayer].xpos += temp1213player[currentPlayer].xpos += object.xpos214else215BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)216end if217218temp2++219next220end function221222223private function PushBlock_HandleTileCollisions224if object.beingPushed == true225if object.gravity == GRAVITY_AIR226object.yvel += 0x1800227object.ypos += object.yvel228temp0 = object.solidBoxL229temp0 += 2230ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)231object.floorSensorL = checkResult232object.gravity = checkResult233234ObjectTileCollision(CSIDE_FLOOR, 0, 16, PATH_A)235object.floorSensorC = checkResult236object.gravity |= checkResult237238temp0 = object.solidBoxR239temp0 -= 2240ObjectTileCollision(CSIDE_FLOOR, temp0, 16, PATH_A)241object.floorSensorR = checkResult242object.gravity |= checkResult243else244object.yvel = 0245temp0 = object.solidBoxL246temp0 += 2247ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)248249object.floorSensorL = checkResult250object.gravity = checkResult251ObjectTileGrip(CSIDE_FLOOR, 0, 16, PATH_A)252253object.floorSensorC = checkResult254object.gravity |= checkResult255256temp0 = object.solidBoxR257temp0 -= 2258ObjectTileGrip(CSIDE_FLOOR, temp0, 16, PATH_A)259object.floorSensorR = checkResult260object.gravity |= checkResult261end if262object.gravity ^= 1263else264object.floorSensorL = true265object.floorSensorC = true266object.floorSensorR = true267end if268end function269270271// ========================272// Events273// ========================274275event ObjectUpdate276temp6 = object.xpos277temp7 = object.ypos278279switch object.state280case PUSHBLOCK_PUSHABLE281object.priority = PRIORITY_ACTIVE282CallFunction(PushBlock_HandleObjectCollisions)283CallFunction(PushBlock_HandleTileCollisions)284break285286case PUSHBLOCK_MOVING287object.xpos += object.xvel288if object.xvel > 0289if object.xpos >= object.pushBoundary290object.xpos = object.pushBoundary291object.xvel = 0292object.gravity = GRAVITY_AIR293object.state = PUSHBLOCK_FALLING294end if295else296if object.xpos <= object.pushBoundary297object.xpos = object.pushBoundary298object.xvel = 0299object.gravity = GRAVITY_AIR300object.state = PUSHBLOCK_FALLING301end if302end if303break304305case PUSHBLOCK_FALLING306CallFunction(PushBlock_HandleTileCollisions)307if object.gravity == GRAVITY_GROUND308object.state = PUSHBLOCK_PUSHABLE309end if310break311312end switch313314temp0 = object.xpos315temp1 = object.ypos316temp4 = object.xpos317temp4 &= 0xFFFF0000318temp5 = object.ypos319temp5 &= 0xFFFF0000320object.xpos = temp6321object.ypos = temp7322temp6 &= 0xFFFF0000323temp7 &= 0xFFFF0000324temp4 -= temp6325temp5 -= temp7326foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)327CheckNotEqual(player[currentPlayer].pushing, false)328temp2 = checkResult329CheckEqual(object.state, 0)330temp2 &= checkResult331if temp2 == 0332BoxCollisionTest(C_SOLID, object.entityPos, object.solidBoxL, -16, object.solidBoxR, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)333if checkResult == COL_TOP334player[currentPlayer].xpos += temp4335player[currentPlayer].ypos += temp5336end if337end if338next339object.xpos = temp0340object.ypos = temp1341342object.drawPos.x = object.xpos343object.drawPos.x &= 0xFFFF0000344if object.outOfBounds == true345temp0 = object.xpos346temp1 = object.ypos347object.xpos = object.startPos.x348object.ypos = object.startPos.y349if object.outOfBounds == true350object.yvel = 0351object.beingPushed = false352object.priority = PRIORITY_BOUNDS353object.state = 0354else355object.xpos = temp0356object.ypos = temp1357end if358end if359end event360361362event ObjectDraw363DrawSpriteXY(object.frame, object.drawPos.x, object.ypos)364end event365366367event ObjectStartup368LoadSpriteSheet("LZ/Objects.gif")369SpriteFrame(-16, -16, 32, 32, 84, 223)370SpriteFrame(-64, -16, 128, 32, 84, 223)371372foreach (TypeName[Push Block], arrayPos0, ALL_ENTITIES)373object[arrayPos0].frame = object[arrayPos0].propertyValue374object[arrayPos0].frame &= 1375376object[arrayPos0].startPos.x = object[arrayPos0].xpos377object[arrayPos0].startPos.y = object[arrayPos0].ypos378object[arrayPos0].beingPushed = false379380if object[arrayPos0].frame == 0381object[arrayPos0].solidBoxL = -16382object[arrayPos0].solidBoxR = 16383object[arrayPos0].pushBoxL = -17384object[arrayPos0].pushBoxR = 17385else386object[arrayPos0].solidBoxL = -64387object[arrayPos0].solidBoxR = 64388object[arrayPos0].pushBoxL = -65389object[arrayPos0].pushBoxR = 65390end if391next392393temp0 = 0394PushBlock_startDebugID = DebugMode_ObjCount395while temp0 < 2396SetTableValue(TypeName[Push Block], DebugMode_ObjCount, DebugMode_TypesTable)397SetTableValue(PushBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)398SetTableValue(PushBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)399DebugMode_ObjCount++400temp0++401loop402end event403404405// ========================406// Editor Events407// ========================408409event RSDKEdit410if editor.returnVariable == true411switch editor.variableID412case EDIT_VAR_PROPVAL // property value413checkResult = object.propertyValue414checkResult &= 1415break416417case 0 // frameID418checkResult = object.propertyValue419checkResult &= 1420break421422end switch423else424switch editor.variableID425case EDIT_VAR_PROPVAL // property value426object.propertyValue = editor.variableValue427object.propertyValue &= 1428break429430case 0 // frameID431object.propertyValue = editor.variableValue432object.propertyValue &= 1433break434435end switch436end if437end event438439440event RSDKDraw441GetBit(object.frame, object.propertyValue, 0)442DrawSprite(object.frame)443end event444445446event RSDKLoad447LoadSpriteSheet("LZ/Objects.gif")448SpriteFrame(-16, -16, 32, 32, 84, 223)449SpriteFrame(-64, -16, 128, 32, 84, 223)450451AddEditorVariable("frameID")452SetActiveVariable("frameID")453AddEnumVariable("Small", 0)454AddEnumVariable("Long", 1)455end event456457458