Path: blob/master/Sonic 1/Scripts/SBZ/ForceField.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Force Field Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011// Bit of a note: The less transparency you have, the more opaque you are12private alias object.value1 : object.transparency1314private alias 0 : FORCEFIELD_SOLID15private alias 1 : FORCEFIELD_WAITFORPLAYER16private alias 2 : FORCEFIELD_FADEIN17private alias 3 : FORCEFIELD_ACTIVE1819// Player Aliases20private alias object.xpos : player.xpos21private alias object.xvel : player.xvel22private alias object.speed : player.speed23private alias object.direction : player.direction242526// ========================27// Function Declarations28// ========================2930reserve function ForceField_DebugDraw31reserve function ForceField_DebugSpawn323334// ========================35// Function Definitions36// ========================3738private function ForceField_DebugDraw39// Backup a few values40temp6 = object.inkEffect41temp7 = object.alpha4243// Turn the object into an alpha blending one44object.inkEffect = INK_ADD4546temp1 = oscillation47temp1 <<= 248Sin(temp0, temp1)49object.alpha = temp050object.alpha >>= 551object.alpha += 0x5052DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)53DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)5455object.alpha = temp056object.alpha >>= 557object.alpha += 0x9058DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)59DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)6061object.alpha = temp062object.alpha >>= 463object.alpha += 0xC064DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)6566// Restore those backed up values from earlier67object.alpha = temp768object.inkEffect = temp669end function707172private function ForceField_DebugSpawn73CreateTempObject(TypeName[Force Field], 0, object.xpos, object.ypos)74object[tempObjectPos].drawOrder = 575object[tempObjectPos].inkEffect = INK_ADD76end function777879// ========================80// Events81// ========================8283event ObjectUpdate84switch object.state85case FORCEFIELD_SOLID86// Active - simply act as a box87foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)88BoxCollisionTest(C_SOLID, object.entityPos, -8, -80, 8, 80, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)89next90break9192case FORCEFIELD_WAITFORPLAYER93// Check if the player is 64 pixels past the right of this94temp0 = object.xpos95temp0 += 0x40000096if player[0].xpos > temp097object.state = FORCEFIELD_FADEIN98end if99break100101case FORCEFIELD_FADEIN102// "Fading in" state where force field starts force fielding103if object.transparency > 0104object.transparency--105else106object.state = FORCEFIELD_ACTIVE107end if108break109110case FORCEFIELD_ACTIVE111temp0 = object.xpos112temp0 += 0x160000113114foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)115if player[currentPlayer].xpos < temp0116BoxCollisionTest(C_TOUCH, object.entityPos, -256, -80, 8, 80, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)117if checkResult == true118if player[currentPlayer].xvel < 0x20000119player[currentPlayer].xvel = 0x20000120player[currentPlayer].speed = 0x20000121player[currentPlayer].direction = FACING_RIGHT122end if123end if124else125BoxCollisionTest(C_SOLID, object.entityPos, -8, -80, 8, 80, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)126end if127next128break129130end switch131end event132133134event ObjectDraw135temp1 = oscillation136temp1 <<= 2137Sin(temp0, temp1)138object.alpha = temp0139object.alpha >>= 5140object.alpha += 0x50141object.alpha >>= object.transparency142DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)143DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)144145object.alpha = temp0146object.alpha >>= 5147object.alpha += 0x90148object.alpha >>= object.transparency149DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)150DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)151152object.alpha = temp0153object.alpha >>= 4154object.alpha += 0xC0155object.alpha >>= object.transparency156DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)157end event158159160event ObjectStartup161LoadSpriteSheet("SBZ/Objects.gif")162163// Force Field frames164SpriteFrame(-8, -72, 2, 144, 382, 266)165SpriteFrame(-6, -72, 3, 144, 384, 266)166SpriteFrame(-3, -72, 6, 144, 387, 266)167SpriteFrame(3, -72, 3, 144, 393, 266)168SpriteFrame(6, -72, 2, 144, 396, 266)169170// Set up values for every Force Field object171foreach (TypeName[Force Field], arrayPos0, ALL_ENTITIES)172object[arrayPos0].drawOrder = 5173object[arrayPos0].inkEffect = INK_ADD174175if object[arrayPos0].propertyValue == 1176object[arrayPos0].state = FORCEFIELD_WAITFORPLAYER177object[arrayPos0].transparency = 10178end if179next180181// Add the object to the debug mode item list182SetTableValue(TypeName[Force Field], DebugMode_ObjCount, DebugMode_TypesTable)183SetTableValue(ForceField_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)184SetTableValue(ForceField_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)185DebugMode_ObjCount++186end event187188189// ========================190// Editor Events191// ========================192193event RSDKEdit194if editor.returnVariable == true195switch editor.variableID196case EDIT_VAR_PROPVAL // property value197checkResult = object.propertyValue198checkResult &= 3199break200201case 0 // type202checkResult = object.propertyValue203checkResult &= 3204break205206end switch207else208switch editor.variableID209case EDIT_VAR_PROPVAL // property value210object.propertyValue = editor.variableValue211object.propertyValue &= 3212break213214case 0 // type215object.propertyValue = editor.variableValue216object.propertyValue &= 3217break218219end switch220end if221end event222223224event RSDKDraw225object.inkEffect = INK_ADD226if object.propertyValue == 1227object.transparency = 10228else229object.transparency = 0230end if231232Sin(temp0, 0)233object.alpha = temp0234object.alpha >>= 5235object.alpha += 0x50236object.alpha >>= object.transparency237DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)238DrawSpriteFX(4, FX_INK, object.xpos, object.ypos)239240object.alpha = temp0241object.alpha >>= 5242object.alpha += 0x90243object.alpha >>= object.transparency244DrawSpriteFX(1, FX_INK, object.xpos, object.ypos)245DrawSpriteFX(3, FX_INK, object.xpos, object.ypos)246247object.alpha = temp0248object.alpha >>= 4249object.alpha += 0xC0250object.alpha >>= object.transparency251DrawSpriteFX(2, FX_INK, object.xpos, object.ypos)252end event253254255event RSDKLoad256LoadSpriteSheet("SBZ/Objects.gif")257SpriteFrame(-8, -72, 2, 144, 382, 266)258SpriteFrame(-6, -72, 3, 144, 384, 266)259SpriteFrame(-3, -72, 6, 144, 387, 266)260SpriteFrame(3, -72, 3, 144, 393, 266)261SpriteFrame(6, -72, 2, 144, 396, 266)262263AddEditorVariable("type")264SetActiveVariable("type")265AddEnumVariable("Always Active", 0)266AddEnumVariable("Active On Enter", 1)267end event268269270