I rewrote some of the code to be even more efficient. I had a dumb idea thinking that something like hold_u + hold_d == 0 was comparison-wise faster than !hold_u && !hold_d - the former has to add and then do a boolean comparison, in the latter if the first condition is false, then it's done. So the former always does two things while the latter does either one thing or two.
I was also able to do that collobj replacement for the objSolid in the corner-cutting. The overlap variable was unnecessary as well since the evaluation of it was only used once in the code chunk. The direction changing code for non-diagonal movement is also more efficient. Additionally, I added an "able to move" and "able to change direction" variable which is useful for later.
However, I realized that the movement engine would be better off if it was broken up to work on the x and y separately as there can be times like when dashing when an x-speed is different from a y-speed. There are also times when you want to limit either x or y movement, so breaking it up improves that. I haven't finished all of this yet, but here is the code for some of the above changes:
var hold_u, hold_d, hold_l, hold_r, collobj;
if (able_m){
hold_u = keyboard_check(vk_up);
hold_d = keyboard_check(vk_down);
hold_l = keyboard_check(vk_left);
hold_r = keyboard_check(vk_right);
if (hold_u && hold_d){
hold_u = 0; hold_d = 0;
}
if (hold_l && hold_r){
hold_l = 0; hold_r = 0;
}
switch (hold_u + hold_d + hold_l + hold_r){
case 0:
move_f = 0;
break;
case 1:
move_f = 1; move_c = 0;
if (able_d){
direction = hold_u * 90 + hold_d * 270 + hold_l * 180;
}
break;
case 2:
move_f = 1.4142135620;
if (able_d){
switch (direction){
case 90:
if (hold_d)
direction = 270;
break;
case 270:
if (hold_u)
direction = 90;
break;
case 180:
if (hold_r)
direction = 0;
break;
case 0:
if (hold_l)
direction = 180;
break;
}
}
break;
}
if (move_f > 0){
move_c += move_s; blink = 0;
while (move_c >= 1){
x += hold_r - hold_l;
if (place_meeting(x,y,objSolid)){
collobj = instance_place(x,y,objSolid);
if (!hold_u && !hold_d){
if (bbox_top > collobj.bbox_bottom || bbox_bottom < collobj.bbox_top || bbox_left + hold_l > collobj.bbox_right || bbox_right - hold_r < collobj.bbox_left){
x -= hold_r - hold_l;
}
else{
move_f = 1.4142135620;
if (!place_meeting(x,y - 1,collobj)){
y -= 1;
}
else if (!place_meeting(x,y + 1,collobj)){
y += 1;
}
else if (!place_meeting(x - hold_r + hold_l,y - height div 2,collobj)){
x -= hold_r - hold_l; y -= 1;
}
else if (!place_meeting(x - hold_r + hold_l,y + height div 2,collobj)){
x -= hold_r - hold_l; y += 1;
}
}
}
else{
x -= hold_r - hold_l;
}
}
y += hold_d - hold_u;
if (place_meeting(x,y,objSolid)){
collobj = instance_place(x,y,objSolid);
if (!hold_l && !hold_r){
if (bbox_top + hold_u > collobj.bbox_bottom || bbox_bottom - hold_d < collobj.bbox_top || bbox_left > collobj.bbox_right || bbox_right < collobj.bbox_left){
y -= hold_d - hold_u;
}
else{
move_f = 1.4142135620;
if (!place_meeting(x - 1,y,collobj)){
x -= 1;
}
else if (!place_meeting(x + 1,y,collobj)){
x += 1;
}
else if (!place_meeting(x - width div 2,y - hold_d + hold_u,collobj)){
x -= 1; y -= hold_d - hold_u;
}
else if (!place_meeting(x + width div 2,y - hold_d + hold_u ,collobj)){
x += 1; y -= hold_d - hold_u;
}
}
}
else{
y -= hold_d - hold_u;
}
}
move_c -= move_f;
}
}
}