In my game you collect coins (surprise!). At the moment I generate them like this:
- Find a random position given a rectangle (eg. the screen size) and generate a coin
- Possible positions are left and right of this coin for our next coin
- If both are available, choose at random
- If a coin exists in one position, use the other
- If neither are available skip this step
- Do the same for up and down positions of the new coin
- Repeat this sequence for all available coins
This works fine but I would like to create custom shapes with my coins like arrows, stars etc. This got me thinking into how I could achieve this. One way I thought of was to use a small texture where each coloured pixel represented the position of a coin. So that a picture like this:
Can be used to generate an array of coin position coordinates in any framework supporting textures. I'm pretty sure this can be done, but was wondering if anyone has tried this or something totally different for generating coins or any other objects in a game. Ideally the game would involve several different textures and choose them at random, and combine this with the random scattering textures from simple algorithms such as the one I have above.