Random Placement for Games.
I have a set of game pieces/images/cards and I want them to be in a different place with each and every run of my game.
Here’s what I need to do to develop that.
Set up your game cards, know their sizes. Then make Flash find a random number times 10 that you limit to anywhere you want from 0-9. For X and Y times that number by the width and height respective of x,y of your game piece for spacing (test for your set up and math this is not an exact just the logic)then RUN.
Now, about the over lapping. Maybe this logic isn’t the best (for that but we will try to rationalize). If you have time to try to figure it out please let me know what you came up with.
In the interest of time. Lets try setting arrays with the set coordinates for all. Then in a for loop assign a coordinate to each game piece from a random index of the arrays holding the coordinates. RUN it. Voila!!! BINGO!
When you have 100+ pieces and or your creating dynamically this can prove to be time consuming if you are hand coding in these coordinates. Lets try a compromise. Push everything dynamically.