Path: blob/master/Sonic 2/Scripts/OOZ/Eggman.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Eggman Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// Using OOZEggman 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.oscillationAngle16private alias object.value3 : object.health17private alias object.value4 : object.invincibilityTimer18private alias object.value5 : object.exploding19private alias object.value6 : object.emergeTargetPos20private alias object.value7 : object.highestEmergePos21private alias object.value8 : object.submergeTargetPos22private alias object.value9 : object.spawnHarpoon2324// Eggman States25private alias 0 : OOZEGGMAN_AWAITPLAYER26private alias 1 : OOZEGGMAN_STARTBOSS27private alias 2 : OOZEGGMAN_EMERGE28private alias 3 : OOZEGGMAN_LOOKAROUND29private alias 4 : OOZEGGMAN_SUBMERGE30private alias 5 : OOZEGGMAN_HARPOONATTACK31private alias 6 : OOZEGGMAN_CANNONATTACK32private alias 7 : OOZEGGMAN_EXPLODE33private alias 8 : OOZEGGMAN_DEFEATED34private alias 9 : OOZEGGMAN_ESCAPE3536// Eggman Animations37private alias 0 : OOZEGGANI_INVISIBLE38private alias 1 : OOZEGGANI_IDLE39private alias 2 : OOZEGGANI_LAUGH40private alias 3 : OOZEGGANI_HIT41private alias 4 : OOZEGGANI_DEFEATED42private alias 5 : OOZEGGANI_TOASTED43private alias 6 : OOZEGGANI_PANIC4445// Player Aliases46private alias object.xpos : player.xpos47private alias object.xvel : player.xvel48private alias object.speed : player.speed49private alias object.animation : player.animation50private alias object.collisionRight : player.collisionRight5152private alias object.value40 : player.hitboxLeft53private alias object.value38 : player.hitboxTop54private alias object.value41 : player.hitboxRight55private alias object.value39 : player.hitboxBottom5657// Music Events58private alias 26 : SLOT_MUSICEVENT_BOSS5960private alias 0 : MUSICEVENT_FADETOBOSS61private alias 1 : MUSICEVENT_FADETOSTAGE626364// ========================65// Function Declarations66// ========================6768reserve function OOZEggman_Oscillate697071// ========================72// Function Definitions73// ========================7475private function OOZEggman_Oscillate76Sin256(object.ypos, object.oscillationAngle)77object.ypos <<= 978object.ypos += object.originPos.y79object.oscillationAngle += 480object.oscillationAngle &= 0xFF81end function828384// ========================85// Events86// ========================8788event ObjectUpdate89switch object.state90case OOZEGGMAN_AWAITPLAYER91if player[0].xpos > object.xpos92temp0 = screen.xcenter93FlipSign(temp0)94if temp0 > -19295temp0 = -19296end if97temp0 += object.ixpos98stage.newXBoundary1 = temp099100temp0 = screen.xcenter101if temp0 < 192102temp0 = 192103end if104temp0 += object.ixpos105stage.newXBoundary2 = temp0106107temp0 = stage.newYBoundary2108temp0 -= screen.ysize109stage.newYBoundary1 = temp0110111object.emergeTargetPos = object.ypos112object.emergeTargetPos -= 0x400000113object.highestEmergePos = object.ypos114object.highestEmergePos -= 0x440000115object.submergeTargetPos = object.ypos116object.animation = OOZEGGANI_IDLE117ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOBOSS, 0, 0)118object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE119120#platform: USE_STANDALONE121object.health = 8122#endplatform123#platform: USE_ORIGINS124if game.bossOneLife == false125object.health = 8126else127object.health = 1128end if129#endplatform130131object.priority = PRIORITY_ACTIVE132object.state = OOZEGGMAN_STARTBOSS133end if134break135136case OOZEGGMAN_STARTBOSS137object.timer++138if object.timer == 60139object.timer = 0140object.yvel = -0x8000141if player[0].xpos > object.xpos142object.direction = FLIP_NONE143else144object.direction = FLIP_X145end if146object.state = OOZEGGMAN_EMERGE147end if148break149150case OOZEGGMAN_EMERGE151object.ypos += object.yvel152if object.ypos <= object.emergeTargetPos153object.ypos = object.emergeTargetPos154object.originPos.y = object.ypos155object.oscillationAngle = 0156object.state = OOZEGGMAN_LOOKAROUND157end if158159if object.animation == OOZEGGANI_IDLE160object.animationTimer = 0161end if162break163164case OOZEGGMAN_LOOKAROUND165CallFunction(OOZEggman_Oscillate)166167// If we got hit, get outta here!168object.timer++169if object.invincibilityTimer > 0170object.timer = 168171end if172173if object.timer == 168174object.timer = 0175object.yvel = -0x4000176object.state = OOZEGGMAN_SUBMERGE177end if178break179180// This state also manages the harpoon/cannon181case OOZEGGMAN_SUBMERGE182object.ypos += object.yvel183if object.ypos < object.highestEmergePos184object.ypos = object.highestEmergePos185object.yvel = 0x8000186end if187188if object.ypos >= object.submergeTargetPos189object.ypos = object.submergeTargetPos190object.yvel = -0x8000191if player[0].xpos > object.xpos192object.direction = FLIP_NONE193else194object.direction = FLIP_X195end if196197if object.spawnHarpoon == true198temp0 = object.entityPos199temp0++200ResetObjectEntity(temp0, TypeName[Eggman Harpoon], object.direction, object.xpos, object.ypos)201object[+1].ypos -= 0x300000202object[+1].priority = PRIORITY_ACTIVE203object.state = OOZEGGMAN_HARPOONATTACK204else205temp0 = object.entityPos206temp0++207ResetObjectEntity(temp0, TypeName[Eggman Cannon], object.direction, object.xpos, object.ypos)208object[+1].ypos -= 0x200000209object[+1].priority = PRIORITY_ACTIVE210object.state = OOZEGGMAN_CANNONATTACK211end if212213object.visible = false214object.spawnHarpoon = false215end if216217if object.animation == OOZEGGANI_IDLE218object.animationTimer = 0219end if220break221222// Wait for the harpoon attack to be over, then do the cannon attack223case OOZEGGMAN_HARPOONATTACK224if object[+1].type == TypeName[Blank Object]225temp0 = object.entityPos226temp0++227ResetObjectEntity(temp0, TypeName[Eggman Cannon], object.direction, object.xpos, object.ypos)228object[+1].ypos -= 0x200000229object[+1].priority = PRIORITY_ACTIVE230object.state = OOZEGGMAN_CANNONATTACK231end if232break233234// Wait for the cannon attack to be over, then emerge235case OOZEGGMAN_CANNONATTACK236if object[+1].type == TypeName[Blank Object]237object.visible = true238object.state = OOZEGGMAN_EMERGE239end if240break241242case OOZEGGMAN_EXPLODE243object.timer++244if object.timer == 180245object.timer = 0246object.animation = OOZEGGANI_TOASTED247object.exploding = false248object.state = OOZEGGMAN_DEFEATED249ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOSTAGE, 0, 0)250object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE251temp0 = tileLayer[0].xsize252temp0 <<= 7253stage.newXBoundary2 = temp0254end if255break256257case OOZEGGMAN_DEFEATED258object.timer++259if object.timer == 30260object.yvel = 0261object.timer = 0262object.state = OOZEGGMAN_ESCAPE263end if264break265266case OOZEGGMAN_ESCAPE267if object.yvel < 0x10000268object.yvel += 0x400269end if270271object.ypos += object.yvel272if object.ypos > object.submergeTargetPos273ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, 0, 0)274end if275break276277end switch278279if object.health != 0280if object.invincibilityTimer > 0281object.invincibilityTimer--282GetBit(temp0, object.invincibilityTimer, 0)283if temp0 == true284SetPaletteEntry(0, 192, 0xE0E0E0)285else286SetPaletteEntry(0, 192, 0x000000)287end if288end if289290if object.visible == true291foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)292if object.invincibilityTimer < 32293CheckEqual(player[currentPlayer].animation, ANI_HURT)294temp0 = checkResult295CheckEqual(player[currentPlayer].animation, ANI_DYING)296temp0 |= checkResult297CheckEqual(player[currentPlayer].animation, ANI_DROWNING)298temp0 |= checkResult299if temp0 != 0300if object.animation != OOZEGGANI_LAUGH301object.animation = OOZEGGANI_LAUGH302object.animationTimer = 0303end if304end if305306BoxCollisionTest(C_TOUCH, object.entityPos, -24, -10, 24, 24, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)307if checkResult == true308CallFunction(Player_CheckHit)309if checkResult == true310object.health--311if object.health == 0312#platform: USE_ORIGINS313CallNativeFunction2(NotifyCallback, NOTIFY_KILL_BOSS, 0)314CallNativeFunction2(NotifyCallback, NOTIFY_BOSS_END, 1)315#endplatform316317player.score += 1000318object.timer = 0319object.animation = OOZEGGANI_DEFEATED320object.animationTimer = 0321object.exploding = true322object.originPos.y = object.ypos323object.state = OOZEGGMAN_EXPLODE324SetPaletteEntry(0, 192, 0x000000)325else326object.animation = OOZEGGANI_HIT327object.animationTimer = 0328object.invincibilityTimer = 64329object.spawnHarpoon = true330PlaySfx(SfxName[Boss Hit], false)331end if332end if333end if334end if335next336end if337end if338339// Handle Right Stage Boundary340if object.state != OOZEGGMAN_ESCAPE341foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)342temp0 = player[currentPlayer].collisionRight343temp0 <<= 16344temp0 += player[currentPlayer].xpos345temp1 = stage.curXBoundary2346temp1 <<= 16347if temp0 > temp1348player[currentPlayer].xvel = 0349player[currentPlayer].speed = 0350player[currentPlayer].xpos = temp1351temp0 = player[currentPlayer].collisionRight352temp0 <<= 16353player[currentPlayer].xpos -= temp0354end if355next356end if357358// Exploding stuff359if object.exploding == true360temp0 = oscillation361temp0 &= 7362if temp0 == 0363Rand(temp0, 48)364temp0 -= 24365temp0 <<= 16366temp0 += object.xpos367368Rand(temp1, 48)369temp1 -= 24370temp1 <<= 16371temp1 += object.ypos372373CreateTempObject(TypeName[Explosion], 0, temp0, temp1)374object[tempObjectPos].drawOrder = 5375PlaySfx(SfxName[Explosion], false)376end if377end if378end event379380381event ObjectDraw382// Submarine383DrawSpriteFX(6, FX_FLIP, object.xpos, object.ypos)384385switch object.animation386default387case OOZEGGANI_INVISIBLE388break389390case OOZEGGANI_IDLE391temp0 = object.animationTimer392temp0 /= 40393object.animationTimer++394object.animationTimer %= 80395DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)396break397398case OOZEGGANI_LAUGH399temp0 = object.animationTimer400temp0 &= 15401temp0 >>= 3402temp0 += 2403object.animationTimer++404if object.animationTimer == 50405object.animationTimer = 0406if player[0].animation != ANI_DYING407object.animation = OOZEGGANI_IDLE408end if409end if410DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)411break412413case OOZEGGANI_HIT414temp0 = object.animationTimer415temp0 &= 1416temp0 += 2417object.animationTimer++418if object.animationTimer == 50419object.animationTimer = 0420object.animation = OOZEGGANI_IDLE421end if422DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)423break424425case OOZEGGANI_DEFEATED426temp0 = object.animationTimer427temp0 >>= 5428temp0 += 4429temp0 %= 5430object.animationTimer++431object.animationTimer &= 63432DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)433break434435case OOZEGGANI_TOASTED436DrawSpriteFX(5, FX_FLIP, object.xpos, object.ypos)437break438439case OOZEGGANI_PANIC440DrawSpriteFX(5, FX_FLIP, object.xpos, object.ypos)441break442443end switch444end event445446447event ObjectStartup448SetPaletteEntry(0, 192, 0x000000) // This is already reset in [OOZSetup]... does it really need to be done again here?449CheckCurrentStageFolder("Zone07")450if checkResult == true451LoadSpriteSheet("OOZ/Objects.gif")452SpriteFrame(-12, -12, 24, 12, 462, 118) // Eggman (Idle) - #0453SpriteFrame(-12, -12, 24, 12, 487, 118) // Eggman (Looking) - #1454SpriteFrame(-12, -12, 24, 12, 462, 131) // Eggman (Laugh 1) - #2455SpriteFrame(-12, -12, 24, 12, 487, 131) // Eggman (Laugh 2) - #3456SpriteFrame(-12, -12, 24, 12, 462, 144) // Eggman (Hit) - #4457SpriteFrame(-12, -12, 24, 12, 487, 144) // Eggman (Defeated) - #5458SpriteFrame(-48, -32, 96, 64, 365, 125) // Submarine - #6459460if options.vsMode == true461foreach (TypeName[Eggman], arrayPos0, ALL_ENTITIES)462object[arrayPos0].type = TypeName[Blank Object]463next464end if465else466LoadSpriteSheet("MBZ/Objects.gif")467SpriteFrame(-12, -12, 24, 12, 413, 91) // Eggman (Idle) - #0468SpriteFrame(-12, -12, 24, 12, 438, 91) // Eggman (Looking) - #1469SpriteFrame(-12, -12, 24, 12, 413, 104) // Eggman (Laugh 1) - #2470SpriteFrame(-12, -12, 24, 12, 438, 104) // Eggman (Laugh 2) - #3471SpriteFrame(-12, -12, 24, 12, 413, 117) // Eggman (Hit) - #4472SpriteFrame(-12, -12, 24, 12, 438, 117) // Eggman (Defeated) - #5473SpriteFrame(-48, -32, 96, 64, 313, 112) // Submarine - #6474end if475end event476477478// ========================479// Editor Events480// ========================481482event RSDKDraw483DrawSprite(1) // Sub484DrawSprite(0) // Eggman485end event486487488event RSDKLoad489CheckCurrentStageFolder("Zone07")490if checkResult == true491LoadSpriteSheet("OOZ/Objects.gif")492SpriteFrame(-12, -12, 24, 12, 462, 118) // Eggman (Idle) - #0493SpriteFrame(-48, -32, 96, 64, 365, 125) // Submarine - #1494else495LoadSpriteSheet("MBZ/Objects.gif")496SpriteFrame(-12, -12, 24, 12, 413, 91) // Eggman (Idle) - #0497SpriteFrame(-48, -32, 96, 64, 313, 112) // Submarine - #1498end if499500SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")501end event502503504