Now I made it so save data contains texture data. We can choose from 7 different textures or colours.
One downside of this is that it takes up 3 times more space. This means currently I can only save and load 1 25x25x25 world.
I tried increasing the world size to something like 32 but it keeps giving me a stack overflow error. I think this is because I store the world in memory as 3d 32x32x32 array. Maybe I should store it as a 1d array of length 32^3?
The stack overflow error came from inside the for loop I used to convert the 3d array into a saveable format. It said I called too many functions or something.
Also I think I may have a go at using run length emcoding to further shrink the size of the save data.
How I saved the world:
3d world array, elements are integers 0 to 7 --->
Flatten into 1d array, element are ints --->
Convert integers to bits and store them into an array -->
Group six bits together, bit shift left by 1 and then add 1-->
Convert the 7 bits to an integer. use this integer to get a character. --->
Append all characters together into a string--->
Save this string to file.
(Loading is the reverse of this)
Looking at the steps now, i think because each stage has a for loop, this may have contributed to the stack overflow error. I don't know how to fix it though.
I should probably stop working on this for now. I have exams next week ðŸ˜. I'll try picking it up after exams tho.
in the future i want to create a game where you can use, combine and place coloured blocks. Each block has their own unique power up. Health, speed, jump, ice, break, explosion, wind block, portal, gravity, colour mixing block. Idk if I'll be able to do all that but it's good to keep a note of. Also I could just save each level like I did here. nah