Powder Toy Clone
- Fabio Pereira
- May 16, 2021
- 1 min read
Overview
For one of my module assignments, I had to program a game in C++. I chose to program a powder toy clone. Powder toy is a sandbox, simulation game where you can add a plethora of elements such as sand, fire and water. I implemented 7 elements in my version.
Final Product
Problem
I had an access violation. I'm using pointers so it didn’t throw an index out of range exception. Which made it harder to debug but after playing around trying to crash the game, I realized why this was happening.
Optimisation was a problem for this project as I was looping through a large array which was slow. I fixed this by adding a needs Updating variable which stops the program from calling update on every element in the array.
Key Takeaways
If I could do this again, I would use a subtree data structure to optimise the updating of elements. I don't think it would optimise the loop anymore but it would be fun to try and implement.
I learned lambdas. To implement a 'brush' that I could change what element I 'painted' in, I had to use an array of lambdas. This way, I eliminated to use of inefficient switch statements.
Comments