Path: blob/master/Sonic 2/Scripts/Global/Springboard.txt
1478 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Springboard Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.bounceDelay12private alias object.value1 : object.force // unused (set but never actually used properly, which funnily enough is how it works in the original S2 too)13private alias object.value2 : object.activePlayers1415// Player Aliases16private alias object.state : player.state17private alias object.xpos : player.xpos18private alias object.ypos : player.ypos19private alias object.iypos : player.iypos20private alias object.xvel : player.xvel21private alias object.yvel : player.yvel22private alias object.speed : player.speed23private alias object.gravity : player.gravity24private alias object.frame : player.frame25private alias object.prevAnimation : player.prevAnimation26private alias object.animationSpeed : player.animationSpeed27private alias object.animation : player.animation28private alias object.collisionBottom : player.collisionBottom29private alias object.tileCollisions : player.tileCollisions30private alias object.value1 : player.timer31private alias object.value10 : player.animationReserve32private alias object.value17 : debugMode.currentSelection33private alias object.value25 : player.gravityStrength343536// ========================37// Function Declarations38// ========================3940reserve function Springboard_DebugDraw41reserve function Springboard_DebugSpawn424344// ========================45// Static Values46// ========================4748private value Springboard_debugStartID = 0495051// ========================52// Tables53// ========================5455// tech56private table Springboard_springForceTable57-0x40000, -0xA0000, -0x8000058end table5960private table Springboard_springPowerTable610x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x0000062-0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x1000063-0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x10000, -0x1000064-0x20000, -0x20000, -0x20000, -0x20000, -0x20000, -0x20000, -0x20000, -0x2000065-0x30000, -0x30000, -0x30000, -0x30000, -0x30000, -0x30000, -0x40000, -0x4000066end table6768private table Springboard_heightsReadyTable698, 9, 10, 11, 12, 13, 147015, 16, 16, 17, 18, 19, 207120, 21, 21, 22, 23, 24, 247224, 24, 24, 24, 24, 24, 2473end table7475private table Springboard_heightsFlatTable768, 9, 10, 11, 12, 12, 127712, 13, 13, 13, 13, 13, 137814, 14, 15, 15, 16, 16, 167916, 15, 15, 14, 14, 13, 1380end table818283// ========================84// Function Definitions85// ========================8687private function Springboard_DebugDraw88DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)89end function909192private function Springboard_DebugSpawn93temp0 = debugMode[0].currentSelection94temp0 -= Springboard_debugStartID95CreateTempObject(TypeName[Springboard], 0, object.xpos, object.ypos)96GetTableValue(object[tempObjectPos].force, temp0, Springboard_springForceTable) // doesn't really mean anything since object.force is unused97object[tempObjectPos].direction = object.direction98end function99100101// ========================102// Events103// ========================104105event ObjectUpdate106if object.bounceDelay != 0107object.bounceDelay--108switch object.bounceDelay109case 0110temp2 = 0111foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)112GetBit(temp3, object.activePlayers, temp2)113if temp3 == true114temp0 = player[currentPlayer].xpos115temp0 -= object.xpos116temp0 += 0x1C0000117temp0 >>= 17118GetBit(temp3, object.direction, 0)119if temp3 == FLIP_X120temp0 -= 28121FlipSign(temp0)122end if123124if temp0 >= 8125player[currentPlayer].animationReserve = ANI_WALKING126if player[currentPlayer].animation == ANI_RUNNING127player[currentPlayer].animationReserve = ANI_RUNNING128end if129130if player[currentPlayer].animation == ANI_PEELOUT131player[currentPlayer].animationReserve = ANI_PEELOUT132end if133134object.bounceDelay = 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].xvel144temp0 -= 8145temp0 <<= 1146if temp0 > 39147temp0 = 39148end if149150GetTableValue(player[currentPlayer].yvel, temp0, Springboard_springPowerTable)151player[currentPlayer].yvel -= 0x40000 // constant in place of object.force (see ObjectStartup)152player[currentPlayer].yvel -= player[currentPlayer].gravityStrength153player[currentPlayer].animation = ANI_TWIRL154player[currentPlayer].prevAnimation = ANI_TWIRL155player[currentPlayer].frame = 0156player[currentPlayer].animationSpeed = 80157player[currentPlayer].timer = 0158PlaySfx(SfxName[Spring], false)159end if160end if161temp2++162next163break164165case 1166object.frame = 0167break168169default170object.frame = 1171break172173end switch174end if175176temp2 = 0177foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)178temp0 = player[currentPlayer].xpos179temp0 -= object.xpos180temp0 += 0x1C0000181temp0 >>= 17182if temp0 < 0183temp0 = 0184end if185if temp0 > 27186temp0 = 27187end if188189switch object.direction190case FLIP_NONE191if object.frame == 0192GetTableValue(temp1, temp0, Springboard_heightsReadyTable)193else194GetTableValue(temp1, temp0, Springboard_heightsFlatTable)195end if196197FlipSign(temp1)198temp4 = player[currentPlayer].speed199temp5 = player[currentPlayer].xpos200BoxCollisionTest(C_SOLID, object.entityPos, -28, temp1, 28, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)201switch checkResult202case COL_LEFT203player[currentPlayer].speed = temp4204player[currentPlayer].xpos = temp5205// [Fallthrough]206case COL_NONE207case COL_RIGHT208case COL_BOTTOM209GetBit(temp3, object.activePlayers, temp2)210if temp3 == true211temp3 = player[currentPlayer].xpos212temp3 -= object.xpos213temp3 >>= 16214Abs(temp3)215if temp3 < 28216if player[currentPlayer].yvel >= 0217player[currentPlayer].iypos = player[currentPlayer].collisionBottom218FlipSign(player[currentPlayer].ypos)219temp1 <<= 16220player[currentPlayer].ypos += temp1221player[currentPlayer].ypos += object.ypos222checkResult = true223end if224end if225end if226break227end switch228break229230case FLIP_X231temp0 -= 27232Abs(temp0)233if object.frame == 0234GetTableValue(temp1, temp0, Springboard_heightsReadyTable)235else236GetTableValue(temp1, temp0, Springboard_heightsFlatTable)237end if238239FlipSign(temp1)240temp4 = player[currentPlayer].speed241temp5 = player[currentPlayer].xpos242BoxCollisionTest(C_SOLID, object.entityPos, -28, temp1, 28, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)243switch checkResult244case COL_RIGHT245player[currentPlayer].speed = temp4246player[currentPlayer].xpos = temp5247// [Fallthrough]248case COL_NONE249case COL_LEFT250case COL_TOP251GetBit(temp3, object.activePlayers, temp2)252if temp3 == true253temp3 = player[currentPlayer].xpos254temp3 -= object.xpos255temp3 >>= 16256Abs(temp3)257if temp3 < 28258if player[currentPlayer].yvel >= 0259player[currentPlayer].iypos = player[currentPlayer].collisionBottom260FlipSign(player[currentPlayer].ypos)261temp1 <<= 16262player[currentPlayer].ypos += temp1263player[currentPlayer].ypos += object.ypos264checkResult = true265end if266end if267end if268break269end switch270break271272// Sorry, no upside-down Springboards..273case FLIP_Y274break275276case FLIP_XY277break278279end switch280281if checkResult == true282SetBit(object.activePlayers, temp2, true)283if temp0 >= 8284if object.bounceDelay == 0285object.bounceDelay = 6286end if287end if288else289SetBit(object.activePlayers, temp2, false)290end if291292temp2++293next294end event295296297event ObjectDraw298DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)299end event300301302event ObjectStartup303LoadSpriteSheet("Global/Items.gif")304305foreach (TypeName[Springboard], arrayPos0, ALL_ENTITIES)306// This part is... weird307// For one, where is this temp0 coming from?308// Here's some fun little notes309// - This object was definitely scripted using the original game's asm as reference, seeing that the two's code are pretty similar310// - In the original S2, the object would get a force value based on (subtype & 2)311// - However, even with that, the force value would never get read and a force of 0x40000 (the first entry on the table) would be used all the time instead312// - For some reason, it looks like they decided to do the same thing in this remake?313// - They still have the same force table, they still get the force value and store it, and they even still force a force of 0x40000 in the actual script too314// - this whole situation is kinda really confusing, but at the very least we can guess that temp0 was like315// GetBit(temp0, object.propertyValue, 1)316// - Or something like that (in the original game bit 0 was useTwirlAnim and the second bit would be force)317318GetTableValue(object[arrayPos0].force, temp0, Springboard_springForceTable)319next320321// One of the rare instances of code being between the sprite sheet and Sprite Frames, a Springboard only has two frames322SpriteFrame(-28, -24, 56, 16, 52, 160)323SpriteFrame(-28, -16, 56, 8, 52, 177)324325temp0 = 0326Springboard_debugStartID = DebugMode_ObjCount327while temp0 < 3328SetTableValue(TypeName[Springboard], DebugMode_ObjCount, DebugMode_TypesTable)329SetTableValue(Springboard_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)330SetTableValue(Springboard_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)331DebugMode_ObjCount++332temp0++333loop334end event335336337// ========================338// Editor Events339// ========================340341event RSDKDraw342DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)343end event344345346event RSDKLoad347LoadSpriteSheet("Global/Items.gif")348SpriteFrame(-28, -24, 56, 16, 52, 160)349350// dir is attr to set from scene, prop val is unused even if it is set sometimes (in the original game it was force/useTwirlAnim)351SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")352end event353354355