xx = mouse_x;
yy = mouse_y;
enum mouse
{
none
}
xx = mouse.none;
yy = mouse.none;
spd = 4;
if (xx != mouse.none && yy != mouse.none)
{
move_towards_point(xx, yy, spd);
}
else
{
speed = 0;
}
if (distance_to_point(xx, yy) < spd + 2)
{
xx = mouse.none;
yy = mouse.none;
}
gs = 32; // Grid size.
global.grid = mp_grid_create(0, 0, room_width / gs, room_height / gs, gs, gs);
mp_grid_add_instances(global.grid, Wall, false); // We avoid the Wall object.
xx = Player.x;
yy = Player.y;
path = path_add(); // We add a path so when we left click, there's one to destroy. Solves memory leak.
// This has nothing to do with the code but how the "Player" functions on the path.
// The "Player" sprite was edited to have a origin of center.
// Now the "Player" object will not overlap the wall when following the path.
if path_exists(path)
{
path_delete(path); // Lets delete the old path. We don't need any memory leaks.
}
xx = mouse_x;
yy = mouse_y;
path = path_add(); // Now lets create a new path on left click.
if mp_grid_path(global.grid, path, Player.x, Player.y, xx, yy, 1)
{
path_start(path, 2, path_action_stop, 0);
}