I'm working on creating a maze using SFML, and I was wondering what the best way to go about creating the walls would be? If I have a Board class and Wall class, and the Board holds a vector of Wall objects, what's the simplest way to create each individual wall? It would be pointless really to try and hardcode the size and shape and position of every wall upon creation, but how else would I go about this? Would having arrays of stored data for the walls be a good idea? (Probably not because then I would have no idea which data corresponded to which wall?)
Let's say this is one of my walls:
1 2 3 4
void Board::SetWalls(){
//creates a wall 10*50, no rotation, position is (20, 20)
walls_.push_back(Wall(10, 50, 0, 20, 20));
}
But I want to have 200 total wall pieces in this maze? Do I have to type walls_.push_back(//insert new wall values here); 200 times or is there an easier way?
Do I have to type walls_.push_back(//insert new wall values here); 200 times or is there an easier way?
1) Use emplace_back() to construct elements in-place. walls_.emplace_back(10, 50, 0, 20, 20);
2) Use resource files. It can be a JSON file secribing each wall, or txt file with mase drawn in pseudographics — positions of individual walls would be calculated by your program.
@MiiNiPaa How would I integrate a JSON file into a c++ program? Also, if I'm simply describing each wall in a JSON file, wouldn't it be just as easy for me to type out each individual wall declaration in my c++ file?
@kbw that was just an example of one wall. Odds are, each wall will have a different size and position, and possibly a different rotation
Also, if I'm simply describing each wall in a JSON file, wouldn't it be just as easy for me to type out each individual wall declaration in my c++ file?
You won't need to recompile your code just to shift walls around. And you do not have to describe each individual wall. You can describe primitives like "line of walls from there to there".
Also if you write WYSIWYG editor, generation of JSON would be automated.
And I strongly reccoment to stick with pseudographic mazes for start:
It is a vector which contains strings std::vector<std::string>
Amd this was just an example.
You can use static 2D buffer, 1D simulation of it, just read info char by char and make note where you are now....