Swinging Vines with a Sync parameter

Version:

1.0

Added on:

06 Aug 2018 03:36

Tags:

Description:
Lets you add a Sync parameter to Swinging Vines in JCS.ini (or the MLLE equivalent), akin to the one on platforms and spike bolls, so that vines will reliably be at predictable positions relative to one another.
  1. const uint NumberOfBitsDevotedToSyncParameter = 3; //this should correspond to the number of bits you assign to the Sync parameter in your JCS.ini (or MLLE equivalent) entry for Swinging Vine. So for example if you give it a parameter Sync:2, this variable should ALSO equal 2.
  2.  
  3. void onLevelLoad() {
  4.   jjObjectPresets[OBJECT::SWINGINGVINE].behavior = SyncedVine;
  5. }
  6.  
  7. void SyncedVine(jjOBJ@ obj) {
  8.   obj.var[1] = 128; //vine length--set this in whatever way appeals to you, but a constant 128 is the value that normal swinging vines use.
  9.  
  10.   if (lastSwingingVineLUTLength != obj.var[1]) { //need to generate LUT (LookUp Table) by doing the same math swinging vine objects do
  11.     lastSwingingVineLUTLength = obj.var[1];
  12.     PossibleVineVariableConfigurations = array<array<int>> = {{obj.var[1] * 256, 0}};
  13.     while (true) {
  14.       const array<int>@ oldConfiguration = @PossibleVineVariableConfigurations[PossibleVineVariableConfigurations.length-1];
  15.       array<int> newConfiguration(2);
  16.       newConfiguration[1] = oldConfiguration[1] + ((oldConfiguration[0] > 0) ? -32 : 32);
  17.       newConfiguration[0] = oldConfiguration[0] + newConfiguration[1];
  18.       if (newConfiguration[1] == 0 && newConfiguration[0] == obj.var[1] * 256) //gone full circle
  19.         break;
  20.       PossibleVineVariableConfigurations.insertLast(newConfiguration);
  21.     }
  22.   }
  23.  
  24.   const array<int>@ syncedConfiguration = PossibleVineVariableConfigurations[(jjGameTicks + (jjParameterGet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0, NumberOfBitsDevotedToSyncParameter) * (PossibleVineVariableConfigurations.length / (1 << NumberOfBitsDevotedToSyncParameter)))) % PossibleVineVariableConfigurations.length];
  25.   for (uint i = 0; i < 2; ++i)
  26.     obj.var[2 + i] = syncedConfiguration[i];
  27.    
  28.   //clean up:
  29.   obj.state = STATE::ACTION;
  30.   obj.behavior = BEHAVIOR::SWINGINGVINE;
  31.   obj.behave();
  32. }
  33. int lastSwingingVineLUTLength = -1;
  34. array<array<int>> PossibleVineVariableConfigurations;