Path: blob/main/Scripts/R7/RPlatform.txt
1319 views
//-----------------Sonic CD R Platform Script-----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.Angle6#alias Object.Value1 : Object.PlatformX7#alias Object.Value2 : Object.PlatformY8#alias Object.Value3 : Object.ChangeX9#alias Object.Value4 : Object.ChangeY10#alias Object.Value5 : Object.SwingAngle11#alias Object.Value6 : Object.ChainsNo1213// States14#alias 0 : RPLATFORM_FULL_CW_SLOWAPEX15#alias 1 : RPLATFORM_FULL_CW16#alias 2 : RPLATFORM_FULL_CCW17#alias 3 : RPLATFORM_TOP18018#alias 4 : RPLATFORM_RIGHT18019#alias 5 : RPLATFORM_BOTTOM1802021// Collision22#alias 1 : PLAYER_COL_FLOOR23#alias 2 : PLAYER_COL_LWALL24#alias 3 : PLAYER_COL_RWALL25#alias 4 : PLAYER_COL_ROOF2627// Property Values28#alias 19 : HALF_CW_BOTTOM29#alias 35 : HALF_CW_TOP30#alias 54 : FULL_CW_SLOW31#alias 67 : HALF_CW_RIGHT32#alias 99 : FULL_CW33#alias 115: FULL_CCW3435// Gravity36#alias 0 : GRAVITY_GROUND373839sub ObjectMain40// Each state directly corresponds to a subtype of the platform41switch Object.State42case RPLATFORM_FULL_CW_SLOWAPEX43Object.SwingAngle++44Object.SwingAngle &= 51145Sin(Object.Angle, Object.SwingAngle)46Object.Angle /= 347Object.Angle += 64048break4950case RPLATFORM_FULL_CW51Object.SwingAngle++52Object.SwingAngle &= 51153TempValue0 = Object.SwingAngle54TempValue0 >>= 155Cos(TempValue1, TempValue0)56TempValue1 >>= 157Object.Angle = 64058Object.Angle -= TempValue159break6061case RPLATFORM_FULL_CCW62Object.SwingAngle++63Object.SwingAngle &= 51164TempValue0 = Object.SwingAngle65TempValue0 >>= 166Cos(Object.Angle, TempValue0)67Object.Angle >>= 168Object.Angle += 64069break7071case RPLATFORM_TOP18072Object.SwingAngle++73Object.SwingAngle &= 51174Sin(Object.Angle, Object.SwingAngle)75Object.Angle >>= 276Object.Angle += 89677break7879case RPLATFORM_RIGHT18080Object.SwingAngle++81Object.SwingAngle &= 51182Sin(Object.Angle, Object.SwingAngle)83Object.Angle >>= 284Object.Angle += 51285break8687case RPLATFORM_BOTTOM18088Object.SwingAngle++89Object.SwingAngle &= 51190Sin(Object.Angle, Object.SwingAngle)91Object.Angle >>= 292Object.Angle += 64093break9495end switch9697TempValue1 = Object.ChainsNo98TempValue1++99TempValue1 <<= 4100101Cos(Object.ChangeX, Object.Angle)102Object.ChangeX *= TempValue1103Object.ChangeX <<= 7104Object.ChangeX += Object.XPos105Object.ChangeX &= 0xFFFF0000 // Truncate the value106Object.ChangeX -= Object.PlatformX107108Sin(Object.ChangeY, Object.Angle)109Object.ChangeY *= TempValue1110Object.ChangeY <<= 7111Object.ChangeY += Object.YPos112Object.ChangeY &= 0xFFFF0000 // Truncate the value113Object.ChangeY -= Object.PlatformY114115end sub116117118sub ObjectPlayerInteraction119// First backup the object's position120TempValue0 = Object.XPos121TempValue1 = Object.YPos122123TempValue2 = Player.YPos124Object.XPos = Object.PlatformX125Object.YPos = Object.PlatformY126127if Player.State == Player_State_Hurt128PlayerObjectCollision(C_BOX, -32, -8, 32, 8)129else130PlayerObjectCollision(C_BOX, -24, -8, 24, 8)131end if132133switch CheckResult134case PLAYER_COL_FLOOR135// The player's on top of the platform, just move them with it for now136Player.XPos += Object.ChangeX137Player.YPos += Object.ChangeY138break139140case PLAYER_COL_LWALL141case PLAYER_COL_RWALL142CallFunction(Player_Hit)143144// [Fallthrough to below, for more collision checks]145146case PLAYER_COL_ROOF147PlayerObjectCollision(C_TOUCH, -16, -8, 16, 9)148149if CheckResult == true150if Player.State != Player_State_Hurt151TempValue3 = Player.XVelocity152if TempValue3 < 0153FlipSign(TempValue3)154end if155156if TempValue3 < 0x60000157if Player.Gravity == GRAVITY_GROUND158CallFunction(Player_Kill)159end if160else161if Player.Gravity == GRAVITY_GROUND162CallFunction(Player_Hit)163end if164end if165else166Player.YPos = TempValue2167end if168else169Player.YPos = TempValue2170171if Player.Gravity == GRAVITY_GROUND172CallFunction(Player_Hit)173end if174end if175break176177end switch178179// Now we can restore the Object back to its normal position180Object.XPos = TempValue0181Object.YPos = TempValue1182183end sub184185186sub ObjectDraw187// Draw the platform post frame188DrawSprite(0)189190// Draw all the chains191TempValue0 = 0192TempValue1 = 16193while TempValue0 < Object.ChainsNo194Cos(TempValue2, Object.Angle)195TempValue2 *= TempValue1196TempValue2 <<= 7197TempValue2 += Object.XPos198199Sin(TempValue3, Object.Angle)200TempValue3 *= TempValue1201TempValue3 <<= 7202TempValue3 += Object.YPos203204DrawSpriteXY(1, TempValue2, TempValue3)205206TempValue0++207TempValue1 += 16208loop209210// Draw the main platform sprite211212// Find the X component213Cos(Object.PlatformX, Object.Angle)214Object.PlatformX *= TempValue1215Object.PlatformX <<= 7216Object.PlatformX += Object.XPos217Object.PlatformX &= 0xFFFF0000 // Truncate the value218219// And then find the Y220Sin(Object.PlatformY, Object.Angle)221Object.PlatformY *= TempValue1222Object.PlatformY <<= 7223Object.PlatformY += Object.YPos224Object.PlatformY &= 0xFFFF0000 // Truncate the value225226DrawSpriteXY(2, Object.PlatformX, Object.PlatformY)227228end sub229230231sub ObjectStartup232233LoadSpriteSheet("R7/Objects.gif")234235// Pivot Ball Frame236SpriteFrame(-8, -8, 16, 16, 34, 1)237238// Chain Frame239SpriteFrame(-8, -8, 16, 16, 51, 1)240241// Platform Frame242SpriteFrame(-32, -8, 64, 16, 68, 1)243244ArrayPos0 = 32245while ArrayPos0 < 1056246if Object[ArrayPos0].Type == TypeName[R Platform]247if Object[ArrayPos0].PropertyValue == HALF_CW_BOTTOM248Object[ArrayPos0].State = RPLATFORM_BOTTOM180249Object[ArrayPos0].ChainsNo = 2250end if251252if Object[ArrayPos0].PropertyValue == HALF_CW_TOP253Object[ArrayPos0].State = RPLATFORM_TOP180254Object[ArrayPos0].ChainsNo = 2255end if256257if Object[ArrayPos0].PropertyValue == FULL_CW_SLOW258Object[ArrayPos0].State = RPLATFORM_FULL_CW_SLOWAPEX259Object[ArrayPos0].ChainsNo = 5260end if261262if Object[ArrayPos0].PropertyValue == HALF_CW_RIGHT263Object[ArrayPos0].State = RPLATFORM_RIGHT180264Object[ArrayPos0].ChainsNo = 2265end if266267if Object[ArrayPos0].PropertyValue == FULL_CW268Object[ArrayPos0].State = RPLATFORM_FULL_CW269Object[ArrayPos0].ChainsNo = 2270end if271272if Object[ArrayPos0].PropertyValue == FULL_CCW273Object[ArrayPos0].State = RPLATFORM_FULL_CCW274Object[ArrayPos0].ChainsNo = 2275end if276end if277278ArrayPos0++279loop280281end sub282283284// ========================285// Editor Subs286// ========================287288// the property value format seems to be289// lowest three bits - chain length290// above - multiplier idk291// but thanks to the way the object's set up, it doesn't truly work like that292// it is worth noting though, that while rsdk uses this rigid and kinda fake system, cd 93 seems to *actually* follow the format so that's interesting293294sub RSDKEdit295if Editor.ReturnVariable == true296switch Editor.VariableID297case EDIT_VAR_PROPVAL // Property Value298CheckResult = Object.PropertyValue299break300case 0 // Type301CheckResult = Object.PropertyValue302break303end switch304else305switch Editor.VariableID306case EDIT_VAR_PROPVAL // Property Value307Object.PropertyValue = Editor.VariableValue308break309case 0 // Type310Object.PropertyValue = Editor.VariableValue311break312end switch313end if314end sub315316// TODO: probably best to rearrange the temps used here, at the moment it's quite the mess...317318sub RSDKDraw319320TempValue4 = 0 // chainsNo321TempValue1 = 0 // behaviour322323switch Object.PropertyValue324case 19325default326TempValue4 = 2327TempValue1 = 5328break329case 35330TempValue4 = 2331TempValue1 = 3332break333case 54334TempValue4 = 5335TempValue1 = 0336break337case 67338TempValue4 = 2339TempValue1 = 4340break341case 99342TempValue4 = 2343TempValue1 = 1344break345case 115346TempValue4 = 2347TempValue1 = 2348break349end switch350351switch TempValue1352case 0353case 1354case 2355case 5356Object.Angle = 640; break357case 3358Object.Angle = 896; break359case 4360Object.Angle = 512; break361end switch362363DrawSprite(0)364365TempValue0 = 0366TempValue1 = 16367while TempValue0 < TempValue4368Cos(TempValue2, Object.Angle)369TempValue2 *= TempValue1370TempValue2 <<= 7371TempValue2 += Object.XPos372373Sin(TempValue3, Object.Angle)374TempValue3 *= TempValue1375TempValue3 <<= 7376TempValue3 += Object.YPos377378DrawSpriteXY(1, TempValue2, TempValue3)379380TempValue0++381TempValue1 += 16382loop383384Cos(TempValue0, Object.Angle)385TempValue0 *= TempValue1386TempValue0 <<= 7387TempValue0 += Object.XPos388TempValue0 &= 0xFFFF0000 // Truncate the value389390Sin(TempValue2, Object.Angle)391TempValue2 *= TempValue1392TempValue2 <<= 7393TempValue2 += Object.YPos394TempValue2 &= 0xFFFF0000 // Truncate the value395396DrawSpriteXY(2, TempValue0, TempValue2)397end sub398399400sub RSDKLoad401LoadSpriteSheet("R7/Objects.gif")402SpriteFrame(-8, -8, 16, 16, 34, 1) // Pivot Ball403SpriteFrame(-8, -8, 16, 16, 51, 1) // Chain404SpriteFrame(-32, -8, 64, 16, 68, 1) // Platform405406// TODO: actual names lol407AddEditorVariable("Type")408SetActiveVariable("Type")409AddEnumVariable("why do", 19)410AddEnumVariable("the values", 35)411AddEnumVariable("jump around", 54)412AddEnumVariable("its so", 67)413AddEnumVariable("wierd", 99)414AddEnumVariable("ratio", 115)415end sub416417418