OK this what I got now for his step and Create code:
Step
if keyboard_check_pressed(vk_right) new_dir=0;
else if keyboard_check_pressed(vk_left) new_dir=180;
else if keyboard_check_pressed(vk_up) new_dir=90;
else if keyboard_check_pressed(vk_down) new_dir=270;
if direction == (new_dir + 0) mod 360 {
direction = new_dir;
switch direction {
case 0: sprite_index = Pac_Man_right; break;
//repeat for other directions
}
}
else {
if (x - grid/2) mod grid == 0 && (y-grid/2) mod grid == 0 {
var h = lengthdir_x(grid/2, new_dir);
var v = lengthdir_y(grid/2, new_dir);
if place_meeting(x+h,y+v,obj_Pac_Collision) //or whatever your wall object is
new_dir = direction; //this makes Pac-Man keep doing what he's doing
else {
direction = new_dir;
//change sprite here, like before
}
}
}
if direction == (new_dir + 180) mod 360 {
direction = new_dir;
switch direction {
case 180: sprite_index = Pac_Man_left; break;
//repeat for other directions
}
}
else {
if (x - grid/2) mod grid == 0 && (y-grid/2) mod grid == 0 {
var h = lengthdir_x(grid/2, new_dir);
var v = lengthdir_y(grid/2, new_dir);
if place_meeting(x+h,y+v,obj_Pac_Collision) //or whatever your wall object is
new_dir = direction; //this makes Pac-Man keep doing what he's doing
else {
direction = new_dir;
//change sprite here, like before
}
}
}
if direction == (new_dir + 90) mod 360 {
direction = new_dir;
switch direction {
case 90: sprite_index = Pac_Man_up; break;
//repeat for other directions
}
}
else {
if (x - grid/2) mod grid == 0 && (y-grid/2) mod grid == 0 {
var h = lengthdir_x(grid/2, new_dir);
var v = lengthdir_y(grid/2, new_dir);
if place_meeting(x+h,y+v,obj_Pac_Collision) //or whatever your wall object is
new_dir = direction; //this makes Pac-Man keep doing what he's doing
else {
direction = new_dir;
//change sprite here, like before
}
}
}
if direction == (new_dir + 270) mod 360 {
direction = new_dir;
switch direction {
case 270: sprite_index = Pac_Man_down; break;
//repeat for other directions
}
}
else {
if (x - grid/2) mod grid == 0 && (y-grid/2) mod grid == 0 {
var h = lengthdir_x(grid/2, new_dir);
var v = lengthdir_y(grid/2, new_dir);
if place_meeting(x+h,y+v,obj_Pac_Collision) //or whatever your wall object is
new_dir = direction; //this makes Pac-Man keep doing what he's doing
else {
direction = new_dir;
//change sprite here, like before
}
}
}
move_wrap(true, true, 1);
Create
direction = 180;
new_dir = direction;
sprite_index = Pac_Man_left;
image_speed = 1;
speed = 4;
grid = 32;
Now the problem is he gets stuck when colliding with wall. I've tried the place_free code but it doesn't seem to work properly for me. I also tried to use place_snapped too but that doesn't work well either.