D
denpa
Guest
I just started with game maker today and I was wondering how I would go about coding diagonal movement while snapped to a grid. I'm going for movement like in the Mystery Dungeon games. Right now I can move in all directions while snapped, but my diagonal movement code doesn't work and I feel like it has to do with the way I'm handling multiple inputs.
What happens is that when I move diagonally it won't stop. It keeps moving that way forever.
Code:
//Movement
if (place_snapped(32,32)){
if (keyboard_check(vk_left)){
motion_set(180,4);
sprite_index = spr_playerW;
}
if (keyboard_check(vk_right)){
motion_set(0,4);
sprite_index = spr_playerE;
}
if (keyboard_check(vk_up)){
motion_set(90,4);
sprite_index = spr_playerN;
}
if (keyboard_check(vk_down)){
motion_set(270,4);
sprite_index = spr_playerS;
}
if (keyboard_check(vk_right) && keyboard_check(vk_up)){
motion_set(45,4);
sprite_index = spr_playerNE;
}
if (keyboard_check(vk_left) && keyboard_check(vk_up)){
motion_set(135,4);
sprite_index = spr_playerNW;
}
if (keyboard_check(vk_right) && keyboard_check(vk_down)){
motion_set(315,4);
sprite_index = spr_playerSE;
}
if (keyboard_check(vk_left) && keyboard_check(vk_down)){
motion_set(225,4);
sprite_index = spr_playerSW;
}
if (keyboard_check(vk_nokey)){
motion_set(0,0,);
if (keyboard_check_released(vk_left)){
image_index = 0;
}
if (keyboard_check_released(vk_right)){
image_index = 0;
}
if (keyboard_check_released(vk_up)){
image_index = 0;
}
if (keyboard_check_released(vk_down)){
image_index = 0;
}
if (keyboard_check(vk_right) && keyboard_check(vk_up)){
image_index = 0;
}
if (keyboard_check(vk_left) && keyboard_check(vk_up)){
image_index = 0;
}
if (keyboard_check(vk_right) && keyboard_check(vk_down)){
image_index = 0;
}
if (keyboard_check(vk_left) && keyboard_check(vk_down)){
image_index = 0;
}
}
}