Path: blob/master/Sonic 1/Scripts/Enemies/NewtronShoot.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Newtron Shoot Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.propertyValue : object.fireDirection1213private alias object.value0 : object.timer14private alias object.value1 : object.fireInDir1516private alias 0 : NEWTRONSHOOT_WAITFORPLAYER17private alias 1 : NEWTRONSHOOT_APPEAR18private alias 2 : NEWTRONSHOOT_SHOOT19private alias 3 : NEWTRONSHOOT_SHOOTDELAY20private alias 4 : NEWTRONSHOOT_DISAPPEAR2122private alias 0 : NEWTRONSHOOT_ANI_IDLE23private alias 1 : NEWTRONSHOOT_ANI_SHOOT2425// Player Aliases26private alias object.xpos : player.xpos27private alias object.value40 : player.hitboxLeft28private alias object.value38 : player.hitboxTop29private alias object.value41 : player.hitboxRight30private alias object.value39 : player.hitboxBottom313233// ========================34// Function Declarations35// ========================3637reserve function NewtronShoot_DebugDraw38reserve function NewtronShoot_DebugSpawn394041// ========================42// Function Definitions43// ========================4445private function NewtronShoot_DebugDraw46DrawSprite(object.direction)47end function484950private function NewtronShoot_DebugSpawn51CreateTempObject(TypeName[Newtron Shoot], object.direction, object.xpos, object.ypos)52object[tempObjectPos].inkEffect = INK_ALPHA53object[tempObjectPos].alpha = 054end function555657// ========================58// Events59// ========================6061event ObjectUpdate62switch object.state63case NEWTRONSHOOT_WAITFORPLAYER64foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)65BoxCollisionTest(C_TOUCH, object.entityPos, -128, -64, 128, 64, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)66if checkResult == true67#platform: USE_ORIGINS68if game.playMode != BOOT_PLAYMODE_MISSION69#endplatform70object.state = NEWTRONSHOOT_APPEAR71if player[currentPlayer].xpos < object.xpos72// Firing to the left73object.fireDirection = FLIP_X74else75// Firing to the right76object.fireDirection = FLIP_NONE77end if78#platform: USE_ORIGINS79else80// fireInDir is set from the editor, in Missions where the Newtrons should only fire in a specific direction (M006)81if object.fireInDir != false82// woah that's actually like, a really cool way of doing it, especially when compared to how Origins does a bunch of other stuff83CheckLower(player[currentPlayer].xpos, object.xpos)84CheckEqual(object.fireDirection, checkResult)85object.state = checkResult86else87CheckLower(player[currentPlayer].xpos, object.xpos)88object.fireDirection = checkResult89object.state = NEWTRONSHOOT_APPEAR90end if91end if92#endplatform93end if94next95break9697case NEWTRONSHOOT_APPEAR98if object.alpha < 0xF899object.alpha += 4100else101object.alpha = 0xFF102object.state++103end if104break105106case NEWTRONSHOOT_SHOOT107if object.timer < 29108object.timer++109else110object.timer = 0111CreateTempObject(TypeName[Newtron Shot], 0, object.xpos, object.ypos)112if object.fireDirection == FLIP_X113// Shooting left114115object[tempObjectPos].xpos -= 0x140000116object[tempObjectPos].xvel = -0x20000117else118// Shooting right119120object[tempObjectPos].xpos += 0x140000121object[tempObjectPos].xvel = 0x20000122end if123object[tempObjectPos].ypos -= 0x80000124object.animation = NEWTRONSHOOT_ANI_SHOOT125object.state++126end if127break128129case NEWTRONSHOOT_SHOOTDELAY130if object.timer < 59131if object.timer == 15132object.animation = NEWTRONSHOOT_ANI_IDLE133end if134object.timer++135else136object.timer = 0137object.alpha = 0xF8138object.state++139end if140break141142case NEWTRONSHOOT_DISAPPEAR143if object.alpha > 0144object.alpha -= 4145else146object.type = TypeName[Blank Object]147end if148break149150end switch151152foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)153switch object.state154default155case NEWTRONSHOOT_WAITFORPLAYER156case NEWTRONSHOOT_APPEAR157case NEWTRONSHOOT_DISAPPEAR158break159160case NEWTRONSHOOT_SHOOT161case NEWTRONSHOOT_SHOOTDELAY162BoxCollisionTest(C_TOUCH, object.entityPos, -12, -14, 12, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)163if checkResult == true164CallFunction(Player_BadnikBreak)165end if166break167168end switch169next170end event171172173event ObjectDraw174switch object.animation175case NEWTRONSHOOT_ANI_IDLE176// Fire Direction matches with a Sprite Frame (0 for right, 1 for left)177// FX effects don't allow for flipping sprites, which is why we used pre-flipped sprites instead178DrawSpriteFX(object.fireDirection, FX_INK, object.xpos, object.ypos)179break180181case NEWTRONSHOOT_ANI_SHOOT182// Same from above applies here too about Fire Direction, yup183temp0 = object.fireDirection184temp0 += 2185DrawSprite(temp0)186break187188end switch189end event190191192event ObjectStartup193CheckCurrentStageFolder("Zone01")194if checkResult == true195LoadSpriteSheet("GHZ/Objects2.gif")196SpriteFrame(-20, -20, 39, 39, 1, 1) // 0 - Idle facing right frame197SpriteFrame(-19, -20, 39, 39, 81, 1) // 1 - Idle facing left frame198SpriteFrame(-20, -20, 39, 39, 41, 1) // 2 - Shooting facing left199SpriteFrame(-19, -20, 39, 39, 121, 1) // 3 - Shoting facing right frame200end if201202CheckCurrentStageFolder("Zone07")203if checkResult == true204LoadSpriteSheet("MBZ/Objects.gif")205SpriteFrame(-20, -20, 39, 39, 1, 164) // 0 - Idle facing right frame206SpriteFrame(-19, -20, 39, 39, 81, 164) // 1 - Idle facing left frame207SpriteFrame(-20, -20, 39, 39, 41, 164) // 2 - Shooting facing left208SpriteFrame(-19, -20, 39, 39, 121, 164) // 3 - Shoting facing right frame209end if210211foreach (TypeName[Newtron Shoot], arrayPos0, ALL_ENTITIES)212object[arrayPos0].inkEffect = INK_ALPHA213object[arrayPos0].alpha = 0214next215216SetTableValue(TypeName[Newtron Shoot], DebugMode_ObjCount, DebugMode_TypesTable)217SetTableValue(NewtronShoot_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)218SetTableValue(NewtronShoot_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)219DebugMode_ObjCount++220end event221222223// ========================224// Editor Events225// ========================226227event RSDKEdit228if editor.returnVariable == true229switch editor.variableID230case EDIT_VAR_PROPVAL // property value231checkResult = object.propertyValue232break233234case 0 // fireInDir235GetBit(checkResult, object.fireInDir, 0)236break237238case 1 // fireDirection239GetBit(checkResult, object.propertyValue, 0)240break241242end switch243else244switch editor.variableID245case EDIT_VAR_PROPVAL // property value246object.propertyValue = editor.variableValue247break248249case 0 // fireInDir250CheckNotEqual(editor.variableValue, false)251SetBit(object.fireInDir, 0, checkResult)252break253254case 1 // fireDirection255CheckNotEqual(editor.variableValue, false)256SetBit(object.propertyValue, 0, checkResult)257break258259end switch260end if261end event262263264event RSDKDraw265GetBit(temp0, object.propertyValue, 0)266DrawSprite(temp0)267end event268269270event RSDKLoad271CheckCurrentStageFolder("Zone07")272if checkResult == true273LoadSpriteSheet("MBZ/Objects.gif")274SpriteFrame(-20, -20, 39, 39, 1, 164)275SpriteFrame(-19, -20, 39, 39, 81, 164)276else277LoadSpriteSheet("GHZ/Objects2.gif")278SpriteFrame(-20, -20, 39, 39, 1, 1)279SpriteFrame(-19, -20, 39, 39, 81, 1)280end if281282// If the Newtron should only Shoot when the player is in a specific direction283// Only used in Origins's Mission Mode284AddEditorVariable("fireInDir")285SetActiveVariable("fireInDir")286AddEnumVariable("False", 0)287AddEnumVariable("True", 1)288289// Related to above, also only used in Mission Mode290// Otherwise, it's ignored291AddEditorVariable("fireDirection")292SetActiveVariable("fireDirection")293AddEnumVariable("Right", 0)294AddEnumVariable("Left", 1)295end event296297298