Path: blob/master/Sonic 2/Scripts/CPZ/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 CPZEggman 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.originPos.x14private alias object.value1 : object.originPos.y15private alias object.value2 : object.oscillationAngle16private alias object.value4 : object.timer17private alias object.value5 : object.flameAnim18private alias object.value6 : object.flameAnimTimer19private alias object.value7 : object.health20private alias object.value8 : object.invincibilityTimer21private alias object.value9 : object.exploding22private alias object.value10 : object.nonStopBopCount2324// Eggman States25private alias 0 : CPZEGGMAN_AWAITPLAYER26private alias 1 : CPZEGGMAN_BOSSFIGHT27private alias 2 : CPZEGGMAN_EXPLODE28private alias 3 : CPZEGGMAN_DEFEATFALL29private alias 4 : CPZEGGMAN_DEFEATRISE30private alias 5 : CPZEGGMAN_FLEE31private alias 6 : CPZEGGMAN_ESCAPE3233// Eggman Animations34private alias 0 : CPZEGGANI_INVISIBLE35private alias 1 : CPZEGGANI_IDLE36private alias 2 : CPZEGGANI_LAUGH37private alias 3 : CPZEGGANI_HIT38private alias 4 : CPZEGGANI_DEFEATED39private alias 5 : CPZEGGANI_TOASTED40private alias 6 : CPZEGGANI_PANIC4142// Flame Animations43private alias 0 : FLAME_INACTIVE44private alias 1 : FLAME_ACTIVE45private alias 2 : FLAME_EXPLODE4647// Dropper Aliases48private alias object.value4 : chemicalDropper.boundsL49private alias object.value5 : chemicalDropper.boundsR5051// Dropper States52private alias 4 : CHEMICALDROPPER_DESTROYED5354// Music Events55private alias 26 : SLOT_MUSICEVENT_BOSS5657private alias 0 : MUSICEVENT_FADETOBOSS58private alias 1 : MUSICEVENT_FADETOSTAGE5960// Player Aliases61private alias object.xpos : player.xpos62private alias object.xvel : player.xvel63private alias object.speed : player.speed64private alias object.animation : player.animation65private alias object.gravity : player.gravity66private alias object.collisionRight : player.collisionRight67private alias object.value40 : player.hitboxLeft68private alias object.value38 : player.hitboxTop69private alias object.value41 : player.hitboxRight70private alias object.value39 : player.hitboxBottom7172// Achievement Aliases73private alias 5 : ACHIEVEMENT_BOBNONSTOP747576// ========================77// Function Declarations78// ========================7980reserve function CPZEggman_Oscillate818283// ========================84// Tables85// ========================8687private table CPZEggman_flameAnimFrameTable887, 8, 8, 7, 7, 1689end table909192// ========================93// Function Definitions94// ========================9596private function CPZEggman_Oscillate97object.ypos = object.originPos.y98Sin256(temp0, object.oscillationAngle)99temp0 <<= 10100object.ypos += temp0101object.oscillationAngle += 2102object.oscillationAngle &= 255103end function104105106// ========================107// Events108// ========================109110event ObjectUpdate111switch object.state112case CPZEGGMAN_AWAITPLAYER113temp0 = object.ixpos114temp0 -= screen.xcenter115stage.newXBoundary1 = temp0116temp0 = object.ixpos117temp0 += screen.xcenter118stage.newXBoundary2 = temp0119if player[0].xpos > object.xpos120object.animation = CPZEGGANI_IDLE121ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOBOSS, 0, 0)122object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE123object.originPos.y = object.ypos124object[+1].type = TypeName[Chemical Dropper]125chemicalDropper[+1].boundsL = object.xpos126chemicalDropper[+1].boundsL -= 0x700000127chemicalDropper[+1].boundsR = object.xpos128chemicalDropper[+1].boundsR += 0x700000129temp0 = screen.xcenter130temp0 += 256131temp0 <<= 16132object.xpos += temp0133object[+1].xpos = object.xpos134object[+1].ypos = object.ypos135object[+1].originPos.x = object.xpos136object[+1].originPos.y = object.ypos137object[+1].priority = PRIORITY_ACTIVE138object.flameAnim = FLAME_ACTIVE139140#platform: USE_STANDALONE141object.health = 8142#endplatform143#platform: USE_ORIGINS144if game.bossOneLife == false145object.health = 8146else147object.health = 1148end if149#endplatform150151object.priority = PRIORITY_ACTIVE152object.state++153end if154break155156case CPZEGGMAN_BOSSFIGHT157break158159case CPZEGGMAN_EXPLODE160object.timer++161if object.timer == 180162object.timer = 0163object.animation = CPZEGGANI_TOASTED164object.exploding = false165object.state++166ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOSTAGE, 0, 0)167object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE168temp0 = tileLayer[0].xsize169temp0 <<= 7170stage.newXBoundary2 = temp0171end if172break173174case CPZEGGMAN_DEFEATFALL175object.ypos += object.yvel176object.yvel += 0x1800177object.timer++178if object.timer == 38179object.yvel = 0180object.timer = 0181object.animationTimer = 0182object.state++183end if184break185186case CPZEGGMAN_DEFEATRISE187if object.timer < 48188object.ypos += object.yvel189object.yvel -= 0x800190object.timer++191else192object.timer = 0193object.yvel = 0194object.originPos.y = object.ypos195object.state++196end if197break198199case CPZEGGMAN_FLEE200object.ypos = object.originPos.y201CallFunction(CPZEggman_Oscillate)202203if object.timer < 8204object.timer++205else206object.timer = 0207object.animation = CPZEGGANI_PANIC208object.animationTimer = 0209object.flameAnim = FLAME_EXPLODE210object.flameAnimTimer = 0211object.direction = FLIP_X212object.priority = PRIORITY_ACTIVE213temp0 = tileLayer[0].xsize214temp0 <<= 7215stage.newXBoundary2 = temp0216object.state++217end if218break219220case CPZEGGMAN_ESCAPE221object.xpos += 0x40000222object.originPos.y -= 0x4000223CallFunction(CPZEggman_Oscillate)224if object.outOfBounds == true225object.type = TypeName[Blank Object]226object.priority = PRIORITY_BOUNDS227end if228break229230end switch231232// If P1's touched the floor, then reset the Bop Non-Stop count for the Achievement233if player[0].gravity == GRAVITY_GROUND234object.nonStopBopCount = 0235end if236237if object.health != 0238if object.invincibilityTimer > 0239object.invincibilityTimer--240GetBit(temp0, object.invincibilityTimer, 0)241if temp0 == true242SetPaletteEntry(0, 192, 0xE0E0E0)243else244SetPaletteEntry(0, 192, 0x000000)245end if246end if247248foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)249if object.invincibilityTimer == 0250CheckEqual(player[currentPlayer].animation, ANI_HURT)251temp0 = checkResult252CheckEqual(player[currentPlayer].animation, ANI_DYING)253temp0 |= checkResult254CheckEqual(player[currentPlayer].animation, ANI_DROWNING)255temp0 |= checkResult256if temp0 != false257if object.animation != CPZEGGANI_LAUGH258object.animation = CPZEGGANI_LAUGH259object.animationTimer = 0260end if261end if262263BoxCollisionTest(C_TOUCH, object.entityPos, -24, -24, 24, 22, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)264if checkResult == true265CallFunction(Player_CheckHit)266if checkResult == true267object.health--268if object.health == 0269#platform: USE_ORIGINS270CallNativeFunction2(NotifyCallback, NOTIFY_KILL_BOSS, 0)271CallNativeFunction2(NotifyCallback, NOTIFY_BOSS_END, 1)272#endplatform273274player.score += 1000275object.animation = CPZEGGANI_DEFEATED276object.animationTimer = 0277object.flameAnim = FLAME_INACTIVE278object.exploding = true279object.originPos.y = object.ypos280object.oscillationAngle = object[+1].oscillationAngle281object.state++282object[+1].state = CHEMICALDROPPER_DESTROYED283284if object.nonStopBopCount >= 7285if stage.debugMode == false286// Grant the "Bob Non-stop" Achievement287CallNativeFunction2(SetAchievement, ACHIEVEMENT_BOBNONSTOP, 100)288end if289end if290else291object.animation = CPZEGGANI_HIT292object.animationTimer = 0293object.invincibilityTimer = 32294PlaySfx(SfxName[Boss Hit], false)295if currentPlayer == 0296if player[0].gravity == GRAVITY_AIR297object.nonStopBopCount++298end if299end if300end if301end if302end if303end if304next305end if306307// Enforce the R Boundary308if object.state != CPZEGGMAN_ESCAPE309foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)310temp0 = player[currentPlayer].collisionRight311temp0 <<= 16312temp0 += player[currentPlayer].xpos313temp1 = stage.curXBoundary2314temp1 <<= 16315if temp0 > temp1316player[currentPlayer].xvel = 0317player[currentPlayer].speed = 0318player[currentPlayer].xpos = temp1319temp0 = player[currentPlayer].collisionRight320temp0 <<= 16321player[currentPlayer].xpos -= temp0322end if323next324end if325326if object.exploding == true327temp0 = oscillation328temp0 &= 7329if temp0 == 0330Rand(temp0, 48)331temp0 -= 24332temp0 <<= 16333temp0 += object.xpos334Rand(temp1, 48)335temp1 -= 24336temp1 <<= 16337temp1 += object.ypos338CreateTempObject(TypeName[Explosion], 0, temp0, temp1)339object[tempObjectPos].drawOrder = 5340PlaySfx(SfxName[Explosion], false)341end if342end if343end event344345346event ObjectDraw347if object.animation != CPZEGGANI_INVISIBLE348DrawSpriteFX(6, FX_FLIP, object.xpos, object.ypos)349end if350351switch object.animation352case CPZEGGANI_IDLE353temp0 = object.animationTimer354temp0 >>= 3355object.animationTimer++356object.animationTimer &= 15357DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)358break359360case CPZEGGANI_LAUGH361temp0 = object.animationTimer362temp0 &= 15363temp0 >>= 3364temp0 += 2365object.animationTimer++366if object.animationTimer == 50367object.animationTimer = 0368if player[0].animation != ANI_DYING369object.animation = CPZEGGANI_IDLE370end if371end if372DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)373break374375case CPZEGGANI_HIT376temp0 = object.animationTimer377temp0 &= 1378temp0 += 2379object.animationTimer++380if object.animationTimer == 50381object.animationTimer = 0382object.animation = CPZEGGANI_IDLE383end if384DrawSpriteFX(4, FX_FLIP, object.xpos, object.ypos)385break386387case CPZEGGANI_DEFEATED388temp0 = object.animationTimer389temp0 >>= 5390temp0 += 4391temp0 %= 5392object.animationTimer++393object.animationTimer &= 63394DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)395break396397case CPZEGGANI_TOASTED398DrawSpriteFX(5, FX_FLIP, object.xpos, object.ypos)399break400401case CPZEGGANI_PANIC402temp0 = object.animationTimer403temp0 >>= 3404object.animationTimer++405object.animationTimer &= 15406DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)407408temp0 = object.animationTimer409temp0 >>= 2410temp0 &= 1411if temp0 == 1412DrawSpriteFX(15, FX_FLIP, object.xpos, object.ypos)413end if414break415416end switch417418switch object.flameAnim419default420case FLAME_INACTIVE421break422423case FLAME_ACTIVE424GetTableValue(temp0, object.flameAnimTimer, CPZEggman_flameAnimFrameTable)425object.flameAnimTimer++426if object.flameAnimTimer == 6427object.flameAnimTimer = 0428end if429DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)430break431432case FLAME_EXPLODE433temp0 = object.flameAnimTimer434temp0 /= 3435temp0 += 9436object.flameAnimTimer++437if object.flameAnimTimer >= 18438object.flameAnimTimer = 0439temp0 = 7440object.flameAnim = FLAME_ACTIVE441end if442DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)443break444445end switch446end event447448449event ObjectStartup450CheckCurrentStageFolder("Zone02")451if checkResult == true452LoadSpriteSheet("Global/EggMobile.gif")453454// 0->5 - Eggman Frames455SpriteFrame(-28, -28, 60, 20, 5, 1)456SpriteFrame(-28, -28, 60, 20, 66, 1)457SpriteFrame(-28, -28, 60, 20, 5, 22)458SpriteFrame(-28, -28, 60, 20, 66, 22)459SpriteFrame(-28, -28, 60, 20, 5, 43)460SpriteFrame(-28, -28, 60, 20, 66, 43)461462// 6 - Eggmobile Body Frame463SpriteFrame(-32, -8, 64, 29, 1, 64)464465// 7->9 - Thruster Frames466SpriteFrame(31, 4, 12, 8, 66, 65)467SpriteFrame(30, 2, 14, 12, 66, 74)468SpriteFrame(31, -2, 22, 14, 66, 87)469470// 10->14 - Explosion Flame Frames471SpriteFrame(31, -9, 32, 26, 94, 64)472SpriteFrame(31, -2, 22, 14, 66, 87)473SpriteFrame(31, -9, 32, 26, 94, 64)474SpriteFrame(31, 4, 12, 8, 66, 65)475SpriteFrame(30, 2, 14, 12, 66, 74)476477// 15 - Sweat Frame478SpriteFrame(-3, -28, 11, 8, 79, 65)479480// 16 - Blank Frame481SpriteFrame(0, 0, 0, 0, 7, 2)482483if options.vsMode == true484foreach (TypeName[Eggman], arrayPos0, ALL_ENTITIES)485object[arrayPos0].type = TypeName[Blank Object]486next487end if488else489LoadSpriteSheet("MBZ/Objects.gif")490491// 0->5 - Eggman Frames492SpriteFrame(-28, -28, 60, 20, 1, 1)493SpriteFrame(-28, -28, 60, 20, 62, 1)494SpriteFrame(-28, -28, 60, 20, 1, 22)495SpriteFrame(-28, -28, 60, 20, 62, 22)496SpriteFrame(-28, -28, 60, 20, 1, 43)497SpriteFrame(-28, -28, 60, 20, 62, 43)498499// 6 - Eggmobile Body Frame500SpriteFrame(-32, -8, 64, 29, 415, 170)501502// 7->9 - Thruster Frames503SpriteFrame(31, 4, 12, 8, 57, 90)504SpriteFrame(30, 2, 14, 12, 57, 99)505SpriteFrame(31, -2, 22, 14, 34, 97)506507// 10->14 - Explosion Flame Frames508SpriteFrame(31, -9, 32, 26, 72, 86)509SpriteFrame(31, -2, 22, 14, 34, 97)510SpriteFrame(31, -9, 32, 26, 72, 86)511SpriteFrame(31, 4, 12, 8, 57, 90)512SpriteFrame(30, 2, 14, 12, 57, 99)513514// 15 - Sweat Frame515SpriteFrame(-3, -28, 11, 8, 45, 88)516517// 16 - Blank Frame518SpriteFrame(0, 0, 0, 0, 7, 2)519end if520end event521522523// ========================524// Editor Events525// ========================526527event RSDKDraw528DrawSprite(1)529DrawSprite(0)530531if editor.showGizmos == true532editor.drawingOverlay = true533534// Draw lines connecting the whole network of boss objects535DrawArrow(object.xpos, object.ypos, object[+1].xpos, object[+1].ypos, 0, 255, 0) // Chemical Dropper536537// Draw arena bounds538temp0 = 212; temp1 = 113; temp2 = 212; temp3 = 128;539CallFunction(EditorHelpers_DrawHitbox)540541// Draw Robotnik's movement bounds542temp0 = object.xpos543temp0 -= 0x700000544545temp1 = object.xpos546temp1 += 0x700000547548DrawLine(temp0, object.ypos, temp1, object.ypos, 0, 255, 0)549550editor.drawingOverlay = false551end if552end event553554555event RSDKLoad556CheckCurrentStageFolder("Zone02")557if checkResult == true558LoadSpriteSheet("Global/EggMobile.gif")559560// 0 - Eggman Frame561SpriteFrame(-28, -28, 60, 20, 5, 1)562563// 1 - Eggmobile Body Frame564SpriteFrame(-32, -8, 64, 29, 1, 64)565else566LoadSpriteSheet("MBZ/Objects.gif")567568// 0 - Eggman Frame569SpriteFrame(-28, -28, 60, 20, 1, 1)570571// 1 - Eggmobile Body Frame572SpriteFrame(-32, -8, 64, 29, 415, 170)573end if574575SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")576end event577578579