Path: blob/master/Sonic 2/Scripts/Enemies/Flasher.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Flasher 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.holdTimer13private alias object.value2 : object.moveIndex14private alias object.value3 : object.flip15private alias object.value4 : object.turnIndex16private alias object.value5 : object.startPos.x17private alias object.value6 : object.startPos.y1819// States20private alias 0 : FLASHER_PAUSED21private alias 1 : FLASHER_MOVING22private alias 2 : FLASHER_CHARGING23private alias 3 : FLASHER_FLASHING24private alias 4 : FLASHER_DIMMING2526// Player Aliases27private alias object.value37 : player.shield28private alias object.value40 : player.hitboxLeft29private alias object.value38 : player.hitboxTop30private alias object.value41 : player.hitboxRight31private alias object.value39 : player.hitboxBottom3233private alias 4 : SHIELD_LIGHTNING343536// ========================37// Function Declarations38// ========================3940reserve function Flasher_DebugDraw41reserve function Flasher_DebugSpawn4243// ========================44// Tables45// ========================4647// How long the Flasher should pause between movements48private table Flasher_delayTable49256, 416, 520, 645, 768, 832, 912, 1088, 6144050end table5152// Which way the flasher should turn after each cycle53// First value in an entry is if it should turn around X-wise, second is for Y54private table Flasher_directionTable551, 1560, 1571, 1580, 1590, 1601, 0610, 1620, 163end table6465// The three below are animation tables, with values corresponding to SpriteFrames66// This is parallel to how the object's animation was handled in the original Sonic 267private table Flasher_aniCharging681, 0, 0, 0690, 0, 1, 0700, 0, 0, 1710, 0, 1, 0721, 0, 1, 0731, 0, 1, 0741, 075end table7677private table Flasher_aniFlashing782, 3, 4, 3, 2, 0, 2790, 3, 0, 4, 0, 3, 080end table8182private table Flasher_aniDimming834, 4, 4, 4843, 3, 3, 3852, 2, 2, 2861, 1, 1, 1870, 0, 0, 088end table899091// ========================92// Function Definitions93// ========================9495private function Flasher_DebugDraw96DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)97end function9899100private function Flasher_DebugSpawn101CreateTempObject(TypeName[Flasher], 0, object.xpos, object.ypos)102end function103104105// ========================106// Events107// ========================108109event ObjectUpdate110switch object.state111case FLASHER_PAUSED112// State only used upon init, just pause for a moment before starting to attack the player113object.timer++114if object.timer == 64115object.timer = 128116object.xvel = -0x10000117object.yvel = 0x4000118object.speed = 512119object.state = FLASHER_MOVING120if object.priority != PRIORITY_XBOUNDS_DESTROY121object.priority = PRIORITY_ACTIVE122end if123end if124125foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)126BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)127if checkResult == true128CallFunction(Player_BadnikBreak)129end if130next131break132133case FLASHER_MOVING134if object.timer > 0135object.timer--136if object.xvel < 0137object.direction = FLIP_NONE138else139object.direction = FLIP_X140end if141142GetTableValue(temp0, object.moveIndex, Flasher_delayTable)143object.holdTimer++144if object.holdTimer == temp0145GetTableValue(object.flip, object.turnIndex, Flasher_directionTable)146if object.flip == true147FlipSign(object.speed)148end if149150object.turnIndex++151GetTableValue(object.flip, object.turnIndex, Flasher_directionTable)152if object.flip == true153FlipSign(object.yvel)154end if155156object.turnIndex++157object.turnIndex &= 15158159object.moveIndex++160if object.moveIndex == 10161object.moveIndex = 0162object.holdTimer = 0163end if164end if165166object.xvel += object.speed167object.xpos += object.xvel168object.ypos += object.yvel169else170object.state = FLASHER_CHARGING171end if172173foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)174BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)175if checkResult == true176CallFunction(Player_BadnikBreak)177end if178next179break180181case FLASHER_CHARGING182GetTableValue(object.frame, object.timer, Flasher_aniCharging)183object.timer++184if object.timer == 26185object.timer = 0186object.state = FLASHER_FLASHING187end if188189foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)190BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)191if player[currentPlayer].shield != SHIELD_LIGHTNING192if checkResult == true193CallFunction(Player_LightningHit)194else195BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)196if checkResult == true197CallFunction(Player_BadnikBreak)198end if199end if200else201if checkResult == true202CallFunction(Player_BadnikBreak)203end if204end if205next206break207208case FLASHER_FLASHING209GetTableValue(object.frame, object.animationTimer, Flasher_aniFlashing)210object.animationTimer++211if object.animationTimer == 14212object.animationTimer = 6213end if214215object.timer++216if object.timer == 128217object.timer = 0218object.state = FLASHER_DIMMING219end if220221foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)222if player[currentPlayer].shield != SHIELD_LIGHTNING223BoxCollisionTest(C_TOUCH, object.entityPos, -12, -12, 12, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)224if checkResult == true225CallFunction(Player_LightningHit)226else227BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)228if checkResult == true229CallFunction(Player_BadnikBreak)230end if231end if232else233BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)234if checkResult == true235CallFunction(Player_BadnikBreak)236end if237end if238next239break240241case FLASHER_DIMMING242GetTableValue(object.frame, object.timer, Flasher_aniDimming)243object.timer++244if object.timer == 20245object.timer = 128246object.state = FLASHER_MOVING247end if248249foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)250BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)251if player[currentPlayer].shield != SHIELD_LIGHTNING252if checkResult == true253CallFunction(Player_LightningHit)254else255BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)256if checkResult == true257CallFunction(Player_BadnikBreak)258end if259end if260else261if checkResult == true262CallFunction(Player_BadnikBreak)263end if264end if265next266break267268end switch269270if object.outOfBounds == true271// Even if out of bounds, only despawn the Flasher if its startPos is OOB too272temp0 = object.xpos273temp1 = object.ypos274object.xpos = object.startPos.x275object.ypos = object.startPos.y276if object.outOfBounds == true277if object.priority != PRIORITY_XBOUNDS_DESTROY278object.timer = 0279object.frame = 0280object.state = FLASHER_PAUSED281object.priority = PRIORITY_BOUNDS282end if283else284// Object startPos is within bounds, move the Flasher back and continue as normal285object.xpos = temp0286object.ypos = temp1287end if288end if289end event290291292event ObjectDraw293DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)294end event295296297event ObjectStartup298CheckCurrentStageFolder("Zone06")299if checkResult == true300LoadSpriteSheet("MCZ/Objects.gif")301302// Normal frame303SpriteFrame(-16, -8, 23, 15, 1, 1)304305// Lighting Frames306SpriteFrame(-16, -8, 23, 15, 25, 1)307SpriteFrame(-16, -8, 24, 16, 1, 17)308SpriteFrame(-16, -12, 28, 24, 1, 34)309SpriteFrame(-16, -16, 32, 32, 1, 59)310else311// Note - even if these are spriteframes for MBZ, they're broken with values copied directly from MCZ's sheet312// Using these sheet positions results in some of Eggman's head frames313LoadSpriteSheet("MBZ/Objects.gif")314315// Normal frame316SpriteFrame(-16, -8, 23, 15, 1, 1)317318// Lighting Frames319SpriteFrame(-16, -8, 23, 15, 25, 1)320SpriteFrame(-16, -8, 24, 16, 1, 17)321SpriteFrame(-16, -12, 28, 24, 1, 34)322SpriteFrame(-16, -16, 32, 32, 1, 59)323end if324325foreach (TypeName[Flasher], arrayPos0, ALL_ENTITIES)326object[arrayPos0].startPos.x = object[arrayPos0].xpos327object[arrayPos0].startPos.y = object[arrayPos0].ypos328next329330SetTableValue(TypeName[Flasher], DebugMode_ObjCount, DebugMode_TypesTable)331SetTableValue(Flasher_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)332SetTableValue(Flasher_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)333DebugMode_ObjCount++334end event335336337// ========================338// Editor Events339// ========================340341event RSDKDraw342DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)343end event344345346event RSDKLoad347CheckCurrentStageFolder("Zone06")348if checkResult == true349LoadSpriteSheet("MCZ/Objects.gif")350SpriteFrame(-16, -8, 23, 15, 1, 1)351else352LoadSpriteSheet("MBZ/Objects.gif")353SpriteFrame(-16, -8, 23, 15, 125, 501) // Decomp note - using fixed frame here354end if355356SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")357end event358359360