//************************************************************************************************** ROPE GENERATOR CREATE CODE //Rope Tables //These arrays contain X and Y offsets for the rope segments. Each offset is in respect of the previous rope segment //A rope is only 33 segments long, so only 33 pairs of offsets are used at any one time rope_X_Table = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,1,1,2,1,1,2,2,3,2,3,2,3,3,3,3,3,3] rope_Y_Table = [6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,4,6,6,4,6,4,6,4,6,4,4,4,6,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4] //The 33 segment window starts at a different array index each frame //For example - frame 1 would start at index 0 in the arrays and move along, frame 2 would start at index 4, frame 3 at index 8 etc. rope_Anim_Table = [0,4,8,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52] //The tables above only show one half swing of the rope - we need to know which way through the animation we are going, and whether it is swinging left or right rope_Anim_Frames = 23 //Total number of frames per half swing rope_Anim_Position = 0 //Where we are in the rope_Anim_Table rope_Anim_Direction = 1 //Which way we are moving through the rope_Anim_Table rope_X_Direction = 1 //Which way we are offsetting X - eg Left or Right //Create 33 segments of rope rope_Segments = [] for (s=0; s<=32; s++) { vRopeSegment = instance_create_layer(x,y+(s*12),"Instances",RopeSpriteSegment) //Create a single instance of a RopeSegment vRopeSegment.segment_ID = s //'Tell' the new rope segment what rope segment number it is vRopeSegment.parent_Instance = id //'Tell' the new rope segment who it's parent Rope_Generator is array_push(rope_Segments, vRopeSegment) //Add the reference for the rope segment to our array } //This function is used in the STEP code to set a segment position function f_SetSegmentPosition(instance, setX, setY) { with(instance) { x=setX y=setY } } //************************************************************************************************** ROPE GENERATOR STEP CODE //Move one step through our animation table in the direction stored in rope_Anim_Direction //This effectively ping-pongs between 0 and 23, 1 at a time rope_Anim_Position += rope_Anim_Direction if (rope_Anim_Position == rope_Anim_Frames) { rope_Anim_Direction = -1 } else if (rope_Anim_Position == 0) { rope_Anim_Direction = 1 rope_X_Direction = 0-rope_X_Direction //When we get back to position 0 in our animation table - swap left and right } //The business bit - put the position of the Rope Generator into variables segmentX and Y segmentX = x segmentY = y //Get our starting point in the rope Tables drawTablePosition = rope_Anim_Table[rope_Anim_Position] //For each of the 32 rope segments... for (s=0; s<=32; s++) { //Put the rope segment in position f_SetSegmentPosition(rope_Segments[s], segmentX, segmentY) //Offset our segment position by amounts drawn from rope tables - Note the *4 and *2 is due to my 4x scale segmentX += rope_X_Direction*(rope_X_Table[drawTablePosition]*4) segmentY += rope_Y_Table[drawTablePosition]*2 //Move to the next table position drawTablePosition++ } //************************************************************************************************ PLAYER COLLISION CODE //I'm not going to go into all of it here, but the player object has var_onRopeInstance and var_onRopeSegmentID variables //On a collision with a RopeSEGMENT object (not the generator) I fetch the parent instance (the generator) and segment id from the collision //If we're not on a rope already - and not on a rope cooldown if (var_onRopeInstance == 0 && var_onRopeCooldown == 0) { //Store the ID of the generator of the rope segment we're grabbing on to var_onRopeInstance = other.id.parent_Instance //Store the segment ID we've collided with - this will be between 1 and 33 var_onRopeSegmentID = other.id.segment_ID } //************************************************************************************************* PLAYER STEP CODE //Remember that rope_Segments array in the generator? We can now use that to put the player on a specific rope segment //Code when on a rope if (var_onRopeInstance) { //Set the player position to the position of the segment, but subtract half the player width and height to put the //middle of the player on the rope. From here, all we need to do to move up and down the rope is increment or //decrement var_onRopeSegmentID x = var_onRopeInstance.rope_Segments[var_onRopeSegmentID].x-32 y = var_onRopeInstance.rope_Segments[var_onRopeSegmentID].y-32 }