Sand Blast.A simple castle crush style game where you fire a cannonball at some blocks.
Shoot all the blocks off the platforms to clear the level. |
🎮 How to play
Good luck, brave cannoneer.
- Use the mouse to aim the cannon and left click to fire a powerful cannonball toward the helpless blocks stacked up ahead of you.
- To clear a level, all blocks must be blown off the green platform(s) or displaced significantly.
- Red barrels will explode if the cannonball hits them.
- You get 10 cannonballs per round.
Good luck, brave cannoneer.
💡 Code Insight: Object pooling for resource optimisation
We instantiate all of the cannonballs at the beginning of the scene so we don't have to load them during a crucial gameplay interaction (firing the ball). The instantiated balls all go into a pool and are available to use when needed.
When the player clicks to fire a ball, the game does the following:
The benefits of this include reducing garbage collection overhead and a reduction in memory allocation. While not really necessary for such a small number of objects, this technique is very useful when dealing with many objects such as when there are hundreds of bullets or enemies on screen.
We instantiate all of the cannonballs at the beginning of the scene so we don't have to load them during a crucial gameplay interaction (firing the ball). The instantiated balls all go into a pool and are available to use when needed.
When the player clicks to fire a ball, the game does the following:
- Get the ball from the pool accoridng to it's index in the pool (_cannonballIndex).
- Instantiate it at the end of the cannon to make it appear to be firing out of it.
- Give the ball a ballistic velocity according to the forward angle of the cannon.
- Increment the _cannonballIndex so the next ball we get is the next one in the pool.
The benefits of this include reducing garbage collection overhead and a reduction in memory allocation. While not really necessary for such a small number of objects, this technique is very useful when dealing with many objects such as when there are hundreds of bullets or enemies on screen.
Build something that makes you think.