Path: blob/master/Sonic 2/Scripts/CNZ/Bumper.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Bumper Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// Along with being used in Casino Night Zone, this Object is also used in Mission "Bounce House" - M036 - Mission_Zone098// Do note, however, that in that stage this Object is given a name of `OBJECT NAME` instead, meaning all the `TypeName[Bumper]` uses9// you see here end up not working there1011// ========================12// Aliases13// ========================1415private alias object.value0 : object.timer16private alias object.value1 : object.bumpCount17private alias object.value2 : object.playerTimers1819// States20private alias 0 : BUMPER_IDLE21private alias 1 : BUMPER_BUMPED2223// Player Aliases24private alias object.state : player.state25private alias object.xpos : player.xpos26private alias object.ypos : player.ypos27private alias object.xvel : player.xvel28private alias object.yvel : player.yvel29private alias object.speed : player.speed30private alias object.gravity : player.gravity31private alias object.animation : player.animation32private alias object.tileCollisions : player.tileCollisions33private alias object.value1 : player.timer34private alias object.value16 : player.isSidekick // false if player 1, true if player 235private alias object.value36 : player.flyCarryTimer // Tails assist lockout timer36private alias object.value40 : player.hitboxLeft37private alias object.value38 : player.hitboxTop38private alias object.value41 : player.hitboxRight39private alias object.value39 : player.hitboxBottom4041// Global Variable ID Aliases42private alias 22 : GLOBAL_PLAYERSCORE434445// ========================46// Function Declarations47// ========================4849reserve function Bumper_DebugDraw50reserve function Bumper_DebugSpawn515253// ========================54// Function Definitions55// ========================5657private function Bumper_DebugDraw58DrawSprite(0)59end function606162private function Bumper_DebugSpawn63CreateTempObject(TypeName[Bumper], 0, object.xpos, object.ypos)64object[tempObjectPos].drawOrder = 465end function666768// ========================69// Events70// ========================7172event ObjectUpdate73if object.state > BUMPER_IDLE74object.frame = object.timer75object.frame /= 576object.frame++7778object.timer++79if object.timer > 1580object.timer = 081object.state = BUMPER_IDLE82object.frame = 083end if84end if8586if object.outOfBounds == true87object.bumpCount = 088object.priority = PRIORITY_BOUNDS89end if9091temp7 = 092foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)93temp6 = object.playerTimers94temp6 >>= temp795temp6 &= 0xFF96if temp6 == false97#platform: USE_STANDALONE98if player[currentPlayer].animation != ANI_HURT99#endplatform100#platform: USE_ORIGINS101CheckNotEqual(player[currentPlayer].animation, ANI_HURT)102temp0 = checkResult103CheckNotEqual(player[currentPlayer].state, Player_State_Death)104temp0 &= checkResult105if temp0 != 0106#endplatform107BoxCollisionTest(C_TOUCH, object.entityPos, -7, -6, 7, 6, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)108if checkResult == true109if object.state == BUMPER_IDLE110PlaySfx(SfxName[Bumper], false)111if object.bumpCount < 10112CreateTempObject(TypeName[Object Score], 16, object.xpos, object.ypos)113114// global variable "array" (yes, this is actually how its done)115arrayPos0 = GLOBAL_PLAYERSCORE116#platform: USE_DECOMP117arrayPos0 = VarName[player.score]118#endplatform119if player[currentPlayer].isSidekick == false120arrayPos0 += currentPlayer121end if122global[arrayPos0] += 10123124object.bumpCount++125end if126end if127128if object.timer > 5129PlaySfx(SfxName[Bumper], false)130end if131132object.state = BUMPER_BUMPED133object.priority = PRIORITY_ACTIVE134temp0 = player[currentPlayer].xpos135temp0 -= object.xpos136temp1 = player[currentPlayer].ypos137temp1 -= object.ypos138ATan2(temp2, temp0, temp1)139Cos256(temp0, temp2)140Sin256(temp1, temp2)141temp0 *= 0x700142temp1 *= 0x700143if player[currentPlayer].state == Player_State_Carried144player[1].flyCarryTimer = 30145end if146147CheckEqual(player[currentPlayer].animation, ANI_GLIDING)148temp2 = checkResult149CheckEqual(player[currentPlayer].animation, ANI_GLIDING_STOP)150temp2 |= checkResult151CheckEqual(player[currentPlayer].animation, ANI_FLYING)152temp2 |= checkResult153CheckEqual(player[currentPlayer].state, Player_State_TubeRoll)154temp2 |= checkResult155CheckEqual(player[currentPlayer].state, Player_State_TubeAirRoll)156temp2 |= checkResult157if temp2 == false158#platform: USE_STANDALONE159player[currentPlayer].state = Player_State_Air160#endplatform161#platform: USE_ORIGINS162player[currentPlayer].state = Player_State_Air_NoDropDash163#endplatform164// Bug Details:165// This code wasn't updated in Origins Plus to include ANI_HAMMER_JUMP, so166// Amy will always start walking if she hits a Bumper with her hammer out167if player[currentPlayer].animation != ANI_JUMPING168if player[currentPlayer].animation != ANI_RUNNING169player[currentPlayer].animation = ANI_WALKING170end if171end if172end if173174if player[currentPlayer].animation != ANI_GLIDING175player[currentPlayer].xvel = temp0176player[currentPlayer].speed = player[currentPlayer].xvel177player[currentPlayer].timer = 0178end if179180player[currentPlayer].yvel = temp1181player[currentPlayer].gravity = GRAVITY_AIR182player[currentPlayer].tileCollisions = true183184// 3 frame cooldown185temp6 = 3186temp6 <<= temp7187object.playerTimers |= temp6188end if189end if190else191// count down by 1 frame on the current player192temp5 = 1193temp5 <<= temp7194object.playerTimers -= temp5195end if196temp7 += 8197next198end event199200201event ObjectDraw202DrawSprite(object.frame)203end event204205206event ObjectStartup207CheckCurrentStageFolder("Zone04")208if checkResult == true209LoadSpriteSheet("CNZ/Objects.gif")210SpriteFrame(-16, -16, 32, 32, 148, 100)211SpriteFrame(-18, -18, 36, 36, 181, 100)212SpriteFrame(-16, -16, 32, 32, 148, 100)213SpriteFrame(-18, -18, 36, 36, 181, 100)214else215#platform: USE_ORIGINS216if game.playMode == BOOT_PLAYMODE_MISSION // Rather than just a "Zone09" check, check if it's Mission Mode as a whole instead217LoadSpriteSheet("MPZ/Objects2.gif")218SpriteFrame(-16, -16, 32, 32, 1, 1)219SpriteFrame(-18, -18, 36, 36, 34, 1)220SpriteFrame(-16, -16, 32, 32, 1, 1)221SpriteFrame(-18, -18, 36, 36, 34, 1)222else223#endplatform224LoadSpriteSheet("MBZ/Objects.gif")225SpriteFrame(-16, -16, 32, 32, 511, 339)226SpriteFrame(-18, -18, 36, 36, 544, 339)227SpriteFrame(-16, -16, 32, 32, 511, 339)228SpriteFrame(-18, -18, 36, 36, 544, 339)229#platform: USE_ORIGINS230end if231#endplatform232end if233234// Bug Details:235// -> In Origins's MPZ "Bounce House" mission that uses this object, this foreach does not properly work236// This is because Bumpers are given the type name of [OBJECT NAME] instead, in that scene237// -> However, they did not update this foreach for that new name, which makes this TypeName invalid and resolve as 0 instead238// This means that not only do all Bumpers stay on Draw Order 3, but all Blank Objects get bumped up to 4 as well239foreach (TypeName[Bumper], arrayPos0, ALL_ENTITIES)240object[arrayPos0].drawOrder = 4241next242243// Bug Details:244// -> This DebugMode_TypesTable entry doesn't work either in that same aforementioned scene,245// same reason here where it instead spawns an object with type ID 0 (Blank Object)246// -> Not too major at all but hey, I'm sure someone somewhere cares247SetTableValue(TypeName[Bumper], DebugMode_ObjCount, DebugMode_TypesTable)248SetTableValue(Bumper_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)249SetTableValue(Bumper_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)250DebugMode_ObjCount++251end event252253254// ========================255// Editor Events256// ========================257258event RSDKDraw259DrawSprite(0)260end event261262263event RSDKLoad264CheckCurrentStageFolder("Zone04")265if checkResult == true266LoadSpriteSheet("CNZ/Objects.gif")267SpriteFrame(-16, -16, 32, 32, 148, 100)268else269CheckCurrentStageFolder("Zone09") // Technically not accurate to how it functions in-game, but we can't really replicate that behaviour either, so...270if checkResult == true271LoadSpriteSheet("MPZ/Objects2.gif")272SpriteFrame(-16, -16, 32, 32, 1, 1)273else274LoadSpriteSheet("MBZ/Objects.gif")275SpriteFrame(-16, -16, 32, 32, 511, 339)276end if277end if278279SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")280end event281282283