Path: blob/master/Sonic 2/Scripts/CNZ/Eggman.txt
1487 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Eggman Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// Using CNZEggman as a prefix here because there's like 12 "Eggman" objects in the game so its less confusing this way89// ========================10// Aliases11// ========================1213private alias object.value0 : object.timer14private alias object.value1 : object.originPos.y15private alias object.value2 : object.oscillateAngle16private alias object.value3 : object.health17private alias object.value4 : object.invincibilityTimer18private alias object.value5 : object.exploding19private alias object.value6 : object.boundsL20private alias object.value7 : object.boundsR21private alias object.value8 : object.boundsT22private alias object.value9 : object.boundsB23private alias object.value10 : object.isClawWide24private alias object.value11 : object.bombDropDisabled25private alias object.value12 : object.sparkSfxTimer26private alias object.value13 : object.paletteTimer27private alias object.value14 : object.isCNZ2829// Eggman States30private alias 0 : CNZEGGMAN_AWAITPLAYER31private alias 1 : CNZEGGMAN_ENTERDELAY32private alias 2 : CNZEGGMAN_MOVEH33private alias 3 : CNZEGGMAN_MOVEV_DOWN34private alias 4 : CNZEGGMAN_MOVEV_UP35private alias 5 : CNZEGGMAN_DROPBOMB36private alias 6 : CNZEGGMAN_DROPPEDBOMB37private alias 7 : CNZEGGMAN_EXPLODE38private alias 8 : CNZEGGMAN_DEFEATFALL39private alias 9 : CNZEGGMAN_DEFEATRISE40private alias 10 : CNZEGGMAN_FLEE41private alias 11 : CNZEGGMAN_ESCAPE4243// Eggman Animations44private alias 0 : CNZEGGANI_INVISIBLE45private alias 1 : CNZEGGANI_IDLE46private alias 2 : CNZEGGANI_LAUGH47private alias 3 : CNZEGGANI_HIT48private alias 4 : CNZEGGANI_DEFEATED49private alias 5 : CNZEGGANI_TOASTED50private alias 6 : CNZEGGANI_PANIC5152// EggmanClaw Aliases53private alias object.value1 : eggmanClaw.parent54private alias object.value2 : eggmanClaw.electricityActive5556// EggmanClaw States57private alias 1 : CNZEGGMANCLAW_DEBRIS5859// EggmanBomb Aliases60private alias object.value1 : eggmanBomb.parent61private alias object.value2 : eggmanBomb.offset.y6263// EggmanBomb States64private alias 1 : CNZEGGMANBOMB_DROPPED6566// BossWall States67private alias 1 : CNZBOSSWALL_APPEAR68private alias 3 : CNZBOSSWALL_DELWALL6970// Player Aliases71private alias object.xpos : player.xpos72private alias object.ypos : player.ypos73private alias object.xvel : player.xvel74private alias object.speed : player.speed75private alias object.animation : player.animation76private alias object.collisionRight : player.collisionRight7778private alias object.value40 : player.hitboxLeft79private alias object.value38 : player.hitboxTop80private alias object.value41 : player.hitboxRight81private alias object.value39 : player.hitboxBottom8283// Music Events84private alias 26 : SLOT_MUSICEVENT_BOSS8586private alias 0 : MUSICEVENT_FADETOBOSS87private alias 1 : MUSICEVENT_FADETOSTAGE8889// ========================90// Function Declarations91// ========================9293reserve function CNZEggman_Oscillate949596// ========================97// Function Definitions98// ========================99100private function CNZEggman_Oscillate101Sin256(object.ypos, object.oscillateAngle)102object.ypos <<= 10103object.ypos += object.originPos.y104105object.oscillateAngle += 2106object.oscillateAngle &= 0xFF107end function108109110// ========================111// Events112// ========================113114event ObjectUpdate115if object.isCNZ == true116object.paletteTimer++117if object.paletteTimer == 4118object.paletteTimer = 0119RotatePalette(0, 194, 196, false)120RotatePalette(0, 197, 202, false)121end if122else123// In MBZ/Egg Gauntlet, where the palette indices used are different124object.paletteTimer++125if object.paletteTimer == 4126object.paletteTimer = 0127RotatePalette(0, 112, 114, false)128RotatePalette(0, 115, 120, false)129end if130end if131132switch object.state133case CNZEGGMAN_AWAITPLAYER134if player[0].xpos > object[-1].xpos135temp0 = -32136temp0 *= screen.xsize137temp0 /= 320138temp0 -= 192139temp0 += object[-1].ixpos140stage.newXBoundary1 = temp0141142temp0 = 32143temp0 *= screen.xsize144temp0 /= 320145temp0 += 192146temp0 += object[-1].ixpos147stage.newXBoundary2 = temp0148149object.boundsL = object[-1].xpos150object.boundsL -= 0x800000151152object.boundsR = object[-1].xpos153object.boundsR += 0x800000154155object.boundsT = object.ypos156object.boundsB = object.ypos157object.boundsB += 0x2C0000158159object.animation = CNZEGGANI_IDLE160ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOBOSS, 0, 0)161object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE162163object[-2].type = TypeName[Eggman Claw]164object[-2].propertyValue = 0 // left claw165eggmanClaw[-2].parent = object.entityPos166167object[+1].type = TypeName[Eggman Claw]168object[+1].propertyValue = 1 // right claw169eggmanClaw[+1].parent = object.entityPos170171172object[+2].priority = PRIORITY_ACTIVE173object[+2].state = CNZBOSSWALL_APPEAR174175object.xvel = -0x18000176object.originPos.y = object.ypos177178CheckCurrentStageFolder("Zone04")179if checkResult == true180object.isCNZ = true181else182// We're gonna assume that we're in MBZ, then183object.isCNZ = false184end if185186#platform: USE_STANDALONE187object.health = 8188#endplatform189#platform: USE_ORIGINS190if game.bossOneLife == false191object.health = 8192else193object.health = 1194end if195#endplatform196197object.priority = PRIORITY_ACTIVE198object.state = CNZEGGMAN_ENTERDELAY199end if200break201202case CNZEGGMAN_ENTERDELAY203object.timer++204if object.timer == 60205object.timer = 0206object.state = CNZEGGMAN_MOVEH207end if208break209210case CNZEGGMAN_MOVEH211CallFunction(CNZEggman_Oscillate)212object.xpos += object.xvel213214if object.xvel > 0215if object.xpos > object.boundsR216object.xpos = object.boundsR217object.direction ^= FLIP_X218FlipSign(object.xvel)219object.bombDropDisabled = false220end if221else222if object.xpos < object.boundsL223object.xpos = object.boundsL224object.direction ^= FLIP_X225FlipSign(object.xvel)226object.bombDropDisabled = false227end if228end if229230object.timer++231if object.timer == 60232object.timer = 0233eggmanClaw[-2].electricityActive = true234object.isClawWide ^= true235end if236237object.sparkSfxTimer++238if object.sparkSfxTimer == 32239object.sparkSfxTimer = 0240PlaySfx(SfxName[BossSpark], false)241end if242243foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)244if object.state == CNZEGGMAN_MOVEH245if player[currentPlayer].ypos > object.ypos246temp0 = player[currentPlayer].xpos247temp0 -= object.xpos248Abs(temp0)249if temp0 < 0x100000250temp0 = player[currentPlayer].ypos251temp0 -= object.ypos252Abs(temp0)253if temp0 < 0x600000254object.state = CNZEGGMAN_MOVEV_DOWN255else256if object.bombDropDisabled == false257object.timer = 0258object.isClawWide = false259object.state = CNZEGGMAN_DROPBOMB260end if261end if262end if263end if264end if265next266break267268case CNZEGGMAN_MOVEV_DOWN269object.isClawWide = true270object.ypos += 0x18000271272if object.ypos > object.boundsB273object.state = CNZEGGMAN_MOVEV_UP274end if275276object.sparkSfxTimer++277if object.sparkSfxTimer == 32278object.sparkSfxTimer = 0279PlaySfx(SfxName[BossSpark], false)280end if281break282283case CNZEGGMAN_MOVEV_UP284object.isClawWide = false285object.ypos -= 0x18000286287if object.ypos < object.boundsT288object.ypos = object.boundsT289object.originPos.y = object.boundsT290object.state = CNZEGGMAN_MOVEH291end if292293object.sparkSfxTimer++294if object.sparkSfxTimer == 32295object.sparkSfxTimer = 0296PlaySfx(SfxName[BossSpark], false)297end if298break299300case CNZEGGMAN_DROPBOMB301CallFunction(CNZEggman_Oscillate)302303object.timer++304if object.timer == 1305eggmanClaw[-2].electricityActive = false306arrayPos0 = object.entityPos307arrayPos0--308ResetObjectEntity(arrayPos0, TypeName[Eggman Bomb], 0, object.xpos, object.ypos)309eggmanBomb[arrayPos0].parent = object.entityPos310else311object[-1].ypos = object.ypos312object[-1].ypos += eggmanBomb[-1].offset.y313end if314315if object.timer == 80316object.timer = 0317object.isClawWide = true318object[-1].state = CNZEGGMANBOMB_DROPPED319object.state = CNZEGGMAN_DROPPEDBOMB320end if321break322323case CNZEGGMAN_DROPPEDBOMB324CallFunction(CNZEggman_Oscillate)325326object.timer++327if object.timer == 20328object.timer = 0329object.isClawWide = false330object.bombDropDisabled = true331eggmanClaw[-2].electricityActive = true332object.state = CNZEGGMAN_MOVEH333end if334break335336case CNZEGGMAN_EXPLODE337object.timer++338if object.timer == 60339if object.direction == FLIP_NONE340object[-2].xvel = -0x10000341else342object[-2].xvel = 0x10000343end if344object[-2].yvel = 0345object[-2].state = CNZEGGMANCLAW_DEBRIS346end if347348if object.timer == 120349if object.direction == FLIP_NONE350object[+1].xvel = 0x10000351else352object[+1].xvel = -0x10000353end if354object[+1].yvel = 0355object[+1].state = CNZEGGMANCLAW_DEBRIS356end if357358if object.timer == 180359object.timer = 0360object.animation = CNZEGGANI_TOASTED361object.exploding = false362object.state++363ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOSTAGE, 0, 0)364object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE365object[+3].priority = PRIORITY_ACTIVE366object[+3].state = CNZBOSSWALL_DELWALL367temp0 = tileLayer[0].xsize368temp0 <<= 7369stage.newXBoundary2 = temp0370end if371break372373case CNZEGGMAN_DEFEATFALL374object.ypos += object.yvel375object.yvel += 0x1800376377object.timer++378if object.timer == 16379object.yvel = 0380object.timer = 0381object.animationTimer = 0382object.state++383end if384break385386case CNZEGGMAN_DEFEATRISE387if object.timer < 24388object.ypos += object.yvel389object.yvel -= 0x800390object.timer++391else392object.timer = 0393object.yvel = 0394object.originPos.y = object.ypos395object.state++396end if397break398399case CNZEGGMAN_FLEE400CallFunction(CNZEggman_Oscillate)401if object.timer < 8402object.timer++403else404object.timer = 0405object.animation = CNZEGGANI_PANIC406object.animationTimer = 0407object.direction = FLIP_X408object.priority = PRIORITY_ACTIVE409410#platform: USE_STANDALONE411temp0 = tileLayer[0].xsize412temp0 <<= 7413stage.newXBoundary2 = temp0414#endplatform415416object.state++417end if418break419420case CNZEGGMAN_ESCAPE421object.xpos += 0x40000422object.originPos.y -= 0x4000423CallFunction(CNZEggman_Oscillate)424425if object.outOfBounds == true426ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, 0, 0)427end if428break429430end switch431432if object.health != 0433if object.invincibilityTimer > 0434object.invincibilityTimer--435GetBit(temp0, object.invincibilityTimer, 0)436if temp0 == true437SetPaletteEntry(0, 192, 0xE0E0E0)438else439SetPaletteEntry(0, 192, 0x000000)440end if441end if442443foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)444if object.invincibilityTimer == 0445CheckEqual(player[currentPlayer].animation, ANI_HURT)446temp0 = checkResult447CheckEqual(player[currentPlayer].animation, ANI_DYING)448temp0 |= checkResult449CheckEqual(player[currentPlayer].animation, ANI_DROWNING)450temp0 |= checkResult451if temp0 != 0452if object.animation != CNZEGGANI_LAUGH453object.animation = CNZEGGANI_LAUGH454object.animationTimer = 0455end if456end if457458BoxCollisionTest(C_TOUCH, object.entityPos, -24, -24, 24, 24, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)459if checkResult == true460CallFunction(Player_CheckHit)461if checkResult == true462object.health--463if object.health == 0464#platform: USE_ORIGINS465CallNativeFunction2(NotifyCallback, NOTIFY_KILL_BOSS, 0)466CallNativeFunction2(NotifyCallback, NOTIFY_BOSS_END, 1)467#endplatform468469player.score += 1000470eggmanClaw[-2].electricityActive = false471object.timer = 0472object.animation = CNZEGGANI_DEFEATED473object.animationTimer = 0474object.exploding = true475object.originPos.y = object.ypos476object.state = CNZEGGMAN_EXPLODE477if object[-1].type == TypeName[Eggman Bomb]478temp0 = object.entityPos479temp0--480ResetObjectEntity(temp0, TypeName[Explosion], 0, object[-1].xpos, object[-1].ypos)481end if482else483object.animation = CNZEGGANI_HIT484object.animationTimer = 0485object.invincibilityTimer = 64486PlaySfx(SfxName[Boss Hit], false)487end if488end if489end if490end if491next492end if493494if object.state != CNZEGGMAN_ESCAPE495foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)496temp0 = player[currentPlayer].collisionRight497temp0 <<= 16498temp0 += player[currentPlayer].xpos499temp1 = stage.curXBoundary2500temp1 <<= 16501if temp0 > temp1502player[currentPlayer].xvel = 0503player[currentPlayer].speed = 0504player[currentPlayer].xpos = temp1505temp0 = player[currentPlayer].collisionRight506temp0 <<= 16507player[currentPlayer].xpos -= temp0508end if509next510end if511512if object.exploding == true513temp0 = oscillation514temp0 &= 7515if temp0 == 0516Rand(temp0, 48)517temp0 -= 24518temp0 <<= 16519temp0 += object.xpos520Rand(temp1, 48)521temp1 -= 24522temp1 <<= 16523temp1 += object.ypos524CreateTempObject(TypeName[Explosion], 0, temp0, temp1)525object[tempObjectPos].drawOrder = 5526PlaySfx(SfxName[Explosion], false)527end if528end if529end event530531532event ObjectDraw533DrawSpriteFX(6, FX_FLIP, object.xpos, object.ypos)534535switch object.animation536default537case CNZEGGANI_INVISIBLE538break539540case CNZEGGANI_IDLE541temp0 = object.animationTimer542temp0 >>= 3543object.animationTimer++544object.animationTimer &= 15545DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)546break547548case CNZEGGANI_LAUGH549temp0 = object.animationTimer550temp0 &= 15551temp0 >>= 3552temp0 += 2553554object.animationTimer++555if object.animationTimer == 50556object.animationTimer = 0557if player[0].animation != ANI_DYING558object.animation = CNZEGGANI_IDLE559end if560end if561562DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)563break564565case CNZEGGANI_HIT566temp0 = object.animationTimer567temp0 &= 1568temp0 += 2569570object.animationTimer++571if object.animationTimer == 50572object.animationTimer = 0573object.animation = CNZEGGANI_IDLE574end if575576DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)577break578579case CNZEGGANI_DEFEATED580temp0 = object.animationTimer581temp0 >>= 5582temp0 += 4583temp0 %= 5584object.animationTimer++585object.animationTimer &= 63586DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)587break588589case CNZEGGANI_TOASTED590DrawSpriteFX(5, FX_FLIP, object.xpos, object.ypos)591break592593case CNZEGGANI_PANIC594temp0 = object.animationTimer595temp0 >>= 3596object.animationTimer++597object.animationTimer &= 15598DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)599600temp0 = object.animationTimer601temp0 >>= 2602temp0 &= 1603if temp0 == true604DrawSpriteFX(7, FX_FLIP, object.xpos, object.ypos)605end if606break607608end switch609end event610611612event ObjectStartup613CheckCurrentStageFolder("Zone04")614if checkResult == true615LoadSpriteSheet("CNZ/Objects.gif")616SpriteFrame(-28, -16, 44, 16, 76, 140) // Idle 1 - #0617SpriteFrame(-28, -16, 44, 16, 121, 140) // Idle 2 - #1618SpriteFrame(-28, -16, 44, 16, 166, 140) // Laugh 1 - #2619SpriteFrame(-28, -16, 44, 16, 211, 140) // Laugh 2 - #3620SpriteFrame(-28, -16, 44, 16, 166, 157) // Hit - #4621SpriteFrame(-28, -16, 44, 16, 211, 157) // Destroyed - #5622SpriteFrame(-40, -40, 80, 72, 175, 183) // Eggmobile - #6623SpriteFrame(-3, -18, 11, 8, 154, 157) // Panic Sweat - #7624625if options.vsMode == true626foreach (TypeName[Eggman], arrayPos0, ALL_ENTITIES)627object[arrayPos0].type = TypeName[Blank Object]628next629end if630else631LoadSpriteSheet("MBZ/Objects.gif")632SpriteFrame(-28, -16, 44, 16, 1, 5) // Idle 1 - #0633SpriteFrame(-28, -16, 44, 16, 62, 5) // Idle 2 - #1634SpriteFrame(-28, -16, 44, 16, 1, 26) // Laugh 1 - #2635SpriteFrame(-28, -16, 44, 16, 62, 26) // Laugh 2 - #3636SpriteFrame(-28, -16, 44, 16, 1, 47) // Hit - #4637SpriteFrame(-28, -16, 44, 16, 62, 47) // Destroyed - #5638SpriteFrame(-40, -40, 80, 72, 232, 112) // Eggmobile - #6639SpriteFrame(-3, -18, 11, 8, 45, 88) // Panic Sweat - #7640end if641end event642643644// ========================645// Editor Events646// ========================647648event RSDKDraw649DrawSprite(1)650DrawSprite(0)651end event652653654event RSDKLoad655CheckCurrentStageFolder("Zone04")656if checkResult == true657LoadSpriteSheet("CNZ/Objects.gif")658SpriteFrame(-28, -16, 44, 16, 76, 140) // Idle 1659SpriteFrame(-40, -40, 80, 72, 175, 183) // Eggmobile660else661LoadSpriteSheet("MBZ/Objects.gif")662SpriteFrame(-28, -16, 44, 16, 1, 5) // Idle 1663SpriteFrame(-40, -40, 80, 72, 232, 112) // Eggmobile664end if665666SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")667end event668669670