I am building a space-related game and do not know how to loop through my array of percentage "spawn" chances, to end up with one generated star with a certain size.
Example of how it must generate:
$star_chance = rand(1,100);
$star_size_chance = rand(1,100);
//loop through the list of stars here
//selected star - orange
//loop through the size chances of star orange
//selected star size = medium
- Red, Orange and Yellow stars each have a spawn chance, only one can spawn at a time
- For each spawned star there is a chance of what size it shall become
-
The equation needs to accommodate for possibly more stars or sizes
$star_array = array( "red" => array( "spawn_chance" => "25", "size_immense_chance" => "50", "size_giant_chance" => "25", "size_large_chance" => "15", "size_medium_chance" => "5", "size_small_chance" => "4", "size_dwarf_chance" => "1" ), "orange" => array( "spawn_chance" => "50", "size_immense_chance" => "4", "size_giant_chance" => "15", "size_large_chance" => "50", "size_medium_chance" => "25", "size_small_chance" => "6", "size_dwarf_chance" => "0" ), "yellow" => array( "spawn_chance" => "25", "size_immense_chance" => "0", "size_giant_chance" => "6", "size_large_chance" => "25", "size_medium_chance" => "50", "size_small_chance" => "15", "size_dwarf_chance" => "4", ) );