Path: blob/master/Sonic 1/Scripts/Enemies/Batbrain.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Batbrain Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.startPos.x12private alias object.value1 : object.startPos.y13private alias object.value2 : object.backupPlayer14private alias object.value3 : object.targetPlayer15private alias object.value4 : object.targetDistance16private alias object.value5 : object.dropPos.y1718// States19private alias 0 : BATBRAIN_AWAITPLAYER20private alias 1 : BATBRAIN_DROPPING21private alias 2 : BATBRAIN_FLYING22private alias 3 : BATBRAIN_RETURNTOROOF2324// Animations25private alias 0 : BATBRAIN_ANI_IDLE26private alias 1 : BATBRAIN_ANI_DROPPING27private alias 2 : BATBRAIN_ANI_FLYING2829// Player Aliases30private alias object.xpos : player.xpos31private alias object.ypos : player.ypos32private alias object.value40 : player.hitboxLeft33private alias object.value38 : player.hitboxTop34private alias object.value41 : player.hitboxRight35private alias object.value39 : player.hitboxBottom3637// Path ID Aliases38private alias 0 : PATH_A394041// ========================42// Function Declarations43// ========================4445reserve function Batbrain_DebugDraw46reserve function Batbrain_DebugSpawn474849// ========================50// Function Definitions51// ========================5253private function Batbrain_DebugDraw54DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)55end function565758private function Batbrain_DebugSpawn59CreateTempObject(TypeName[Batbrain], 0, object.xpos, object.ypos)60object[tempObjectPos].startPos.x = object.xpos61object[tempObjectPos].startPos.y = object.ypos62end function636465// ========================66// Events67// ========================6869event ObjectUpdate70switch object.state71case BATBRAIN_AWAITPLAYER72object.priority = PRIORITY_ACTIVE7374object.targetDistance = 0x7FFFFFFF75object.backupPlayer = 076object.targetPlayer = 0xFFFF7778foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)79temp0 = player[currentPlayer].xpos80temp0 -= object.xpos81Abs(temp0)82if temp0 < object.targetDistance83object.targetDistance = temp084object.backupPlayer = currentPlayer85end if8687if temp0 < 0x80000088if player[currentPlayer].ypos >= object.ypos89if object.targetPlayer != 0xFFFF90arrayPos0 = object.targetPlayer91if player[currentPlayer].ypos < player[arrayPos0].ypos92object.targetPlayer = currentPlayer93end if94else95object.targetPlayer = currentPlayer96end if97end if98end if99next100101if object.targetPlayer != 0xFFFF102arrayPos0 = object.targetPlayer103temp0 = player[arrayPos0].ypos104temp0 -= object.ypos105if temp0 >= 0106if temp0 <= 0x800000107Rand(temp0, 8)108if temp0 == 0109object.state = BATBRAIN_DROPPING110object.dropPos.y = player[arrayPos0].ypos111object.animation = BATBRAIN_ANI_DROPPING112end if113end if114end if115else116arrayPos0 = object.backupPlayer117end if118119if player[arrayPos0].xpos < object.xpos120object.direction = FLIP_NONE121else122object.direction = FLIP_X123end if124break125126case BATBRAIN_DROPPING127object.ypos += object.yvel128object.yvel += 0x1800129arrayPos0 = object.targetPlayer130if player[arrayPos0].xpos < object.xpos131object.direction = FLIP_NONE132else133object.direction = FLIP_X134end if135136temp0 = object.dropPos.y137temp0 -= object.ypos138if temp0 < 0x100000139if object.direction == FLIP_NONE140object.xvel = -0x10000141else142object.xvel = 0x10000143end if144object.yvel = 0145object.animation = BATBRAIN_ANI_FLYING146object.state = BATBRAIN_FLYING147end if148break149150case BATBRAIN_FLYING151object.xpos += object.xvel152arrayPos0 = object.targetPlayer153temp0 = player[arrayPos0].xpos154temp0 -= object.xpos155Abs(temp0)156if temp0 >= 0x800000157Rand(temp0, 8)158if temp0 == 0159object.state = BATBRAIN_RETURNTOROOF160end if161end if162break163164case BATBRAIN_RETURNTOROOF165object.xpos += object.xvel166object.ypos += object.yvel167object.yvel -= 0x1800168169ObjectTileCollision(CSIDE_ROOF, 0, -12, PATH_A)170if checkResult == true171object.xvel = 0172object.yvel = 0173object.state = BATBRAIN_AWAITPLAYER174object.animation = BATBRAIN_ANI_IDLE175end if176break177178end switch179180if object.outOfBounds == true181temp0 = object.xpos182temp1 = object.ypos183object.xpos = object.startPos.x184object.ypos = object.startPos.y185if object.outOfBounds == true186object.xvel = 0187object.yvel = 0188object.direction = FLIP_NONE189object.animation = BATBRAIN_ANI_IDLE190object.frame = 0191object.priority = PRIORITY_BOUNDS192object.state = BATBRAIN_AWAITPLAYER193else194object.xpos = temp0195object.ypos = temp1196end if197end if198199foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)200BoxCollisionTest(C_TOUCH, object.entityPos, -12, -18, 12, 18, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)201if checkResult == true202CallFunction(Player_BadnikBreak)203end if204next205206switch object.animation207case BATBRAIN_ANI_IDLE208object.frame = 0209break210211case BATBRAIN_ANI_DROPPING212object.frame = 1213break214215case BATBRAIN_ANI_FLYING216if object.animationTimer == 0217PlaySfx(SfxName[Batbrain Fly], false)218end if219object.frame = object.animationTimer220object.frame >>= 2221object.frame++222object.animationTimer++223object.animationTimer &= 15224break225226end switch227end event228229230event ObjectDraw231DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)232end event233234235event ObjectStartup236CheckCurrentStageFolder("Zone02")237#platform: USE_ORIGINS238temp0 = checkResult239if game.playMode == BOOT_PLAYMODE_MISSION240// In Origins's missions, GHZ and SYZ qualify for loading MZ sprites too241CheckCurrentStageFolder("Zone01")242temp0 |= checkResult243CheckCurrentStageFolder("Zone03")244temp0 |= checkResult245end if246247if temp0 == true248#endplatform249#platform: USE_STANDALONE250if checkResult == true251#endplatform252LoadSpriteSheet("MZ/Objects.gif")253SpriteFrame(-7, -12, 14, 24, 37, 98)254SpriteFrame(-12, -14, 32, 30, 52, 81)255SpriteFrame(-15, -6, 35, 20, 1, 106)256SpriteFrame(-12, -8, 29, 28, 85, 81)257SpriteFrame(-15, -6, 35, 20, 1, 106)258end if259260CheckCurrentStageFolder("Zone07")261if checkResult == true262LoadSpriteSheet("MBZ/Objects.gif")263SpriteFrame(-7, -12, 14, 24, 52, 68)264SpriteFrame(-12, -14, 32, 30, 1, 93)265SpriteFrame(-15, -6, 35, 20, 64, 99)266SpriteFrame(-12, -8, 29, 28, 34, 93)267SpriteFrame(-15, -6, 35, 20, 64, 99)268end if269270foreach (TypeName[Batbrain], arrayPos0, ALL_ENTITIES)271// Store the object's starting pos272object[arrayPos0].startPos.x = object[arrayPos0].xpos273object[arrayPos0].startPos.y = object[arrayPos0].ypos274object[arrayPos0].drawOrder = 5275next276277// Add the object to the stage's debug object list278SetTableValue(TypeName[Batbrain], DebugMode_ObjCount, DebugMode_TypesTable)279SetTableValue(Batbrain_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)280SetTableValue(Batbrain_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)281DebugMode_ObjCount++282end event283284285// ========================286// Editor Events287// ========================288289event RSDKDraw290DrawSprite(0)291end event292293294event RSDKLoad295CheckCurrentStageFolder("Zone07")296if checkResult == true297LoadSpriteSheet("MBZ/Objects.gif")298SpriteFrame(-7, -12, 14, 24, 52, 68)299else300// We just load MZ sprites as the backup, not checking for MZ (or GHZ or SYZ) here301LoadSpriteSheet("MZ/Objects.gif")302SpriteFrame(-7, -12, 14, 24, 37, 98)303end if304305SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")306end event307308309