GML I need help for a rope Swing game

J

Jemios

Guest
Hi everyone, I've started using GM2 less than a month ago and I definitely have bitten more than i can chew.
Bit desperate here, I am running out of time and I have a prototype for a game I needed to make for trying out for a school.

I need my player to rope swing but in a side-scrolling endless runner setting so i need my player to always stay on the left side of the room, in a sort of infinite level like in an endless runner.
I tried using this video of Shaun Spalding as a starter and from then on modify the code so to use the spacebar to instantly draw a line/rope towards the sky and then complete the swing once i release the spacebar.
I know that i need to do something like this:
GML:
if(mouse_check_button_released(vk_space))
{
if (state == pState.swing)
spd = 1;
xx = mouse_x;
yy = mouse_y;
draw_line(x,y,xx,yy)
}
And then maybe use the variable from the video? I honestly have no clue i can't do it alone. so any help would be immensely appreciated.
I inspired myself from this game and this one if my explanation wasn't clear enough. Thanks a lot everyone.
 

Yal

šŸ§ *penguin noises*
GMC Elder
If the issue is that you can't BOTH have the player swing properly AND stay at the left-hand side of the room, how about allowing them to swing ahead of the camera, but if they're ahead the zone they're supposed to stay in, the camera quickly speeds up until they're in the zone again? Could also look nicer with other sources of extra speed (trampolines/boost pads, etc).
 

Nidoking

Member
Talk me through your flow here. When you release the spacebar, you're already in the swing state, and that's when you create the line, which will only exist for one step. But you're doing all of this checking in a Draw event?
 
J

Jemios

Guest
Talk me through your flow here. When you release the spacebar, you're already in the swing state, and that's when you create the line, which will only exist for one step. But you're doing all of this checking in a Draw event?
Bit late answer i'm sorry. I'm probably bad at explaining things, so basically, all this is in the step event, i want that then i press the spacebar key, a line is drawn towards the sky of the room. and then i release spacebar i go back into the normal state to complete the swing.
so probably something like this:

GML:
if (keyboard_check_pressed(vk_space))
{
        grappleX = mouse_x;
        grappleY = mouse_y;
        ropeX = x;
        ropeY = y;
        ropeAngleVelocity = 0;
        ropeAngle = point_direction(grappleX,grappleY,x,y);
        ropeLength = point_distance(grappleX,grappleY,x,y);
        state = pState.swing;

}
I believe i need to change the grappleX and grappleY variable so the line draws in the sky instead of choosing the position with the mouse.
also here's the draw event:
Code:
if (state == pState.swing) draw_line_width(grappleX,grappleY,ropeX,ropeY,2);

draw_self();
Did i answer your question correctly or was i off subject?
 
J

Jemios

Guest
If the issue is that you can't BOTH have the player swing properly AND stay at the left-hand side of the room, how about allowing them to swing ahead of the camera, but if they're ahead the zone they're supposed to stay in, the camera quickly speeds up until they're in the zone again? Could also look nicer with other sources of extra speed (trampolines/boost pads, etc).
You're right, but how can i make the camera "catch up" to the player tho?
maybe i should make something like "if the player is at x position then the camera will move to the right" ?
 

Nidoking

Member
That's very different from what you posted before. It makes a lot more sense now. One thing to watch for is that most of those values are going to change as you swing on the rope. You'll need to update them each step.
 
J

Jemios

Guest
That's very different from what you posted before. It makes a lot more sense now. One thing to watch for is that most of those values are going to change as you swing on the rope. You'll need to update them each step.
thanks a lot for taking the time to answer but with what can i change the grapple variable so it just aim on the sky? I've been searching a bit inside the manual and I'm not sure.
 
J

Jemios

Guest
Where do you want it to go? "The sky" is a pretty big target. I imagine it would be hard to miss.
GML:
if (keyboard_check_pressed(vk_space))
        {
                sprite_index = spr_joueur_swing;
                grappleX = x+200;
                grappleX = x+200;
                grappleY = -y;
                ropeX = x;
                ropeY = y;
                ropeAngleVelocity = -0.02;
                ropeAngle = point_direction(grappleX,grappleY,x,y);
                ropeLength = point_distance(grappleX,grappleY,x,y);
        }
lol yeah I've done it. I was thinking too hard, the solution wasn't that difficult.
the player swing a little too fast but other than that it's ok.
Now I just need to figure out the level part but now i feel like i can finish so thanks a lot.
 
Top