3 ms·
I think you could optimize quite a bit of this. If you made your shape objects more robust, even just {x,y,on}, instead of doing all of those nested for loops,
by acconrad 10y ago
I think you could optimize quite a bit of this. If you made your shape objects more robust, even just {x,y,on}, instead of doing all of those nested for loops, you could start leveraging array methods like filter to only select the ones where on === 1, then do some sort of matrix transform to swap out that x,y coord in the 4x4 with the shape you're replacing.
Either way, cool game! Pretty neat you could do that in sub 400 lines of code.
- jstimpfle 10y agoThe reason why I'm (sort of) proud of this is exactly that I managed to not get hung up with such considerations and just do the obvious things. It's not a problem to scan through 200 blocks (of which often 50% will be habitated) once every 100ms or so). If there is any need for optimization, then it would probably be to avoid DOM inefficiencies and opting for canvas or another environment.