GML Super Mario Bros. - ? Block Glitch

P

PizzaGuy676

Guest
I am currently working on a recreation of Super Mario Bros. But there's a glitch in my game that I want to fix. I'm assuming you know about the blocks with question marks on them, which create a mushroom when Mario hits them from underneath. I have these same blocks in my game, and I have programmed them to create a mushroom when Mario is one pixel beneath them. However, for some reason, when Mario hits the block from the side, his collision glitches out, shown in the link below:

http://imgur.com/a/wvoat

Just in case it helps, here's the code for the collision with the ? block (in the step event for obj_question_block):
Code:
///Mario collides with ? block
if place_meeting(x, y + 1, par_mario) {
    instance_create(x + 8, y - 8, obj_mushroom);
    instance_change(obj_question_block_empty, true);
}
 
P

PizzaGuy676

Guest
im pretty sure the problem is in mario`s code.
Alright, here's some code for Mario

Step event for obj_mario_small:
Code:
scr_mario_controls();

//Colliding with ground
if (place_meeting(x, y + 1, par_block)) {
    vspd = 0;

   
    //Jumping
    if (jump) {
        vspd = -jump_spd;
        jump = true;
        still = false;
    }
} else {
    //Gravity
    if (vspd < 10) {
        vspd += grav;
        jump = true;
        still = false;
    }
   
    if (keyboard_check_released(vk_space) and vspd < -4) {
        vspd = -4;
        jump = true;
    }
}

//If not moving
if ((!move_right and !move_left) || (move_right and move_left)) {
     hspd = max(abs(hspd) - frcn, 0) * sign(hspd);
     move = false;
     still = true;
}
   
//Moving right
if (move_right) {
    if (hspd < spd) {
        hspd += frcn;
    } else {
        hspd = spd;
        still = true;
    }
    facing = 1;
    move = true;
    still = false;
}

//Moving left
if (move_left) {
    if (hspd > -spd) {
        hspd -= frcn;
    } else {
        hspd = -spd;
        still = true;
    }
    facing = -1;
    move = true;
    still = false;
}

//Horizontal collisions
if (place_meeting(x + hspd, y, par_block)) {
    while (!place_meeting(x+sign(hspd), y, par_block)) {
        x += sign(hspd);
    }
    hspd = 0;
    move = false;
}

//Move horizontally
x += hspd;

//Vertical collisions
if (place_meeting(x, y + vspd, par_block)) {
    while (!place_meeting(x, y + sign(vspd), par_block)) {
        y += sign(vspd);
    }
    vspd = 0;
    jump = false;
}

//Move vertically
y += vspd;

//Animate Mario
if (jump = true) {
    sprite_index = spr_mario_jump_small;
}
else if (move = true) {
    sprite_index = spr_mario_walk_small;
}
else if (still = true) {
    sprite_index = spr_mario_idle_small;
}

//Death
if global.hits == 0 {
    instance_change(obj_mario_die, true);
}
I also have a separate player object called obj_mario_big (which is exactly what it sounds like), but I don't think it's necessary to put here since it has almost the exact same code as obj_mario_small.
 
Top