Bentley
Member
I know "better" is vague, sorry. I want a jump that is more "game-like" (that's extremely vague too).
For the longest time I've been terrible at jump codes. Is there anything in the code below I can improve on? Is there another way I can go about it?
Edit: I know the rising/falling variables are pointless. The thought behind using them was that I may want two different speeds, a rise_speed and a fall_speed. But yeah, just letting the vspd go from negative to positive makes the most sense.
CREATE
STEP
Thanks for reading. Any help is appreciated!
For the longest time I've been terrible at jump codes. Is there anything in the code below I can improve on? Is there another way I can go about it?
Edit: I know the rising/falling variables are pointless. The thought behind using them was that I may want two different speeds, a rise_speed and a fall_speed. But yeah, just letting the vspd go from negative to positive makes the most sense.
CREATE
Code:
state = "normal";
rising = false;
falling = false;
vspd = 8;
grav = 0.2;
Code:
//Press jump
if (state == "normal") && (keyboard_check_pressed(vk_space))
{
state = "jump";
rising = true;
}
//Jump state
if (state == "jump")
{
//Rise
if (rising)
{
if (!place_meeting(x, y - vspd, oWall)) //If there's not a wall above you, rise
{
y -= vspd;
vspd -= grav;
if (vspd < 0) //If you aren't moving up anymore, fall
{
rising = false;
falling = true;
}
}
else //Collide with ceiling, then fall
{
while (!place_meeting(x, y - 1, oWall)) y -= 1;
rising = false;
falling = true;
}
}
//Fall
if (falling)
{
if (!place_meeting(x, y + vspd, oWall))
{
y += vspd;
vspd += grav; //Fall faster
}
else
{
while (!place_meeting(x, y + 1, oWall)) y += 1;
falling = false;
vspd = 8; //Default vspd
state = "normal";
}
}
}
Last edited: