I’m making a 2D game where each level is determined by a config.json file. It contains the level name, and the name of a file called “level1.txt”, “level2.txt” etc. I have a buffered reader that reads the txt file, and prints out a tilemap based on the txt file.
I have a variable called currentLevelIndex that is an index which determines which level.txt to load.
Once the player reaches the exit tile, it should load the next level’s map.
How can I rerun the code that reads the config file? It’s in setup so I can’t figure out how to rerun the code without having to restart the entire program
Edit: The tilemap is stored in an arraylist, and in draw(), I have loop that draws out the tiles depending on what is stored in the arraylist
The bufferedreader I used updates the arraylist with the map, but that only works for level 1 as its in setup.
Edit 2: This is what I’m currently thinking:
- Make the bufferedreader thing a separate function, and not in setup()
- Call the function at the start of draw()
However, this means the map will have to be read every single frame, and I’m not sure if thats bad or not