Hola a todos mi nombre es Mario y llevo unos cuantos días intentando que me funcione un codigo pero no lo consigo. Básicamente alterna entre tres estados: idle, walk y jump. Pues bien, consigo que mi personaje camine para un lado y para otro, con sus respectivas animaciones, pero a la hora de saltar no hace absolutamente nada. Llevo bastante tiempo revisandolo y me decido a preguntar por aquí, pues no consigo que haga un salto, es como si no me reconociera la tecla vk_up. Aquí dejo el código a ver si alguien me ayuda, gracias de antemano.

CÓDIGO:

Create Event:

execute code:

/// Variables
state_id = state_idle;
entered_new_state = false;
def_walk_speed = 10;
def_friction = 1;

//Jump
def_jump_speed = -15;
def_gravity = 1;
jump_count = 0;
jump_limit = 2;
grounded = false;
loop_index = 0;



Step Event:

execute code:

///state machine update
var current_state = state_id;
event_user(state_id);

if (state_id != state_jump) {
    if (y < global.room_bottom && place_empty(x, y + 1)) {
        state_id = state_jump;
        grounded = false;
    }

    if (grounded && jump_count < jump_limit && keyboard_check_pressed(vk_up)) {
        state_id = state_jump;
    }
}

if (current_state != state_id) {
    entered_new_state = true;
}



Other Event: User Defined 0:

execute code:

/// IDLE STATE

if (entered_new_state) {
    sprite_index = spr_player;
    image_index = 0;
    friction = def_friction;
    entered_new_state = false;
}

if (keyboard_check(vk_left)) {
    state_id = state_walk;
    image_xscale = -1;
}

else if(keyboard_check(vk_right)) {
    state_id = state_walk;
    image_xscale = 1;
}

if (entered_new_state) {
    sprite_index = spr_vlad_idle;
    image_index = 0;
    loop_index = 0;
}

Other Event: User Defined 1:

execute code:

/// WALK STATE

if (entered_new_state) {
    sprite_index = spr_walking;
    image_index = 0;
    friction = 0;
    hspeed = def_walk_speed;
    if (image_xscale < 0) {
        hspeed *= -1;
    }
    entered_new_state = false;
}
if ((image_xscale < 0 && !keyboard_check(vk_left)) || (image_xscale > 0 && !keyboard_check(vk_right))) {
    state_id = state_idle;
}

if (entered_new_state) {
    sprite_index = spr_vlad_walk;
    image_index = 0;
    loop_index = 0;
}

Other Event: User Defined 2:

execute code:

/// JUMP / FALL STATE

key_jump = vk_up;

if (entered_new_state) {
    sprite_index = spr_player_jump;
    loop_index = 11;
    if (grounded) {
        vspeed = def_jump_speed;
        image_index = 0;
        audio_play_sound(snd_jump, 0, false);
    }
    else {
        image_index = 11;
    }
    jump_count++;
    gravity = def_gravity;
    friction = 0;
    grounded = false;
    entered_new_state = false;
}
if (keyboard_check(vk_left)) {
    image_xscale = -1;
    hspeed = max(hspeed - def_friction, -def_walk_speed);
}
else if (keyboard_check(vk_right)) {
    image_xscale = 1;
    hspeed = min(hspeed + def_friction, def_walk_speed);
}
else {
    if (hspeed < def_friction) {
        hspeed = min(hspeed + def_friction, 0);
    }
    else if (hspeed > def_friction) {
        hspeed = max(hspeed - def_friction, 0);
    }
    else {
        hspeed = 0;
    }
}

if (vspeed < 0 && keyboard_check_released(vk_up)) {
    vspeed *= 0.5;
}
else if (jump_count < jump_limit && keyboard_check_pressed(vk_up)) {
    entered_new_state = true;
    grounded = true;
}

if (y + vspeed > global.room_bottom) {
    y = global.room_bottom;
    vspeed = 0;
    gravity = 0;
    jump_count = 0;
    state_id = state_idle;
}




solo veo una linea donde ponga el grounded en true, que es lo que necesitas para poder saltar la primera vez, y esa linea dice que has de pulsar la tecla... no estar en el suelo como es a lo que se refiere..

prueba poner por el principio mismo
if !place_free(x,y+2) grounded = true;
[spoiler="ola k ase clickarme o k ase"]la imagen no se quita xD
[/spoiler]


Vale, lo he resuelto cambiando a true un grounded. Muchas gracias amigo, de verdad. Llevaba dos días revisandolo... :D