Path: blob/master/Sonic 1/Scripts/Global/InvisibleBlock.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Invisible Block Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.width12private alias object.value1 : object.height1314// States are to be set from the editor15private alias 0 : INVISIBLEBLOCK_SOLID // regular invis block16private alias 1 : INVISIBLEBLOCK_EJECT_L // ejects the player out (to the left)17private alias 2 : INVISIBLEBLOCK_EJECT_R // ejects the player out (to the right)1819// Player Aliases20private alias 0 : SLOT_PLAYER12122private alias object.type : player.type23private alias object.state : player.state24private alias object.xpos : player.xpos25private alias object.speed : player.speed26private alias object.gravity : player.gravity27private alias object.collisionLeft : player.collisionLeft28private alias object.collisionRight : player.collisionRight293031// ========================32// Function Declarations33// ========================3435reserve function InvisibleBlock_DebugDraw36reserve function InvisibleBlock_DebugSpawn373839// ========================40// Function Definitions41// ========================4243private function InvisibleBlock_DebugDraw44temp0 = object.xpos45temp1 = object.ypos46temp0 -= 0x8000047temp1 -= 0x8000048DrawSpriteXY(0, temp0, temp1)4950temp0 += 0x10000051DrawSpriteXY(0, temp0, temp1)5253temp0 -= 0x10000054temp1 += 0x10000055DrawSpriteXY(0, temp0, temp1)5657temp0 += 0x10000058DrawSpriteXY(0, temp0, temp1)59end function606162private function InvisibleBlock_DebugSpawn63// Place a 1x1 block64CreateTempObject(TypeName[Invisible Block], 0x11, object.xpos, object.ypos)65object[tempObjectPos].drawOrder = 566object[tempObjectPos].width = 1667object[tempObjectPos].height = 1668end function697071// ========================72// Events73// ========================7475event ObjectUpdate76temp0 = object.width77FlipSign(temp0)78temp1 = object.height79FlipSign(temp1)8081// Note: state is editable and is set via the editor8283switch object.state84case INVISIBLEBLOCK_SOLID85foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)86if player[currentPlayer].state != Player_State_LedgePullUp87BoxCollisionTest(C_SOLID, object.entityPos, temp0, temp1, object.width, object.height, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)88switch checkResult89case COL_NONE90temp0 += 291temp1 += 292temp2 = object.width93temp3 = object.height94temp2 -= 295temp3 -= 296BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, temp2, temp3, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)97if checkResult == true98player[currentPlayer].gravity = GRAVITY_GROUND99end if100break101102case COL_BOTTOM103if player[currentPlayer].gravity == GRAVITY_GROUND104CallFunction(Player_Kill)105end if106break107108end switch109end if110next111break112113case INVISIBLEBLOCK_EJECT_L114foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)115if player[currentPlayer].state != Player_State_LedgePullUp116BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, object.width, object.height, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)117if checkResult == true118if player[currentPlayer].gravity == GRAVITY_GROUND119player[currentPlayer].xpos = player[currentPlayer].collisionRight120FlipSign(player[currentPlayer].xpos)121player[currentPlayer].xpos -= object.width122player[currentPlayer].xpos <<= 16123player[currentPlayer].xpos += object.xpos124if player[currentPlayer].speed > 0125player[currentPlayer].speed = 0126end if127end if128end if129end if130next131break132133case INVISIBLEBLOCK_EJECT_R134foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)135if player[currentPlayer].state != Player_State_LedgePullUp136BoxCollisionTest(C_TOUCH, object.entityPos, temp0, temp1, object.width, object.height, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)137if checkResult == true138if player[currentPlayer].gravity == GRAVITY_GROUND139player[currentPlayer].xpos = player[currentPlayer].collisionLeft140FlipSign(player[currentPlayer].xpos)141player[currentPlayer].xpos += object.width142player[currentPlayer].xpos <<= 16143player[currentPlayer].xpos += object.xpos144if player[currentPlayer].speed < 0145player[currentPlayer].speed = 0146end if147end if148end if149end if150next151break152153end switch154end event155156157event ObjectDraw158if player[SLOT_PLAYER1].type == TypeName[Debug Mode]159temp0 = object.xpos160temp1 = object.ypos161temp2 = object.propertyValue162temp4 = temp2163temp4 &= 0xF0164temp4 <<= 15165temp2 >>= 4166temp2++167temp6 = temp2168temp3 = object.propertyValue169temp3 &= 0x0F170temp5 = temp3171temp5 <<= 19172temp3++173temp0 -= temp4174temp4 = temp0175temp1 -= temp5176while temp3 > 0177while temp2 > 0178DrawSpriteXY(object.state, temp0, temp1)179temp0 += 0x100000180temp2--181loop182temp2 = temp6183temp0 = temp4184temp1 += 0x100000185temp3--186loop187end if188end event189190191event ObjectStartup192LoadSpriteSheet("Global/Display.gif")193194// Sprite Frames195// Original S1 releases only used the top left Eggman icon and the arrows were just more Eggmen,196// but a later update changed the object's debug view a little bit to be clearer197SpriteFrame(-8, -7, 16, 14, 1, 176) // 0 - Eggman face198SpriteFrame(-8, -7, 16, 14, 17, 176) // 1 - Left arrow199SpriteFrame(-8, -7, 16, 14, 1, 190) // 2 - Right arrow200// (bottom right Eggman icon on the sheet is unused)201202// Do some set up for every invis block object203foreach (TypeName[Invisible Block], arrayPos0, ALL_ENTITIES)204object[arrayPos0].drawOrder = 5205206object[arrayPos0].width = object[arrayPos0].propertyValue207object[arrayPos0].width &= 0xF0208object[arrayPos0].width += 16209object[arrayPos0].width >>= 1210211object[arrayPos0].height = object[arrayPos0].propertyValue212object[arrayPos0].height &= 0x0F213object[arrayPos0].height++214object[arrayPos0].height <<= 3215next216217// Add this object to the debug object list218// Note that it's only added once, so there aren't extra variants for different sizes or modes or anything219SetTableValue(TypeName[Invisible Block], DebugMode_ObjCount, DebugMode_TypesTable)220SetTableValue(InvisibleBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)221SetTableValue(InvisibleBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)222DebugMode_ObjCount++223end event224225226// ========================227// Editor Events228// ========================229230event RSDKEdit231if editor.returnVariable == true232switch editor.variableID233case EDIT_VAR_PROPVAL // property value234checkResult = object.propertyValue235break236237case 0 // width238checkResult = object.propertyValue239checkResult >>= 4240checkResult &= 0xF241break242243case 1 // height244checkResult = object.propertyValue245checkResult &= 0xF246break247248case 2 // type249checkResult = object.state250break251252end switch253else254switch editor.variableID255case EDIT_VAR_PROPVAL // property value256object.propertyValue = editor.variableValue257break258259case 0 // width260temp0 = editor.variableValue261temp0 &= 0xF262temp0 <<= 4263object.propertyValue &= 0x0F264object.propertyValue |= temp0265break266267case 1 // height268temp0 = editor.variableValue269temp0 &= 0xF270object.propertyValue &= 0xF0271object.propertyValue |= temp0272break273274case 2 // type275object.state = editor.variableValue276break277278end switch279end if280end event281282283event RSDKDraw284temp0 = object.xpos285temp1 = object.ypos286temp2 = object.propertyValue287288temp4 = temp2289temp4 &= 0xF0290temp4 <<= 15291292temp2 >>= 4293temp2++294temp6 = temp2295296temp3 = object.propertyValue297temp3 &= 0x0F298temp5 = temp3299temp5 <<= 19300temp3++301302temp0 -= temp4303temp4 = temp0304temp1 -= temp5305while temp3 > 0306while temp2 > 0307DrawSpriteXY(object.state, temp0, temp1)308temp0 += 0x100000309temp2--310loop311temp2 = temp6312temp0 = temp4313temp1 += 0x100000314temp3--315loop316317// TODO: I had an idea to add a box around the object but... would that really serve to do much?318end event319320321event RSDKLoad322LoadSpriteSheet("Global/Display.gif")323SpriteFrame(-8, -7, 16, 14, 1, 176)324SpriteFrame(-8, -7, 16, 14, 17, 176)325SpriteFrame(-8, -7, 16, 14, 1, 190)326327AddEditorVariable("width")328AddEditorVariable("height")329330AddEditorVariable("type")331SetActiveVariable("type")332AddEnumVariable("Solid", INVISIBLEBLOCK_SOLID)333AddEnumVariable("Eject left", INVISIBLEBLOCK_EJECT_L)334AddEnumVariable("Eject right", INVISIBLEBLOCK_EJECT_R)335336// TODO: it may just be a mistake, but MZ1 gives one a scale of 0 and draw order of 0 too337end event338339340