Path: blob/master/Sonic 1/Scripts/Mission/Batbrain2.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// This script is a copy of the normal Batbrain script, just with a check to see if the object's visible before playing sfx8// ..yes that's it, that's the only change910// ========================11// Aliases12// ========================1314private alias object.value0 : object.startPos.x15private alias object.value1 : object.startPos.y16private alias object.value2 : object.backupPlayer17private alias object.value3 : object.targetPlayer18private alias object.value4 : object.targetDistance19private alias object.value5 : object.dropPos.y2021// States22private alias 0 : BATBRAIN_AWAITPLAYER23private alias 1 : BATBRAIN_DROPPING24private alias 2 : BATBRAIN_FLYING25private alias 3 : BATBRAIN_RETURNTOROOF2627// Animations28private alias 0 : BATBRAIN_ANI_IDLE29private alias 1 : BATBRAIN_ANI_DROPPING30private alias 2 : BATBRAIN_ANI_FLYING3132// Player Aliases33private alias object.xpos : player.xpos34private alias object.ypos : player.ypos35private alias object.value40 : player.hitboxLeft36private alias object.value38 : player.hitboxTop37private alias object.value41 : player.hitboxRight38private alias object.value39 : player.hitboxBottom3940// Path ID Aliases41private alias 0 : PATH_A424344// ========================45// Function Declarations46// ========================4748reserve function Batbrain_DebugDraw49reserve function Batbrain_DebugSpawn50reserve function Batbrain_CheckOutOfRange515253// ========================54// Function Definitions55// ========================5657private function Batbrain_DebugDraw58DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)59end function606162private function Batbrain_DebugSpawn63CreateTempObject(TypeName[Batbrain], 0, object.xpos, object.ypos)64object[tempObjectPos].startPos.x = object.xpos65object[tempObjectPos].startPos.y = object.ypos66end function676869private function Batbrain_CheckOutOfRange70// This function is new to Batbrain271// There's not really much to say about it, it just sees if the object is visible at all7273temp1 = object.ixpos74temp1 -= screen.xoffset75CheckLower(temp1, 0)76temp0 = checkResult7778CheckGreater(temp1, screen.xsize)79temp0 |= checkResult8081temp1 = object.iypos82temp1 -= screen.yoffset83CheckLower(temp1, 0)84temp0 |= checkResult8586CheckGreater(temp1, screen.ysize)87checkResult |= temp088end function899091// ========================92// Events93// ========================949596event ObjectUpdate97switch object.state98case BATBRAIN_AWAITPLAYER99object.priority = PRIORITY_ACTIVE100101object.targetDistance = 0x7FFFFFFF102object.backupPlayer = 0103object.targetPlayer = 0xFFFF104105foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)106temp0 = player[currentPlayer].xpos107temp0 -= object.xpos108Abs(temp0)109if temp0 < object.targetDistance110object.targetDistance = temp0111object.backupPlayer = currentPlayer112end if113114if temp0 < 0x800000115if player[currentPlayer].ypos >= object.ypos116if object.targetPlayer != 0xFFFF117arrayPos0 = object.targetPlayer118if player[currentPlayer].ypos < player[arrayPos0].ypos119object.targetPlayer = currentPlayer120end if121else122object.targetPlayer = currentPlayer123end if124end if125end if126next127128if object.targetPlayer != 0xFFFF129arrayPos0 = object.targetPlayer130temp0 = player[arrayPos0].ypos131temp0 -= object.ypos132if temp0 >= 0133if temp0 <= 0x800000134Rand(temp0, 8)135if temp0 == 0136object.state = BATBRAIN_DROPPING137object.dropPos.y = player[arrayPos0].ypos138object.animation = BATBRAIN_ANI_DROPPING139end if140end if141end if142else143arrayPos0 = object.backupPlayer144end if145146if player[arrayPos0].xpos < object.xpos147object.direction = FLIP_NONE148else149object.direction = FLIP_X150end if151break152153case BATBRAIN_DROPPING154object.ypos += object.yvel155object.yvel += 0x1800156arrayPos0 = object.targetPlayer157if player[arrayPos0].xpos < object.xpos158object.direction = FLIP_NONE159else160object.direction = FLIP_X161end if162163temp0 = object.dropPos.y164temp0 -= object.ypos165if temp0 < 0x100000166if object.direction == FLIP_NONE167object.xvel = -0x10000168else169object.xvel = 0x10000170end if171object.yvel = 0172object.animation = BATBRAIN_ANI_FLYING173object.state = BATBRAIN_FLYING174end if175break176177case BATBRAIN_FLYING178object.xpos += object.xvel179arrayPos0 = object.targetPlayer180temp0 = player[arrayPos0].xpos181temp0 -= object.xpos182Abs(temp0)183if temp0 >= 0x800000184Rand(temp0, 8)185if temp0 == 0186object.state = BATBRAIN_RETURNTOROOF187end if188end if189break190191case BATBRAIN_RETURNTOROOF192object.xpos += object.xvel193object.ypos += object.yvel194object.yvel -= 0x1800195196ObjectTileCollision(CSIDE_ROOF, 0, -12, PATH_A)197if checkResult == true198object.xvel = 0199object.yvel = 0200object.state = BATBRAIN_AWAITPLAYER201object.animation = BATBRAIN_ANI_IDLE202end if203break204205end switch206207if object.outOfBounds == true208temp0 = object.xpos209temp1 = object.ypos210object.xpos = object.startPos.x211object.ypos = object.startPos.y212if object.outOfBounds == true213object.xvel = 0214object.yvel = 0215object.direction = FLIP_NONE216object.animation = BATBRAIN_ANI_IDLE217object.frame = 0218object.priority = PRIORITY_BOUNDS219object.state = BATBRAIN_AWAITPLAYER220else221object.xpos = temp0222object.ypos = temp1223end if224end if225226foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)227BoxCollisionTest(C_TOUCH, object.entityPos, -12, -18, 12, 18, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)228if checkResult == true229CallFunction(Player_BadnikBreak)230end if231next232233switch object.animation234case BATBRAIN_ANI_IDLE235object.frame = 0236break237238case BATBRAIN_ANI_DROPPING239object.frame = 1240break241242case BATBRAIN_ANI_FLYING243if object.animationTimer == 0244// this is the only change in this (Batbrain2) script245// ..thanks ig?246CallFunction(Batbrain_CheckOutOfRange)247if checkResult == false248PlaySfx(SfxName[Batbrain Fly], false)249end if250end if251object.frame = object.animationTimer252object.frame >>= 2253object.frame++254object.animationTimer++255object.animationTimer &= 15256break257258end switch259end event260261262event ObjectDraw263DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)264end event265266267event ObjectStartup268CheckCurrentStageFolder("Zone02")269temp0 = checkResult270if game.playMode == BOOT_PLAYMODE_MISSION271// In Origins's missions, GHZ and SYZ qualify for loading MZ sprites too272CheckCurrentStageFolder("Zone01")273temp0 |= checkResult274CheckCurrentStageFolder("Zone03")275temp0 |= checkResult276end if277278if temp0 == true279LoadSpriteSheet("MZ/Objects.gif")280SpriteFrame(-7, -12, 14, 24, 37, 98)281SpriteFrame(-12, -14, 32, 30, 52, 81)282SpriteFrame(-15, -6, 35, 20, 1, 106)283SpriteFrame(-12, -8, 29, 28, 85, 81)284SpriteFrame(-15, -6, 35, 20, 1, 106)285end if286287CheckCurrentStageFolder("Zone07")288if checkResult == true289LoadSpriteSheet("MBZ/Objects.gif")290SpriteFrame(-7, -12, 14, 24, 52, 68)291SpriteFrame(-12, -14, 32, 30, 1, 93)292SpriteFrame(-15, -6, 35, 20, 64, 99)293SpriteFrame(-12, -8, 29, 28, 34, 93)294SpriteFrame(-15, -6, 35, 20, 64, 99)295end if296297foreach (TypeName[Batbrain], arrayPos0, ALL_ENTITIES)298object[arrayPos0].startPos.x = object[arrayPos0].xpos299object[arrayPos0].startPos.y = object[arrayPos0].ypos300object[arrayPos0].drawOrder = 5301next302303SetTableValue(TypeName[Batbrain], DebugMode_ObjCount, DebugMode_TypesTable)304SetTableValue(Batbrain_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)305SetTableValue(Batbrain_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)306DebugMode_ObjCount++307end event308309310// ========================311// Editor Events312// ========================313314event RSDKDraw315DrawSprite(0)316end event317318319event RSDKLoad320CheckCurrentStageFolder("Zone07")321if checkResult == true322LoadSpriteSheet("MBZ/Objects.gif")323SpriteFrame(-7, -12, 14, 24, 52, 68)324else325// We just load MZ sprites as the backup, not checking for MZ (or GHZ or SYZ) here326LoadSpriteSheet("MZ/Objects.gif")327SpriteFrame(-7, -12, 14, 24, 37, 98)328end if329330SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")331end event332333334