#region tile level
// 1 buffer on each side so that we can check tiles "outside" the grid
for (var _y = 1; _y < grid_h - 1; _y++){
	for (var _x = 1; _x < grid_w - 1; _x++){
		if (level_data[_x][_y].type != TILES.FLOOR){
			var _north_tile = level_data[_x][_y - 1].type == TILES.VOID //returns true if void else return false
			var _west_tile = level_data[_x - 1][_y].type == TILES.VOID
			var _east_tile = level_data[_x + 1][_y].type == TILES.VOID
			var _south_tile = level_data[_x][_y + 1].type == TILES.VOID
			
			//+1 because tiles are not 0-indexed
			var _tile_index = NORTH * _north_tile + WEST * _west_tile + EAST * _east_tile + SOUTH * _south_tile + 1
			
			tilemap_set(wall_map, _tile_index, _x, _y)
		}
		else{
			tilemap_set(wall_map, 0, _x, _y)
		}
	}
}
#endregion

if (!instance_exists(obj_enemy) && !instance_exists(obj_door)){
    instance_create_layer(get_end_room().x_pos * TILE_SIZE, get_end_room().y_pos * TILE_SIZE, "Instances", obj_door)
	
	obj_game.draw_objective = true
	obj_game.alarm[0] = 240
	global.objective = "FIND THE EXIT"
	
	audio_stop_all()
	snd = audio_play_sound(bgm_exit, 1, false)
	audio_sound_gain(obj_game.snd, 0, 3000)
	audio_sound_gain(snd, 0, 0)
	audio_sound_gain(snd, 1, 3000)
}

if (clamp(global.this_floor_time, 3, 15) == global.this_floor_time){
	if (floor(global.time_since_boulder) % 35 == 0){
		//create a boulder every 5 seconds if the position is not in the wall
		var _pos_x = irandom(grid_w) * TILE_SIZE
		var _pos_y = irandom(grid_h) * TILE_SIZE
		instance_create_layer(_pos_x, _pos_y, "Instances", obj_boulder_fall_test)
	}
}
else{
	if (floor(global.time_since_boulder) % 25 == 0){
		//create a boulder every 5 seconds if the position is not in the wall
		var _pos_x = irandom_range(CAM_X / TILE_SIZE, (CAM_W + CAM_X) / TILE_SIZE) * TILE_SIZE
		var _pos_y = irandom_range(CAM_Y / TILE_SIZE, (CAM_H + CAM_Y) / TILE_SIZE) * TILE_SIZE
		instance_create_layer(_pos_x, _pos_y, "Instances", obj_boulder_fall_test)
	}
}












