Swinging Vines with a Sync parameter

Version:

1.0

Added on:

06 Aug 2018 01: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.
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.

void onLevelLoad() {
  jjObjectPresets[OBJECT::SWINGINGVINE].behavior = SyncedVine;
}

void SyncedVine(jjOBJ@ obj) {
  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.
  
  if (lastSwingingVineLUTLength != obj.var[1]) { //need to generate LUT (LookUp Table) by doing the same math swinging vine objects do
    lastSwingingVineLUTLength = obj.var[1];
    PossibleVineVariableConfigurations = array<array<int>> = {{obj.var[1] * 256, 0}};
    while (true) {
      const array<int>@ oldConfiguration = @PossibleVineVariableConfigurations[PossibleVineVariableConfigurations.length-1];
      array<int> newConfiguration(2);
      newConfiguration[1] = oldConfiguration[1] + ((oldConfiguration[0] > 0) ? -32 : 32);
      newConfiguration[0] = oldConfiguration[0] + newConfiguration[1];
      if (newConfiguration[1] == 0 && newConfiguration[0] == obj.var[1] * 256) //gone full circle
        break;
      PossibleVineVariableConfigurations.insertLast(newConfiguration);
    }
  }
  
  const array<int>@ syncedConfiguration = PossibleVineVariableConfigurations[(jjGameTicks + (jjParameterGet(uint(obj.xOrg) >> 5, uint(obj.yOrg) >> 5, 0, NumberOfBitsDevotedToSyncParameter) * (PossibleVineVariableConfigurations.length / (1 << NumberOfBitsDevotedToSyncParameter)))) % PossibleVineVariableConfigurations.length];
  for (uint i = 0; i < 2; ++i)
    obj.var[2 + i] = syncedConfiguration[i];
    
  //clean up:
  obj.state = STATE::ACTION;
  obj.behavior = BEHAVIOR::SWINGINGVINE;
  obj.behave();
}
int lastSwingingVineLUTLength = -1;
array<array<int>> PossibleVineVariableConfigurations;