- Home /
2D Level Generation Storage
Alright, so this question has been driving me nuts all day. My game is a 2D game which consists of a grid layout. Each level has a 2D grid of blocks that are various colors. The colors represent the states of the blocks. I am planning on creating dozens of levels and have been trying to come up with a good way to store each level's setup layout.
I have a GridManager
that can take the size of the grid, the total number of possible colors and a List<T>
of the starting states of the blocks. I have all of this information wrapped up in class LevelLayout
but that's where I run into an issue. Is there an easy way for me to create a List<LevelLayouts> MasterLayoutList
and keep it somewhere until a level is loaded. Then access that List<LevelLayouts> MasterLayoutList
and pull whatever index is necessary and generate the level from the loaded class instance. My problem is, I don't know how to create a file that hard codes these levels, they are not going to change, and stores them in the master list for use later. Any suggestions?
I would prefer not to have to generate every puzzle layout and save it as a different scene, that seems rather time consuming and less elegant than generating the necessary level at Runtime. I'm not against using XML or some other resource file but it seems silly to me that I can't just create a code file that populates a list and include that in my GridManager
script.
If it helps here is the class that is designed to hold the information for each layout:
public class PuzzleBlueprint
{
/* ---------- Public Variables and Functions ---------- */
public PuzzleBlueprint(int new_puzzle_level, int new_size, int new_selection_limit, int new_total_colors, List<PuzzlePieceStates> new_puzzle_layout)
{
m_puzzle_level = new_puzzle_level;
m_size = new_size;
m_selection_limit = new_selection_limit;
m_total_colors = new_total_colors;
m_puzzle_layout = new_puzzle_layout;
}
private int m_puzzle_level;
private int m_size;
private int m_selection_limit;
private int m_total_colors;
private List<PuzzlePieceStates> m_puzzle_layout;
}