Bentley
Member
Hello. I'm using an mp_grid and marking cells forbidden based on where I placed tiles in the room. I only want to mark tiles forbidden from the "Collisions" tilemap, but, for some reason, cells from the "Items" tilemap are also marked forbidden.
The above code keeps Pacman from entering cells with tiles from the "Items" tilemap".
Temporary Fix (runs below the above code)
Does anyone know where I'm going wrong? I don't know why the loop also marks cells forbidden from the "Items" tilemap.
Thanks for reading.
Code:
global.grid = mp_grid_create(0, 0, COLS, ROWS, TS, TS);
var lay_id, tilemap_id;
lay_id = layer_get_id("Collisions");
tilemap_id = layer_tilemap_get_id(lay_id);
for (var i = 0; i < COLS; i++)
{
for (var j = 0; j < ROWS; j++)
{
if (tilemap_get_at_pixel(tilemap_id, i * TS, j * TS) != 0) // FIX: This line includes the "Items" tilemap
{
mp_grid_add_cell(global.grid, i, j);
}
}
}
Temporary Fix (runs below the above code)
Code:
// Unmark cells that I accidently marked forbidden
var lay_id, tilemap_id;
lay_id = layer_get_id("Items");
tilemap_id = layer_tilemap_get_id(lay_id);
for (var i = 0; i < COLS; i++)
{
for (var j = 0; j < ROWS; j++)
{
if (tilemap_get_at_pixel(tilemap_id, i * TS, j * TS) == TILE_PELLET)
{
mp_grid_clear_cell(global.grid, i, j);
}
}
}
Thanks for reading.
Last edited: