The main challenge here is the performance. All particles are updated if needed and redrawn every cycle.
The Particles array stores the state of all "game pixels". A value of 0 means that the pixel is empty. Other values mean that there is a particle on that pixel.
Sand particles move down or diagonally if they can.
The RowsState array tracks the rows that are considered dirty. Non-dirty rows are skipped.
Single dimension arrays of bytes can be accessed in an optimized way in B4i with Bit.FastArrayGet / Set methods (https://www.b4x.com/android/forum/threads/92951/#content). I used these methods in some of the cases.
All the important code is implemented in the Game class, which is of course shared between the three projects. No sprites are used in this game. The drawings are done in the MoveParticles sub.
As in the Tetris game the layout is managed with the designer script.
You need to change the GameUtils module that is included in the zip files with the one attached separately.
Dependencies:
- Recent version of XUI.
- BitmapCreator v3.6 (B4J, B4i)
The three projects are attached. I've also uploaded an executable jar. Download and double click.
www.b4x.com/b4j/files/games/FallingSand_ExecutableJar.jar
Attachments
Last edited: