Path: blob/master/Sonic 1/Scripts/MZ/Eggman.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Eggman Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// Using MZEggman 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.health15private alias object.value2 : object.invincibilityTimer16private alias object.value3 : object.flameAnim17private alias object.value4 : object.flameAnimTimer18private alias object.value5 : object.boundsL19private alias object.value6 : object.boundsR20private alias object.value7 : object.divePos.y21private alias object.value8 : object.originPos.y22private alias object.value9 : object.fireballDropDelay23private alias object.value10 : object.dontRandomizeNextDrop24private alias object.value11 : object.nextState25private alias object.value12 : object.hitDelay2627// Eggman States28private alias 0 : MZEGGMAN_AWAITPLAYER29private alias 1 : MZEGGMAN_ENTEREGGMAN30private alias 2 : MZEGGMAN_TAUNT31private alias 3 : MZEGGMAN_MOVE_L32private alias 4 : MZEGGMAN_DROPFIREBALL_L33private alias 5 : MZEGGMAN_DROPPEDFIREBALL_L34private alias 6 : MZEGGMAN_MOVE_R35private alias 7 : MZEGGMAN_DROPFIREBALL_R36private alias 8 : MZEGGMAN_DROPPEDFIREBALL_R37private alias 9 : MZEGGMAN_EXPLODE38private alias 10 : MZEGGMAN_DEFEATFALL39private alias 11 : MZEGGMAN_DEFEATRISE40private alias 12 : MZEGGMAN_FLEE41private alias 13 : MZEGGMAN_ESCAPE42private alias 14 : MZEGGMAN_HITFREEZE4344// Eggman Animations45private alias 0 : MZEGGANI_INVISIBLE46private alias 1 : MZEGGANI_IDLE47private alias 2 : MZEGGANI_LAUGH48private alias 3 : MZEGGANI_LAUGH_LOOP49private alias 4 : MZEGGANI_HIT50private alias 5 : MZEGGANI_DEFEATED51private alias 6 : MZEGGANI_TOASTED52private alias 7 : MZEGGANI_PANIC5354// Flame Animations55private alias 0 : FLAME_INACTIVE56private alias 1 : FLAME_ACTIVE57private alias 2 : FLAME_EXPLODE5859// Marker aliases60private alias object.xpos : marker.xpos61private alias object.ypos : marker.ypos62private alias object.ixpos : marker.ixpos63private alias object.iypos : marker.iypos6465// Fireball aliases66private alias object.value2 : fireball.fireballDir67private alias object.value3 : fireball.finalY68private alias 1 : FIREBALL_MOVE_GRAVITY6970// Player Aliases71private alias object.xpos : player.xpos72private alias object.xvel : player.xvel73private alias object.speed : player.speed74private alias object.animation : player.animation75private alias object.collisionRight : player.collisionRight76private alias object.value40 : player.hitboxLeft77private alias object.value38 : player.hitboxTop78private alias object.value41 : player.hitboxRight79private alias object.value39 : player.hitboxBottom80private alias object.value18 : player.sortedDrawOrder8182// Music Events83private alias 26 : SLOT_MUSICEVENT_BOSS8485private alias 0 : MUSICEVENT_FADETOBOSS86private alias 1 : MUSICEVENT_FADETOSTAGE87private alias 2 : MUSICEVENT_TRANSITION888990// ========================91// Function Declarations92// ========================9394reserve function MZEggman_Oscillate95reserve function MZEggman_HandleFireballErupt969798// ========================99// Aliases100// ========================101102private function MZEggman_Oscillate103Sin256(object.ypos, object.angle)104object.ypos <<= 10105object.ypos += object.originPos.y106object.angle += 2107object.angle &= 0xFF108end function109110111private function MZEggman_HandleFireballErupt112if object.fireballDropDelay > 0113object.fireballDropDelay--114else115Rand(temp0, 112)116temp0 -= 56117temp0 <<= 16118temp0 += marker[+1].xpos119temp1 = marker[+1].ypos120temp1 += 0x200000121CreateTempObject(TypeName[Fireball], 0, temp0, temp1)122object[tempObjectPos].state = FIREBALL_MOVE_GRAVITY123object[tempObjectPos].xvel = 0124object[tempObjectPos].yvel = -0x40000125fireball[tempObjectPos].finalY = temp1126fireball[tempObjectPos].fireballDir = 2127PlaySfx(SfxName[Small Fireball], false)128129if object.dontRandomizeNextDrop == false130Rand(temp0, 3)131if temp0 == 2132object.fireballDropDelay = 70133object.dontRandomizeNextDrop = true134else135object.fireballDropDelay = 140136end if137else138object.dontRandomizeNextDrop = false139object.fireballDropDelay = 140140end if141end if142end function143144145// ========================146// Events147// ========================148149event ObjectUpdate150switch object.state151case MZEGGMAN_AWAITPLAYER152temp0 = marker[+1].ixpos153temp0 += screen.xcenter154stage.newXBoundary2 = temp0155156temp0 -= screen.xsize157stage.newXBoundary1 = temp0158159temp0 = stage.curYBoundary2160temp0 -= screen.ysize161stage.newYBoundary1 = temp0162163if player[0].xpos > marker[+1].xpos164object.divePos.y = marker[+1].ypos165object.divePos.y -= 0x900000166object.originPos.y = marker[+1].ypos167object.originPos.y -= 0x900000168169temp0 = 0x700000170temp0 *= screen.xcenter171temp0 /= 160172object.speed = 0x20000173object.speed *= screen.xcenter174object.speed /= 160175176object.boundsL = marker[+1].xpos177object.boundsL -= temp0178object.boundsR = marker[+1].xpos179object.boundsR += temp0180181object.xvel = -0x10000182object.flameAnim = FLAME_ACTIVE183object.fireballDropDelay = 120184ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOBOSS, 0, 0)185object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE186object.drawOrder = 4187player[0].sortedDrawOrder = 5188if object[1].type == TypeName[Player 2 Object]189player[1].sortedDrawOrder = 5190end if191object.state++192end if193break194195case MZEGGMAN_ENTEREGGMAN196object.xpos += object.xvel197if object.xpos <= object.boundsR198object.xpos = object.boundsR199object.flameAnim = FLAME_INACTIVE200object.state++201end if202CallFunction(MZEggman_Oscillate)203break204205case MZEGGMAN_TAUNT206CallFunction(MZEggman_Oscillate)207208object.timer++209if object.timer == 16210object.timer = 0211object.xvel = object.speed212FlipSign(object.xvel)213object.yvel = 0x10000214object.flameAnim = FLAME_ACTIVE215object.state++216end if217break218219case MZEGGMAN_MOVE_L220object.yvel -= 0x400221object.xpos += object.xvel222object.ypos += object.yvel223224if object.xpos <= object.boundsL225object.xpos = object.boundsL226object.flameAnim = FLAME_INACTIVE227object.state++228end if229CallFunction(MZEggman_HandleFireballErupt)230break231232case MZEGGMAN_DROPFIREBALL_L233object.yvel -= 0x400234object.ypos += object.yvel235236if object.ypos <= object.divePos.y237object.ypos = object.divePos.y238object.direction = FACING_LEFT239object.animation = MZEGGANI_LAUGH_LOOP240object.animationTimer = 0241CreateTempObject(TypeName[Boss Fireball], 0, object.xpos, object.ypos)242object[tempObjectPos].ypos += 0x140000243object.state++244end if245CallFunction(MZEggman_HandleFireballErupt)246break247248case MZEGGMAN_DROPPEDFIREBALL_L249object.timer++250if object.timer == 80251object.timer = 0252object.xvel = object.speed253object.yvel = 0x10000254object.animation = MZEGGANI_IDLE255object.flameAnim = FLAME_ACTIVE256object.state++257end if258259CallFunction(MZEggman_HandleFireballErupt)260break261262case MZEGGMAN_MOVE_R263object.yvel -= 0x400264object.xpos += object.xvel265object.ypos += object.yvel266267if object.xpos >= object.boundsR268object.xpos = object.boundsR269object.flameAnim = FLAME_INACTIVE270object.state++271end if272CallFunction(MZEggman_HandleFireballErupt)273break274275case MZEGGMAN_DROPFIREBALL_R276object.yvel -= 0x400277object.ypos += object.yvel278279if object.ypos <= object.divePos.y280object.ypos = object.divePos.y281object.direction = FACING_RIGHT282object.animation = MZEGGANI_LAUGH_LOOP283object.animationTimer = 0284CreateTempObject(TypeName[Boss Fireball], 0, object.xpos, object.ypos)285object[tempObjectPos].ypos += 0x140000286object.state++287end if288CallFunction(MZEggman_HandleFireballErupt)289break290291case MZEGGMAN_DROPPEDFIREBALL_R292object.timer++293if object.timer == 80294object.timer = 0295object.xvel = object.speed296FlipSign(object.xvel)297object.yvel = 0x10000298object.animation = MZEGGANI_IDLE299object.flameAnim = FLAME_INACTIVE300object.state = MZEGGMAN_MOVE_L301end if302303CallFunction(MZEggman_HandleFireballErupt)304break305306case MZEGGMAN_EXPLODE307object.timer++308temp0 = object.timer309temp0 &= 7310if temp0 == 4311Rand(temp0, 64)312temp0 -= 32313temp0 <<= 16314temp0 += object.xpos315Rand(temp1, 48)316temp1 -= 24317temp1 <<= 16318temp1 += object.ypos319CreateTempObject(TypeName[Explosion], 0, temp0, temp1)320PlaySfx(SfxName[Explosion], false)321end if322323if object.timer == 180324object.animation = MZEGGANI_TOASTED325object.animationTimer = 0326object.timer = 0327object.direction = FACING_LEFT328ResetObjectEntity(SLOT_MUSICEVENT_BOSS, TypeName[Music Event], MUSICEVENT_FADETOSTAGE, 0, 0)329object[SLOT_MUSICEVENT_BOSS].priority = PRIORITY_ACTIVE330object.state++331end if332break333334case MZEGGMAN_DEFEATFALL335object.ypos += object.yvel336object.yvel += 0x1800337338object.timer++339if object.timer == 32340object.yvel = 0341object.timer = 0342object.state++343end if344break345346case MZEGGMAN_DEFEATRISE347if object.timer < 40348object.ypos += object.yvel349object.yvel -= 0x800350object.timer++351else352object.timer = 0353object.yvel = 0354object.angle = 0355object.originPos.y = object.ypos356object.state++357end if358break359360case MZEGGMAN_FLEE361CallFunction(MZEggman_Oscillate)362363if object.timer < 8364object.timer++365else366object.timer = 0367object.animation = MZEGGANI_PANIC368object.animationTimer = 0369object.flameAnim = FLAME_EXPLODE370object.flameAnimTimer = 0371object.priority = PRIORITY_ACTIVE372temp0 = tileLayer[0].xsize373temp0 <<= 7374stage.newXBoundary2 = temp0375object.state++376end if377break378379case MZEGGMAN_ESCAPE380CallFunction(MZEggman_Oscillate)381object.xpos += 0x40000382object.originPos.y -= 0x4000383if object.outOfBounds == true384object.type = TypeName[Blank Object]385object.priority = PRIORITY_BOUNDS386end if387break388389case MZEGGMAN_HITFREEZE390object.hitDelay++391if object.hitDelay == 16392object.hitDelay = 0393object.state = object.nextState394end if395break396397end switch398399if object.health != 0400if object.invincibilityTimer > 0401object.invincibilityTimer--402end if403404foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)405if object.invincibilityTimer == 0406CheckEqual(player[currentPlayer].animation, ANI_HURT)407temp0 = checkResult408CheckEqual(player[currentPlayer].animation, ANI_DYING)409temp0 |= checkResult410CheckEqual(player[currentPlayer].animation, ANI_DROWNING)411temp0 |= checkResult412if temp0 != false413if object.animation != MZEGGANI_LAUGH414object.animation = MZEGGANI_LAUGH415object.animationTimer = 0416end if417end if418419#platform: USE_STANDALONE420BoxCollisionTest(C_TOUCH, object.entityPos, -20, -16, 20, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)421#endplatform422#platform: USE_ORIGINS423BoxCollisionTest(C_TOUCH, object.entityPos, -20, -16, 20, 16, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)424#endplatform425if checkResult == true426CallFunction(Player_CheckHit)427if object.state > MZEGGMAN_TAUNT428if object.state != MZEGGMAN_HITFREEZE429object.nextState = object.state430object.state = MZEGGMAN_HITFREEZE431end if432end if433434if checkResult == true435object.health--436if object.health == 0437#platform: USE_ORIGINS438CallNativeFunction2(NotifyCallback, NOTIFY_KILL_BOSS, 0)439CallNativeFunction2(NotifyCallback, NOTIFY_BOSS_END, true)440#endplatform441player.score += 1000442object.drawOrder = 3443object.animation = MZEGGANI_DEFEATED444object.animationTimer = 0445object.flameAnim = FLAME_INACTIVE446object.timer = 0447object.yvel = 0448object.state = MZEGGMAN_EXPLODE449else450object.animation = MZEGGANI_HIT451object.animationTimer = 0452object.invincibilityTimer = 32453PlaySfx(SfxName[Boss Hit], false)454end if455end if456end if457end if458next459end if460461// Handle Right Bounds462if object.state < MZEGGMAN_ESCAPE463foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)464temp0 = player[currentPlayer].collisionRight465temp0 <<= 16466temp0 += player[currentPlayer].xpos467temp1 = stage.curXBoundary2468temp1 <<= 16469if temp0 > temp1470player[currentPlayer].xvel = 0471player[currentPlayer].speed = 0472player[currentPlayer].xpos = temp1473temp0 = player[currentPlayer].collisionRight474temp0 <<= 16475player[currentPlayer].xpos -= temp0476end if477next478end if479end event480481482event ObjectDraw483switch object.animation484default485case MZEGGANI_INVISIBLE486break487488case MZEGGANI_IDLE489temp0 = object.animationTimer490temp0 /= 6491object.animationTimer++492object.animationTimer %= 12493DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)494break495496case MZEGGANI_LAUGH497temp0 = object.animationTimer498temp0 %= 10499temp0 /= 5500temp0 += 9501object.animationTimer++502if object.animationTimer == 50503object.animationTimer = 0504if player[0].animation != ANI_DYING505object.animation = MZEGGANI_IDLE506end if507end if508DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)509break510511case MZEGGANI_LAUGH_LOOP512temp0 = object.animationTimer513temp0 /= 5514temp0 += 9515object.animationTimer++516object.animationTimer %= 10517DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)518break519520case MZEGGANI_HIT521temp0 = object.animationTimer522temp0 &= 1523temp0 += 2524object.animationTimer++525if object.animationTimer == 30526object.animationTimer = 0527object.animation = MZEGGANI_IDLE528end if529DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)530break531532case MZEGGANI_DEFEATED533temp0 = object.animationTimer534temp0 >>= 5535temp0 += 4536object.animationTimer++537object.animationTimer &= 63538DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)539break540541case MZEGGANI_TOASTED542DrawSpriteFX(6, FX_FLIP, object.xpos, object.ypos)543break544545case MZEGGANI_PANIC546temp0 = object.animationTimer547temp0 >>= 2548temp0 += 7549object.animationTimer++550object.animationTimer %= 7551DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)552break553554end switch555556switch object.flameAnim557default558case FLAME_INACTIVE559break560561case FLAME_ACTIVE562temp0 = object.flameAnimTimer563temp0 >>= 2564temp0 += 11565object.flameAnimTimer++566object.flameAnimTimer &= 7567DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)568break569570case FLAME_EXPLODE571temp0 = object.flameAnimTimer572temp0 /= 3573temp0 += 11574object.flameAnimTimer++575if object.flameAnimTimer > 21576object.flameAnimTimer = 18577end if578DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)579break580581end switch582583DrawSpriteFX(19, FX_FLIP, object.xpos, object.ypos)584end event585586587event ObjectStartup588LoadSpriteSheet("Global/Eggman.gif")589590SpriteFrame(-28, -32, 64, 56, 1, 1)591SpriteFrame(-28, -32, 64, 56, 66, 1)592SpriteFrame(-28, -32, 64, 56, 131, 1)593SpriteFrame(-28, -32, 64, 56, 1, 58)594SpriteFrame(-28, -32, 64, 56, 1, 1)595SpriteFrame(-28, -32, 64, 56, 1, 58)596SpriteFrame(-28, -32, 64, 56, 66, 58)597SpriteFrame(-28, -32, 64, 56, 131, 58)598SpriteFrame(-28, -32, 64, 56, 66, 1)599SpriteFrame(-28, -32, 64, 56, 1, 115)600SpriteFrame(-28, -32, 64, 56, 66, 115)601SpriteFrame(34, 1, 10, 9, 196, 2)602SpriteFrame(33, 0, 15, 11, 196, 12)603SpriteFrame(34, -1, 22, 14, 213, 1)604SpriteFrame(34, -8, 32, 26, 213, 16)605SpriteFrame(34, -1, 22, 14, 213, 1)606SpriteFrame(34, -8, 32, 26, 213, 16)607SpriteFrame(34, 1, 10, 9, 196, 2)608SpriteFrame(33, 0, 15, 11, 196, 12)609SpriteFrame(-8, 16, 16, 16, 238, 43)610611// Set up values for every Eggman object612foreach (TypeName[Eggman], arrayPos0, ALL_ENTITIES)613object[arrayPos0].animation = MZEGGANI_IDLE614#platform: USE_STANDALONE615object[arrayPos0].health = 8616#endplatform617#platform: USE_ORIGINS618if game.bossOneLife == false619object[arrayPos0].health = 8620else621object[arrayPos0].health = 1622end if623#endplatform624next625626if stage.actNum == 3627if screen.xsize == 320628// Change the boss arena to match the original game's version629SetTileLayerEntry(348, 0, 50, 5)630SetTileLayerEntry(349, 0, 51, 5)631end if632end if633end event634635636// ========================637// Editor Events638// ========================639640event RSDKDraw641DrawSprite(0)642DrawSprite(19)643end event644645646event RSDKLoad647LoadSpriteSheet("Global/Eggman.gif")648SpriteFrame(-28, -32, 64, 56, 1, 1)649SpriteFrame(-28, -32, 64, 56, 66, 1)650SpriteFrame(-28, -32, 64, 56, 131, 1)651SpriteFrame(-28, -32, 64, 56, 1, 58)652SpriteFrame(-28, -32, 64, 56, 1, 1)653SpriteFrame(-28, -32, 64, 56, 1, 58)654SpriteFrame(-28, -32, 64, 56, 66, 58)655SpriteFrame(-28, -32, 64, 56, 131, 58)656SpriteFrame(-28, -32, 64, 56, 66, 1)657SpriteFrame(-28, -32, 64, 56, 1, 115)658SpriteFrame(-28, -32, 64, 56, 66, 115)659SpriteFrame(34, 1, 10, 9, 196, 2)660SpriteFrame(33, 0, 15, 11, 196, 12)661SpriteFrame(34, -1, 22, 14, 213, 1)662SpriteFrame(34, -8, 32, 26, 213, 16)663SpriteFrame(34, -1, 22, 14, 213, 1)664SpriteFrame(34, -8, 32, 26, 213, 16)665SpriteFrame(34, 1, 10, 9, 196, 2)666SpriteFrame(33, 0, 15, 11, 196, 12)667SpriteFrame(-8, 16, 16, 16, 238, 43)668669SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")670end event671672673