• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Would appreciate any help simplifying my code and/or getting double jump feature to work

D

David Villarreal

Guest
I'm pretty new to GameMaker and know that my code is sloppy and inefficient. All of my states are working, except for the code that has to do with the double jump. I am not sure on what is the best way to code the jumping state, and also the falling state, so I'm open to suggestions.

scr_collision();
switch (state) {
case "IDLE": {
image_speed = 0;
sprite_index = spr_player_idle;
hspd = 0;
vspd = 0;
jumps = jumpsmax;
if (!place_meeting(x, y+1, obj_solid)) state = "FALLING";

if (input.jump) state = "JUMPING";
if (input.left) state = "LEFT";
if (input.right) state = "RIGHT";
if (!input.jump && !input.left && !input.right) state = "IDLE";
break;
}
case "JUMPING": {
image_speed = 0;
sprite_index = spr_player_jump;
if (move == 1) {
image_xscale = 1;
} else if (move == -1) {
image_xscale = -1;
}
vspd += grav;
if (jumps > 0) {
scr_jump();
}
if (input.jump) && (jumps > 0) {
scr_jump();
}
if (vspd > 0) state = "FALLING";
scr_move();
hspd = move * playerspd;
break;
}

case "MIDAIR": {


break;
}

case "FALLING": {
image_speed = 0;
sprite_index = spr_player_fall;
if (move == 1) {
image_xscale = 1;
} else if (move == -1) {
image_xscale = -1;
}

if (jumps == jumpsmax) jumps -= 1

if (!place_meeting(x, y+1, obj_solid)) {
vspd += grav;
} else if (place_meeting(x, y+1, obj_solid)) state = "IDLE";

scr_move();
hspd = move * playerspd;

break;
}

case "DOWN": {
image_speed = 0;
if (input.jump) state = "JUMP";
if (input.left) state = "LEFT";
if (input.right) state = "RIGHT";
if (!input.jump && !input.left && !input.right) state = "IDLE";
break;
}
case "LEFT": {
image_speed = animspd;
sprite_index = spr_player_walk;
scr_move();
image_xscale = -1;
hspd = move * playerspd;
vspd = 0;
jumps = jumpsmax;
if (!place_meeting(x, y+1, obj_solid)) state = "FALLING";
if (input.jump) state = "JUMPING";
if (input.right) state = "RIGHT";
if (!input.jump && !input.left && !input.right) state = "IDLE";
break;
}
case "RIGHT": {
image_speed = animspd;
sprite_index = spr_player_walk;
scr_move();
image_xscale = 1;
hspd = move * playerspd;
vspd = 0;
jumps = jumpsmax;
if (!place_meeting(x, y+1, obj_solid)) state = "FALLING";
if (input.jump) state = "JUMPING";
if (input.left) state = "LEFT";
if (!input.jump && !input.left && !input.right) state = "IDLE";
break;
}
}



The code for the scr_jump is

vspd = -jumpspd;
jumps -= 1;

Also I want to be able to double jump whether I'm rising in jumping state or falling in the falling state.
 
K

KaiXtr

Guest
I'm not expert in Scripts,but if you want a double jump,change the break to able the player to press the jump button 2 times,not 1.
 
Top