Path: blob/master/Sonic 2/Scripts/Enemies/Buzzer.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Buzzer Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.startPos.x13private alias object.value2 : object.hasShot14private alias object.value3 : object.shootTimer1516// States17private alias 0 : BUZZER_FLYING18private alias 1 : BUZZER_STOPPED19private alias 2 : BUZZER_SHOOTING20private alias 3 : BUZZER_INVISIBLE2122// Animations23private alias 0 : BUZZER_ANI_FLYING24private alias 1 : BUZZER_ANI_STOPPED25private alias 2 : BUZZER_ANI_SHOOTING26private alias 3 : BUZZER_ANI_INVISBLE2728// Player Aliases29private alias object.value40 : player.hitboxLeft30private alias object.value38 : player.hitboxTop31private alias object.value41 : player.hitboxRight32private alias object.value39 : player.hitboxBottom333435// ========================36// Function Declarations37// ========================3839reserve function Buzzer_DebugDraw40reserve function Buzzer_DebugSpawn414243// ========================44// Function Definitions45// ========================4647private function Buzzer_DebugDraw48DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)49end function505152private function Buzzer_DebugSpawn53CreateTempObject(TypeName[Buzzer], 0, object.xpos, object.ypos)54GetBit(temp0, object.direction, 0)55if temp0 == FACING_RIGHT56object[tempObjectPos].direction = FLIP_NONE57object[tempObjectPos].xvel = -0x1000058else59object[tempObjectPos].direction = FLIP_X60object[tempObjectPos].xvel = 0x1000061end if62end function636465// ========================66// Events67// ========================6869event ObjectUpdate70switch object.state71case BUZZER_FLYING72object.priority = PRIORITY_ACTIVE73if object.timer < 25674object.timer++75object.xpos += object.xvel76else77object.timer = 078object.state = BUZZER_STOPPED79object.animation = BUZZER_ANI_STOPPED80object.direction ^= FLIP_X81FlipSign(object.xvel)82end if83break8485case BUZZER_STOPPED86if object.shootTimer < 3087object.shootTimer++88else89object.shootTimer = 090object.state = BUZZER_FLYING91object.animation = BUZZER_ANI_FLYING92object.hasShot = false93end if94break9596case BUZZER_SHOOTING97if object.shootTimer < 5098object.shootTimer++99if object.shootTimer == 30100CreateTempObject(TypeName[Buzzer Shot], 0, object.xpos, object.ypos)101object[tempObjectPos].direction = object.direction102if object.direction == FLIP_NONE103object[tempObjectPos].xpos += 0xD0000104object[tempObjectPos].xvel = -0x18000105else106object[tempObjectPos].xpos -= 0xD0000107object[tempObjectPos].xvel = 0x18000108end if109object[tempObjectPos].ypos += 0x180000110object[tempObjectPos].yvel = 0x18000111end if112else113object.shootTimer = 0114object.state = BUZZER_FLYING115object.animation = BUZZER_ANI_FLYING116object.hasShot = true117end if118break119120case BUZZER_INVISIBLE121object.animation = BUZZER_ANI_INVISBLE122break123124end switch125126if object.outOfBounds == true127temp0 = object.xpos128object.xpos = object.startPos.x129if object.shootTimer == 1130object.state = BUZZER_INVISIBLE131end if132133if object.outOfBounds == true134object.xpos = object.startPos.x135GetBit(temp0, object.propertyValue, 0)136if temp0 == 0137object.direction = FLIP_NONE138object.xvel = -0x10000139else140object.direction = FLIP_X141object.xvel = 0x10000142end if143144#platform: USE_ORIGINS145if game.playMode == BOOT_PLAYMODE_MISSION146GetBit(temp0, object.propertyValue, 1)147if temp0 != false148object.xvel = 0149end if150end if151#endplatform152153object.timer = 0154object.animation = BUZZER_ANI_FLYING155object.priority = PRIORITY_BOUNDS156object.state = BUZZER_FLYING157else158object.xpos = temp0159end if160end if161162foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)163if object.state == BUZZER_FLYING164if object.hasShot == false165if object.direction == FLIP_NONE166BoxCollisionTest(C_TOUCH, object.entityPos, -28, -256, -30, 256, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)167else168BoxCollisionTest(C_TOUCH, object.entityPos, 28, -256, 30, 256, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)169end if170171if checkResult == true172object.state = BUZZER_SHOOTING173object.animation = BUZZER_ANI_SHOOTING174end if175end if176end if177178if object.state < BUZZER_INVISIBLE179BoxCollisionTest(C_TOUCH, object.entityPos, -16, -12, 16, 12, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)180if checkResult == true181CallFunction(Player_BadnikBreak)182end if183end if184next185186object.frame = object.animationTimer187object.frame /= 3188object.frame += 3189object.animationTimer++190if object.animationTimer >= 6191object.animationTimer = 0192end if193end event194195196event ObjectDraw197switch object.animation198case BUZZER_ANI_FLYING199DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)200DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)201break202203case BUZZER_ANI_STOPPED204DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)205break206207case BUZZER_ANI_SHOOTING208DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)209break210211case BUZZER_ANI_INVISBLE212break213214end switch215end event216217218event ObjectStartup219CheckCurrentStageFolder("Zone01")220if checkResult == true221LoadSpriteSheet("EHZ/Objects.gif")222SpriteFrame(-24, -8, 48, 16, 1, 1)223SpriteFrame(-24, -8, 42, 31, 1, 18)224SpriteFrame(1, 6, 17, 17, 50, 1)225SpriteFrame(5, -8, 6, 5, 19, 50)226SpriteFrame(5, -8, 7, 5, 19, 56)227else228LoadSpriteSheet("MBZ/Objects.gif")229SpriteFrame(-24, -8, 48, 16, 1, 256)230SpriteFrame(-24, -8, 42, 31, 1, 273)231SpriteFrame(1, 6, 17, 17, 268, 501)232SpriteFrame(5, -8, 6, 5, 137, 331)233SpriteFrame(5, -8, 7, 5, 137, 337)234end if235236foreach (TypeName[Buzzer], arrayPos0, ALL_ENTITIES)237object[arrayPos0].startPos.x = object[arrayPos0].xpos238239GetBit(temp0, object[arrayPos0].propertyValue, 0)240if temp0 == 0241object[arrayPos0].direction = FLIP_NONE242object[arrayPos0].xvel = -0x10000243else244object[arrayPos0].direction = FLIP_X245object[arrayPos0].xvel = 0x10000246end if247248#platform: USE_ORIGINS249if game.playMode == BOOT_PLAYMODE_MISSION250GetBit(temp0, object.propertyValue, 1)251if temp0 != false252object.xvel = 0253end if254end if255#endplatform256next257258SetTableValue(TypeName[Buzzer], DebugMode_ObjCount, DebugMode_TypesTable)259SetTableValue(Buzzer_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)260SetTableValue(Buzzer_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)261DebugMode_ObjCount++262end event263264265// ========================266// Editor Events267// ========================268269event RSDKEdit270if editor.returnVariable == true271switch editor.variableID272case EDIT_VAR_PROPVAL // property value273checkResult = object.propertyValue274break275276case 0 // direction277GetBit(checkResult, object.propertyValue, 0)278break279280case 1 // static281GetBit(checkResult, object.propertyValue, 1)282break283284end switch285else286switch editor.variableID287case EDIT_VAR_PROPVAL // property value288object.propertyValue = editor.variableValue289break290291case 0 // direction292CheckNotEqual(editor.variableValue, 0)293SetBit(object.propertyValue, 0, checkResult)294break295296case 1 // static297CheckNotEqual(editor.variableValue, 0)298SetBit(object.propertyValue, 1, checkResult)299break300301end switch302end if303end event304305306event RSDKDraw307GetBit(object.direction, object.propertyValue, 0)308DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)309DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)310end event311312313event RSDKLoad314CheckCurrentStageFolder("Zone01")315if checkResult == true316LoadSpriteSheet("EHZ/Objects.gif")317SpriteFrame(-24, -8, 48, 16, 1, 1)318SpriteFrame(5, -8, 6, 5, 19, 50)319else320LoadSpriteSheet("MBZ/Objects.gif")321SpriteFrame(-24, -8, 48, 16, 1, 256)322SpriteFrame(5, -8, 6, 5, 137, 331)323end if324325AddEditorVariable("direction")326SetActiveVariable("direction")327AddEnumVariable("Left", 0)328AddEnumVariable("Right", 1)329330// Only functional in Origins' Mission Mode331// Not much of a good way to show that in the editor, though...332AddEditorVariable("static")333SetActiveVariable("static")334AddEnumVariable("False", 0)335AddEnumVariable("True", 1)336end event337338339