Path: blob/master/Sonic 1/Scripts/Global/RedSpring.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Red Spring 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.isPlatform13private alias object.value7 : object.enabledInAir1415// Player aliases16private alias object.state : player.state17private alias object.direction : player.direction18private alias object.xvel : player.xvel19private alias object.yvel : player.yvel20private alias object.speed : player.speed21private alias object.angle : player.angle22private alias object.controlLock : player.controlLock23private alias object.pushing : player.pushing24private alias object.animation : player.animation25private alias object.animationSpeed : player.animationSpeed26private alias object.gravity : player.gravity27private alias object.collisionMode : player.collisionMode28private alias object.tileCollisions : player.tileCollisions29private alias object.value1 : player.timer30private alias object.value10 : player.animationReserve31private alias object.value17 : debugMode.currentSelection3233// ========================34// Function Declarations35// ========================3637reserve function RedSpring_DebugDraw38reserve function RedSpring_DebugSpawn394041// ========================42// Static Values43// ========================4445private value RedSpring_startDebugID = 0464748// ========================49// Function Declarations50// ========================5152private function RedSpring_DebugDraw53temp0 = debugMode[0].currentSelection54temp0 -= RedSpring_startDebugID5556DrawSprite(temp0)5758temp0 += 459DrawSprite(temp0)60end function616263private function RedSpring_DebugSpawn64temp0 = debugMode[0].currentSelection65temp0 -= RedSpring_startDebugID6667CreateTempObject(TypeName[Red Spring], temp0, object.xpos, object.ypos)68end function697071// ========================72// Events73// ========================7475event ObjectUpdate76foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)77switch object.propertyValue78case 0 // Up79temp0 = object.isPlatform80if player[currentPlayer].gravity == GRAVITY_AIR81temp0 = true82end if8384if player[currentPlayer].collisionMode > CMODE_FLOOR85if player[currentPlayer].yvel < 086temp0 = true87end if88end if8990if temp0 == false91BoxCollisionTest(C_SOLID, object.entityPos, -14, -8, 14, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)9293BoxCollisionTest(C_TOUCH, object.entityPos, -14, -10, 14, -6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)94if checkResult == true95player[currentPlayer].animationReserve = ANI_WALKING96if player[currentPlayer].animation == ANI_RUNNING97player[currentPlayer].animationReserve = ANI_RUNNING98end if99100if player[currentPlayer].animation == ANI_PEELOUT101player[currentPlayer].animationReserve = ANI_PEELOUT102end if103104object.timer = 1105#platform: USE_STANDALONE106player[currentPlayer].state = Player_State_Air107#endplatform108#platform: USE_ORIGINS109player[currentPlayer].state = Player_State_Air_NoDropDash110#endplatform111player[currentPlayer].tileCollisions = true112player[currentPlayer].gravity = GRAVITY_AIR113player[currentPlayer].speed = player[currentPlayer].xvel114player[currentPlayer].yvel = -0x100000115player[currentPlayer].animation = ANI_BOUNCING116player[currentPlayer].timer = 0117PlaySfx(SfxName[Spring], false)118end if119else120if player[currentPlayer].yvel >= 0121BoxCollisionTest(C_PLATFORM, object.entityPos, -14, -8, 14, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)122123BoxCollisionTest(C_TOUCH, object.entityPos, -14, -10, 14, -6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)124if checkResult == true125player[currentPlayer].animationReserve = ANI_WALKING126if player[currentPlayer].animation == ANI_RUNNING127player[currentPlayer].animationReserve = ANI_RUNNING128end if129130if player[currentPlayer].animation == ANI_PEELOUT131player[currentPlayer].animationReserve = ANI_PEELOUT132end if133134object.timer = 1135#platform: USE_STANDALONE136player[currentPlayer].state = Player_State_Air137#endplatform138#platform: USE_ORIGINS139player[currentPlayer].state = Player_State_Air_NoDropDash140#endplatform141player[currentPlayer].tileCollisions = true142player[currentPlayer].gravity = GRAVITY_AIR143player[currentPlayer].speed = player[currentPlayer].xvel144player[currentPlayer].yvel = -0x100000145player[currentPlayer].animation = ANI_BOUNCING146player[currentPlayer].timer = 0147PlaySfx(SfxName[Spring], false)148end if149end if150end if151break152153case 1 // Right154BoxCollisionTest(C_SOLID, object.entityPos, -8, -14, 8, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)155if player[currentPlayer].gravity == GRAVITY_GROUND156BoxCollisionTest(C_TOUCH, object.entityPos, 6, -14, 11, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)157if checkResult == true158object.timer = 1159player[currentPlayer].tileCollisions = true160player[currentPlayer].angle = 0161player[currentPlayer].speed = 0x100000162player[currentPlayer].collisionMode = CMODE_FLOOR163player[currentPlayer].pushing = 0164player[currentPlayer].direction = FACING_RIGHT165player[currentPlayer].controlLock = 12166PlaySfx(SfxName[Spring], false)167168if player[currentPlayer].state != Player_State_Roll169player[currentPlayer].state = Player_State_Ground170player[currentPlayer].animation = ANI_RUNNING171end if172end if173else174if object.enabledInAir == true175BoxCollisionTest(C_TOUCH, object.entityPos, 6, -4, 11, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)176if checkResult == true177object.timer = 1178player[currentPlayer].tileCollisions = true179player[currentPlayer].angle = 0180player[currentPlayer].speed = 0x100000181player[currentPlayer].yvel = 0182player[currentPlayer].collisionMode = CMODE_FLOOR183player[currentPlayer].pushing = 0184player[currentPlayer].direction = FACING_RIGHT185player[currentPlayer].controlLock = 12186PlaySfx(SfxName[Spring], false)187if player[currentPlayer].state != Player_State_RollJump188player[currentPlayer].animation = ANI_BOUNCING189if player[currentPlayer].animation != ANI_JUMPING190player[currentPlayer].animation = ANI_RUNNING191end if192193object.animationSpeed = object.speed194player[currentPlayer].animationSpeed *= 80195player[currentPlayer].animationSpeed /= 0x60000196end if197end if198end if199end if200break201202case 2 // Left203BoxCollisionTest(C_SOLID, object.entityPos, -8, -14, 8, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)204if player[currentPlayer].gravity == GRAVITY_GROUND205BoxCollisionTest(C_TOUCH, object.entityPos, -10, -14, -6, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)206if checkResult == true207object.timer = 1208player[currentPlayer].tileCollisions = true209player[currentPlayer].speed = -0x100000210player[currentPlayer].collisionMode = CMODE_FLOOR211player[currentPlayer].pushing = 0212player[currentPlayer].direction = FACING_LEFT213player[currentPlayer].controlLock = 15214PlaySfx(SfxName[Spring], false)215if player[currentPlayer].state != Player_State_Roll216player[currentPlayer].state = Player_State_Ground217player[currentPlayer].animation = ANI_RUNNING218end if219end if220else221if object.enabledInAir == true222BoxCollisionTest(C_TOUCH, object.entityPos, -10, -14, -6, 14, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)223if checkResult == true224object.timer = 1225player[currentPlayer].tileCollisions = true226player[currentPlayer].speed = -0x100000227player[currentPlayer].yvel = 0228player[currentPlayer].collisionMode = CMODE_FLOOR229player[currentPlayer].pushing = 0230player[currentPlayer].direction = FACING_LEFT231player[currentPlayer].controlLock = 15232PlaySfx(SfxName[Spring], false)233if player[currentPlayer].state != Player_State_RollJump234player[currentPlayer].animation = ANI_BOUNCING235if player[currentPlayer].animation != ANI_JUMPING236player[currentPlayer].animation = ANI_RUNNING237end if238239object.animationSpeed = object.speed240FlipSign(player[currentPlayer].animationSpeed)241player[currentPlayer].animationSpeed *= 80242player[currentPlayer].animationSpeed /= 0x60000243end if244end if245end if246end if247break248249case 3 // Down250BoxCollisionTest(C_SOLID, object.entityPos, -14, -8, 14, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)251if player[currentPlayer].yvel <= 0252BoxCollisionTest(C_TOUCH, object.entityPos, -14, 6, 14, 10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)253if checkResult == true254if player[currentPlayer].collisionMode == CMODE_ROOF255FlipSign(player[currentPlayer].speed)256FlipSign(player[currentPlayer].xvel)257end if258259object.timer = 1260#platform: USE_STANDALONE261player[currentPlayer].state = Player_State_Air262#endplatform263#platform: USE_ORIGINS264player[currentPlayer].state = Player_State_Air_NoDropDash265#endplatform266player[currentPlayer].tileCollisions = true267player[currentPlayer].gravity = GRAVITY_AIR268player[currentPlayer].speed = player[currentPlayer].xvel269player[currentPlayer].yvel = 0x100000270player[currentPlayer].timer = 0271PlaySfx(SfxName[Spring], false)272end if273end if274break275276end switch277next278end event279280281event ObjectDraw282if object.timer == 0283temp1 = object.propertyValue284DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)285temp1 += 4286DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)287else288switch object.timer289case 2290case 3291temp1 = object.propertyValue292DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)293temp1 += 4294DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)295break296297case 1298temp1 = object.propertyValue299temp1 += 8300DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)301break302303case 4304case 5305case 6306case 7307case 8308case 9309temp1 = object.propertyValue310temp1 += 12311DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)312temp1 += 4313DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)314break315316end switch317318object.timer++319if object.timer >= 10320object.timer = 0321end if322end if323end event324325326event ObjectStartup327LoadSpriteSheet("Global/Items.gif")328329arrayPos0 = 0x20330while arrayPos0 < 0x420331if object[arrayPos0].type == TypeName[Red Spring]332if object[arrayPos0].propertyValue > 3333object[arrayPos0].propertyValue -= 4334object[arrayPos0].enabledInAir = true335end if336337// leftover from CD's spring script, this is supposed to be setup for downwards diag springs but s1 doesn't really have those338if object[arrayPos0].propertyValue > 5339object[arrayPos0].direction = FLIP_Y340end if341end if342343arrayPos0++344loop345346SpriteFrame(-16, 0, 32, 8, 84, 9)347SpriteFrame(-8, -16, 8, 32, 141, 26)348SpriteFrame(0, -16, 8, 32, 141, 59)349SpriteFrame(-16, -8, 32, 8, 150, 101)350351SpriteFrame(-16, -8, 32, 8, 84, 1)352SpriteFrame(0, -16, 8, 32, 149, 26)353SpriteFrame(-8, -16, 8, 32, 133, 59)354SpriteFrame(-16, 0, 32, 8, 150, 109)355356SpriteFrame(-16, 0, 32, 8, 84, 1)357SpriteFrame(-8, -16, 8, 32, 149, 26)358SpriteFrame(0, -16, 8, 32, 133, 59)359SpriteFrame(-16, -8, 32, 8, 150, 109)360361SpriteFrame(-16, -16, 32, 24, 117, 1)362SpriteFrame(-8, -16, 24, 32, 158, 26)363SpriteFrame(-16, -16, 24, 32, 158, 59)364SpriteFrame(-16, -8, 32, 24, 150, 1)365366SpriteFrame(-16, -24, 32, 8, 84, 1)367SpriteFrame(16, -16, 8, 32, 149, 26)368SpriteFrame(-24, -16, 8, 32, 133, 59)369SpriteFrame(-16, 16, 32, 8, 150, 109)370371temp0 = 0372RedSpring_startDebugID = DebugMode_ObjCount373while temp0 < 4374SetTableValue(TypeName[Red Spring], DebugMode_ObjCount, DebugMode_TypesTable)375SetTableValue(RedSpring_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)376SetTableValue(RedSpring_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)377DebugMode_ObjCount++378temp0++379loop380end event381382383// ========================384// Editor Events385// ========================386387event RSDKEdit388if editor.returnVariable == true389switch editor.variableID390case EDIT_VAR_PROPVAL // property value391checkResult = object.propertyValue392break393394case 0 // flipFlags395checkResult = object.propertyValue396checkResult &= 3397break398399case 1 // enabledInAir400GetBit(checkResult, object.propertyValue, 3)401break402403end switch404else405switch editor.variableID406case EDIT_VAR_PROPVAL // property value407object.propertyValue = editor.variableValue408break409410case 0 // flipFlags411temp0 = 3412Not(temp0)413object.propertyValue &= temp0414editor.variableValue &= 3415416object.propertyValue |= editor.variableValue417break418419case 1 // enabledInAir420CheckNotEqual(editor.variableValue, false)421SetBit(object.propertyValue, 3, checkResult)422break423424end switch425end if426end event427428429event RSDKDraw430temp1 = object.propertyValue431temp1 &= 3432433DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)434435temp1 += 4436DrawSpriteFX(temp1, FX_FLIP, object.xpos, object.ypos)437end event438439440event RSDKLoad441LoadSpriteSheet("Global/Items.gif")442SpriteFrame(-16, 0, 32, 8, 84, 9)443SpriteFrame(-8, -16, 8, 32, 141, 26)444SpriteFrame(0, -16, 8, 32, 141, 59)445SpriteFrame(-16, -8, 32, 8, 150, 101)446447SpriteFrame(-16, -8, 32, 8, 84, 1)448SpriteFrame(0, -16, 8, 32, 149, 26)449SpriteFrame(-8, -16, 8, 32, 133, 59)450SpriteFrame(-16, 0, 32, 8, 150, 109)451452SpriteFrame(-16, 0, 32, 8, 84, 1)453SpriteFrame(-8, -16, 8, 32, 149, 26)454SpriteFrame(0, -16, 8, 32, 133, 59)455SpriteFrame(-16, -8, 32, 8, 150, 109)456457SpriteFrame(-16, -16, 32, 24, 117, 1)458SpriteFrame(-8, -16, 24, 32, 158, 26)459SpriteFrame(-16, -16, 24, 32, 158, 59)460SpriteFrame(-16, -8, 32, 24, 150, 1)461462SpriteFrame(-16, -24, 32, 8, 84, 1)463SpriteFrame(16, -16, 8, 32, 149, 26)464SpriteFrame(-24, -16, 8, 32, 133, 59)465SpriteFrame(-16, 16, 32, 8, 150, 109)466467AddEditorVariable("flipFlag")468SetActiveVariable("flipFlag")469AddEnumVariable("Up", 0)470AddEnumVariable("Right", 1)471AddEnumVariable("Left", 2)472AddEnumVariable("Down", 3)473474AddEditorVariable("enabledInAir")475SetActiveVariable("enabledInAir")476AddEnumVariable("false", false)477AddEnumVariable("true", true)478479SetVariableAlias(ALIAS_VAR_VAL1, "isPlatform")480481// scale is set to 256 (half) in mission M005 but it doesn't really mean anything lol482end event483484485